Audio samples don't work on Android



  • Hello, so my app records audio and does audio processing on it.

    It works perfectly on Desktop, but on Mobile I don't seem to get any correct floating point audio samples.
    I use a chart to show the value of all samples and the Android version seems to only receive values of value 0 and negative values, but nothing that makes sense.

    Here are screenshots of what I mean:
    Desktop screenshot
    As you can see, on Desktop the audio samples are good.

    However, on mobile I only get weird values (values <= 0):
    Mobile screenshot

    When I try the audio example app from Qt, that does similar audio processing, I get correct samples on Android as well. But this example app uses integer samples. I need the floating point samples though.

    Here is my code for setting up the audio recording:

    m_format.setSampleRate(SAMPLE_RATE);
    // mono sound
    m_format.setChannelCount(1);
    // aubio requires float
    m_format.setSampleType(QAudioFormat::SampleType::Float);
    // floats have a size of 32 bit
    m_format.setSampleSize(sizeof(float) * 8);
    m_format.setCodec("audio/pcm");
    m_rec = new QAudioInput(m_format, this);
    

    Any idea what could be wrong with floating point samples on Android?

    If you need the full source code, it's available here: https://github.com/magnus-gross/quickpitch



  • OK, I found the problem. Qt doesn't support float samples on Android at all and changes the format to integer samples, even if you explicitly specify floating point samples. The QAudioDeviceInfo provides a isFormatSupported method to check for these cases.

    I now proceeded to write a int to float conversion method and it works well now.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.