QAudioOutput in Qt5 makes no sound

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);
    //  qDebug() << "Value : " << (short int)value;
    writeStream << value;
}

QAudioFormat format;
// Set up the format, eg.
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), , .

- ? ? - ?

;)

0
2

, 8 .

: 8- :

format.setSampleType(QAudioFormat::UnsignedInt);

Qt. ? , WAV 8- , 16- . .

, 16- :

format.setSampleType(QAudioFormat:SignedInt);

(IMHO , Qt , , , , ).

: https://ccrma.stanford.edu/courses/422/projects/WaveFormat/

( , 16-): Qt QAudioOutput push mode

+1

:

QEventLoop loop;

loop.exec();

+1

All Articles