1 /***************************************************** vim:set ts=4 sw=4 sts=4:
3 Speeds up or slows down an audio file by stretching the audio stream.
4 Uses the sox program to do the stretching.
7 (C) 2004 by Gary Cramblitt <garycramblitt@comcast.net>
9 Original author: Gary Cramblitt <garycramblitt@comcast.net>
11 This program is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 2 of the License, or
14 (at your option) any later version.
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24 ******************************************************************************/
26 // Stretcher includes.
27 #include "stretcher.h"
28 #include "stretcher.moc"
31 #include <k3process.h>
37 Stretcher::Stretcher(QObject
*parent
, const char *name
) :
48 Stretcher::~Stretcher()
54 * Stretch the given input file to an output file.
55 * @param inFilename Name of input audio file.
56 * @param outFilename Name of output audio file.
57 * @param stretchFactor Amount to stretch. 2.0 is twice as slow. 0.5 is twice as fast.
58 * @return False if an error occurs.
60 bool Stretcher::stretch(const QString
&inFilename
, const QString
&outFilename
, float stretchFactor
)
62 if (m_stretchProc
) return false;
63 m_outFilename
= outFilename
;
64 m_stretchProc
= new K3Process
;
65 QString stretchStr
= QString("%1").arg(stretchFactor
, 0, 'f', 3);
66 *m_stretchProc
<< "sox" << inFilename
<< outFilename
<< "stretch" << stretchStr
;
67 connect(m_stretchProc
, SIGNAL(processExited(K3Process
*)),
68 this, SLOT(slotProcessExited(K3Process
*)));
69 if (!m_stretchProc
->start(K3Process::NotifyOnExit
, K3Process::NoCommunication
))
71 kDebug() << "Stretcher::stretch: Error starting audio stretcher process. Is sox installed?";
74 m_state
= ssStretching
;
78 void Stretcher::slotProcessExited(K3Process
*)
80 m_stretchProc
->deleteLater();
83 emit
stretchFinished();
87 * Returns the state of the Stretcher.
89 int Stretcher::getState() { return m_state
; }
92 * Returns the output filename (as given in call to stretch).
94 QString
Stretcher::getOutFilename() { return m_outFilename
; }
97 * Acknowledges the finished stretching.
99 void Stretcher::ackFinished() { m_state
= ssIdle
; }