I have an array of double (size more than 60k entries), I have the frequency value. Now I want to create a sound from it using C/C++ which I can play
-
I have an array of double (size more than 60k entries), I have the frequency value. Now I want to create a sound from it using C/C++ which I can play on speaker.
-
Hi,
You can convert your data array to floats and use QAudioOutput from QtMultimedia module to play the sound. You can inform QAudioOutput of the format of your data (sampling frequency, number of channels, data type, ...) via a QAudioFormat. -
hey unai_i thanks for reply .....i ahve no experience on Qaudiooutput and QtMultimedia can u provide some sample code in which i can get step by step solution.........
-
Simple example:
http://qt-project.org/doc/qt-5/qtmultimedia-audiooutput-example.htmlAdvanced example:
http://qt-project.org/doc/qt-5/qtmultimedia-spectrum-example.html -
Hi,
something along the lines of the snippet below adapted from the "documentation":http://qt-project.org/doc/qt-5/qaudiooutput.html example should work. Note that I have not tested this so it may require some changes.
@
QVector<double> yourData;
QBuffer buffer;
float tmp = 0;
for(int i=0; i < yourData.count(); i++)
{
tmp = yourData[i];
buffer.write((char*) &tmp, 4);
}
buffer.seek(0);QAudioOutput* audio;
QAudioFormat format;
// Set up the format, eg.
format.setSampleRate(8000); // adapt this to your needs
format.setChannelCount(1); // adapt this to your needs
format.setSampleSize(32); // float32
format.setCodec("audio/pcm");
format.setByteOrder(QAudioFormat::LittleEndian); // adapt this to your needs
format.setSampleType(QAudioFormat::Float);QAudioDeviceInfo info(QAudioDeviceInfo::defaultOutputDevice());
if (!info.isFormatSupported(format)) {
qWarning() << "Raw audio format not supported by backend, cannot play audio.";
return;
}audio = new QAudioOutput(format); // don't forget to delete when not needed anymore
audio.start(&buffer);
@ -
hey thanks a lot but when i included QAudiooutput class that show no such file and directory...after that i included QT+ = multimedia in my .pro file but getting same error ...i am using qt 4.7.....
-
Which OS are you on? Capitalization might matter (QAudioOutput, not QAudiooutput)
-
working on windows7
-
Which compiler?
Qt 4.7 is very old, but I got multimedia working with the MinGW 4.4 compiler before.
Can you please post your .pro file?