kttsd Library API Documentation

stretcher.cpp

00001 /***************************************************** vim:set ts=4 sw=4 sts=4:
00002   Description: 
00003      Speeds up or slows down an audio file by stretching the audio stream.
00004      Uses the sox program to do the stretching.
00005 
00006   Copyright:
00007   (C) 2004 by Gary Cramblitt <garycramblitt@comcast.net>
00008   -------------------
00009   Original author: Gary Cramblitt <garycramblitt@comcast.net
00010  ******************************************************************************/
00011 
00012 /******************************************************************************
00013  *                                                                            *
00014  *    This program is free software; you can redistribute it and/or modify    *
00015  *    it under the terms of the GNU General Public License as published by    *
00016  *    the Free Software Foundation; either version 2 of the License.          *
00017  *                                                                            *
00018  ******************************************************************************/
00019 
00020 // KDE includes.
00021 #include <kprocess.h>
00022 #include <kdebug.h>
00023 
00024 // Stretcher includes.
00025 #include "stretcher.h"
00026 #include "stretcher.moc"
00027 
00031 Stretcher::Stretcher(QObject *parent, const char *name) :
00032     QObject(parent, name)
00033 {
00034     m_state = 0;
00035     m_stretchProc = 0;
00036 }
00037 
00041 Stretcher::~Stretcher()
00042 {
00043     delete m_stretchProc;
00044 }
00045 
00053 bool Stretcher::stretch(const QString &inFilename, const QString &outFilename, const float stretchFactor)
00054 {
00055     if (m_stretchProc) return false;
00056     m_outFilename = outFilename;
00057     m_stretchProc = new KProcess;
00058     QString stretchStr = QString("%1").arg(stretchFactor, 0, 'f', 3);
00059     *m_stretchProc << "sox" << inFilename << outFilename << "stretch" << stretchStr;
00060     connect(m_stretchProc, SIGNAL(processExited(KProcess*)),
00061         this, SLOT(slotProcessExited(KProcess*)));
00062     if (!m_stretchProc->start(KProcess::NotifyOnExit, KProcess::NoCommunication))
00063     {
00064         kdDebug() << "Stretcher::stretch: Error starting audio stretcher process.  Is sox installed?" << endl;
00065         return false;
00066     }
00067     m_state = ssStretching;
00068     return true;
00069 }
00070 
00071 void Stretcher::slotProcessExited(KProcess*)
00072 {
00073     m_stretchProc->deleteLater();
00074     m_stretchProc = 0;
00075     m_state = ssFinished;
00076     emit stretchFinished();
00077 }
00078 
00082 int Stretcher::getState() { return m_state; }
00083 
00087 QString Stretcher::getOutFilename() { return m_outFilename; }
00088 
00092 void Stretcher::ackFinished() { m_state = ssIdle; }
00093 
KDE Logo
This file is part of the documentation for kttsd Library Version 3.3.90.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sun Dec 12 14:37:18 2004 by doxygen 1.3.9.1 written by Dimitri van Heesch, © 1997-2003