Remove this line
[kdeaccessibility.git] / kttsd / libkttsd / stretcher.cpp
blob2981f1b50c309f15ddcd68f67e8ec620e2efc44f
1 /***************************************************** vim:set ts=4 sw=4 sts=4:
2 Description:
3 Speeds up or slows down an audio file by stretching the audio stream.
4 Uses the sox program to do the stretching.
6 Copyright:
7 (C) 2004 by Gary Cramblitt <garycramblitt@comcast.net>
8 -------------------
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"
30 // KDE includes.
31 #include <k3process.h>
32 #include <kdebug.h>
34 /**
35 * Constructor.
37 Stretcher::Stretcher(QObject *parent, const char *name) :
38 QObject(parent)
40 Q_UNUSED(name);
41 m_state = 0;
42 m_stretchProc = 0;
45 /**
46 * Destructor.
48 Stretcher::~Stretcher()
50 delete m_stretchProc;
53 /**
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?";
72 return false;
74 m_state = ssStretching;
75 return true;
78 void Stretcher::slotProcessExited(K3Process*)
80 m_stretchProc->deleteLater();
81 m_stretchProc = 0;
82 m_state = ssFinished;
83 emit stretchFinished();
86 /**
87 * Returns the state of the Stretcher.
89 int Stretcher::getState() { return m_state; }
91 /**
92 * Returns the output filename (as given in call to stretch).
94 QString Stretcher::getOutFilename() { return m_outFilename; }
96 /**
97 * Acknowledges the finished stretching.
99 void Stretcher::ackFinished() { m_state = ssIdle; }