I have a Qt code with a QSound object that is supposed to read two wav files on a thread.
My code works on iOS simulator, but not on Android.
My thread code that reads wav files :
ClickThread::ClickThread(): highClickFile("://high_click.wav"), lowClickFile("://low_click.wav"), isRunning(false)
{
this->highClick = new QSound(highClickFile);
this->lowClick = new QSound(lowClickFile);
this->setPeriod(120);
}
void ClickThread::process(){
while(this->isRunning == true)
{ if(!this->isRunning) break;
highClick->play();
QThread::msleep(period);
highClick->stop();
if(!this->isRunning) break;
lowClick->play();
QThread::msleep(period);
lowClick->stop();
if(!this->isRunning) break;
lowClick->play();
QThread::msleep(period);
lowClick->stop();
if(!this->isRunning) break;
lowClick->play();
QThread::msleep(period);
lowClick->stop();
}
}
There is the error message I got :
W linker : Warning: "/data/data/org.qtproject.example.MyProject/qt-reserved-files/plugins/audio/libqtaudio_opensles.so" has unsupported flags DT_FLAGS_1=0x80 (ignoring unsupported flags)
D : PlayerBase::PlayerBase()
D : TrackPlayerBase::TrackPlayerBase()
I libOpenSLES: Emulating old channel mask behavior (ignoring positional mask 0x4, using default mask 0x1 based on channel count of 1)
I AudioTrack: createTrack_l(0): AUDIO_OUTPUT_FLAG_FAST successful; frameCount 0 -> 1322
E android.media.AudioTrack: getMinBufferSize(): Invalid audio format.
W libc : malloc(4294967292) failed: returning null pointer
F libc : /Volumes/Android/buildbot/src/android/ndk-release-r20/external/libcxx/../../external/libcxxabi/src/abort_message.cpp:73: abort_message: assertion "terminating with uncaught exception of type std::bad_alloc: std::bad_alloc" failed
F libc : Fatal signal 6 (SIGABRT), code -1 (SI_QUEUE) in tid 7670 (QtThread), pid 6740 (.MyProject)
Thanks for your answers
P
EDIT :
The problem was that my wav file was encoded in 24 bits. Android doesn't seem to use this kind of encoding for PCM files, referring to this website : https://developer.android.com/reference/android/media/AudioFormat we only can have 8, 16 or 32 bits.
So, I used FFmpeg to encode my wav files in 16 bits and now my code works ! Check that link for an exemple of encoding with FFmpeg : ffmpeg FLAC 24 bit 96khz to 16 bit 48khz
Pierre.