Hi to all,
I would put in a separate thread the code to encode in an mp3 file some audio datas.
#include <QThread>
{
public:
WaveEncoder
( QString
& sndName, QString
& outputDir,
bool bg, SoundData
*, WaveDisplay
*,
QObject* parent
= 0 );
~WaveEncoder();
protected:
void run();
private:
int EncodeToMp3();
void ProcessTitle( QString&, QString& );
bool LoadBgSound();
SoundData* m_wave;
WaveDisplay* m_WaveDisplay;
/* for the background audio */
signed short* inbuffer;
FMOD::Sound* bgSound;
unsigned int bgBytes; // length in Bytes
unsigned int bgSamples; // length in PCM
/* to call sound::lock() */
void* ptr1;
void* ptr2;
unsigned int len1;
unsigned int len2;
bool m_bgAudio;
};
#endif //__WAVEENCODER_H__
#include <QThread>
class WaveEncoder : public QThread
{
public:
WaveEncoder( QString& sndName, QString& outputDir, bool bg, SoundData*, WaveDisplay*, QObject* parent = 0 );
~WaveEncoder();
protected:
void run();
private:
int EncodeToMp3();
void ProcessTitle( QString&, QString& );
bool LoadBgSound();
SoundData* m_wave;
WaveDisplay* m_WaveDisplay;
QString m_SoundName;
QString m_OutputDir;
/* for the background audio */
signed short* inbuffer;
FMOD::Sound* bgSound;
unsigned int bgBytes; // length in Bytes
unsigned int bgSamples; // length in PCM
/* to call sound::lock() */
void* ptr1;
void* ptr2;
unsigned int len1;
unsigned int len2;
bool m_bgAudio;
};
#endif //__WAVEENCODER_H__
To copy to clipboard, switch view to plain text mode
the ctor
WaveEncoder::WaveEncoder( QString& sndName,
QString& outputDir,
bool bg,
SoundData* sndData,
WaveDisplay* waveDisp,
{
m_SoundName = sndName;
m_OutputDir = outputDir;
m_wave = sndData;
m_WaveDisplay = waveDisp;
}
WaveEncoder::WaveEncoder( QString& sndName,
QString& outputDir,
bool bg,
SoundData* sndData,
WaveDisplay* waveDisp,
QObject* parent )
: QThread(parent)
{
m_SoundName = sndName;
m_OutputDir = outputDir;
m_wave = sndData;
m_WaveDisplay = waveDisp;
}
To copy to clipboard, switch view to plain text mode
and the run method
void WaveEncoder::run()
{
EncodeToMp3();
}
void WaveEncoder::run()
{
EncodeToMp3();
}
To copy to clipboard, switch view to plain text mode
Here is where I create and run the thread:
void WaveWidget::cutSound()
{
WaveEncoder encoder(m_SoundName, m_outputDir, false, m_wave, m_WaveDisplay);
encoder.start();
}
void WaveWidget::cutSound()
{
WaveEncoder encoder(m_SoundName, m_outputDir, false, m_wave, m_WaveDisplay);
encoder.start();
}
To copy to clipboard, switch view to plain text mode
I get this error:
ASSERT failure in QThread::setTerminationEnabled(): Current thread was not started with QThread....
What does mean? And how can I solve this error?
Regards,
Franco
Bookmarks