Im works under kubuntu 12.10 and develops an application in which I need to generate sound in a QIODevice, and then play it using QAudioOutput.
I read all the literature, talking about how to do it right, and I think I did it.
So far I have done:
QVector <double> * soundData = SoundGenerator::getSound();
soundBuffer->open(QIODevice::ReadWrite);
QDataStream writeStream(soundBuffer);
foreach(double d, *soundData) {
char value = d * (2 << 7);
writeStream << value;
}
QAudioFormat format;
format.setSampleRate(SoundGenerator::getAudioSampleRate());
format.setChannelCount(1);
format.setSampleSize(8);
format.setCodec("audio/pcm");
format.setByteOrder(QAudioFormat::LittleEndian);
format.setSampleType(QAudioFormat::SignedInt);
QAudioDeviceInfo info(QAudioDeviceInfo::defaultOutputDevice());
audio = new QAudioOutput(format, this);
if (audio->error() != QAudio::NoError) {
qDebug() << "Problem playing sound";
}
connect(audio, SIGNAL(stateChanged(QAudio::State)), this, SLOT(aboutToFinish(QAudio::State)));
I also have a call to audio> start (soundBuffer)
- from another slot I have no error initializing QAudioOutput
And I do not have NO SOUND AT ALL (all other applications have sound, and Im port Qt4 application to Qt5, in Qt4 everything is fine with Phonon)
The aboutToFinish slot is called at the beginning with ActiveState as a state and NoError when QAudioOutput :: error is called, but it is no longer called, even if it expects much longer than the expected duration of the sound.
, wav , .
, Qts, , (, sprectrum), , .
- ? ? - ?
;)