fandyushin
fandyushin

Reputation: 2432

Nexus 9 primary sample rate

I have an app that uses OpenSL ES. When I try to use it on a Nexus9 6.0.1, I hear a noise like I have the wrong sampling rate. On other devices all is OK.

My SLDataFormat_PCM structure:

SLDataFormat_PCM format_pcm = {
            SL_DATAFORMAT_PCM,
            aChannels,
            48000 * 1000,
            SL_PCMSAMPLEFORMAT_FIXED_16,
            SL_PCMSAMPLEFORMAT_FIXED_16,
            aChannels == 2 ? SL_SPEAKER_FRONT_LEFT | SL_SPEAKER_FRONT_RIGHT
                           : SL_SPEAKER_FRONT_CENTER,
            SL_BYTEORDER_LITTLEENDIAN
    };

When I change the sample rate (+/- 1Hz) in this structure, the output sounds OK, but I receive an AudioTrack debug message:

W/AudioTrack: AUDIO_OUTPUT_FLAG_FAST denied by client; transfer 1, track 47999 Hz, output 48000 Hz

Why do I have a problem in FAST mode, if the Nexus9 has 48000Hz?

I checked it using this method:

jclass clazz = env.getEnv()->FindClass("android/media/AudioSystem");
jmethodID mid = env.getEnv()->GetStaticMethodID(clazz, "getPrimaryOutputSamplingRate", "()I");
int nSampleRate = env.getEnv()->CallStaticIntMethod(clazz, mid);
LOGDEBUG << "Sample Rate: " << nSampleRate;

[ DBG:c894860f] 11:16:14.902: Sample Rate: 48000

Is there a better method to get device's sample rate?

Upvotes: 1

Views: 269

Answers (2)

fandyushin
fandyushin

Reputation: 2432

The problem was with mutex in callback function.

UPD: OpenSLES Readme

Known issues

At 48000Hz, Galaxy Nexus and Nexus 10 produce glitchy output. At 44100Hz, Galaxy Nexus tends to glitch when switching activities or bringing up large dialogs. Touch sounds occasionally cause OpenSL to glitch. It's probably a good idea to disable touch sounds in audio apps. These problems are not specific to opensl_stream and have been reproduced in other settings.

Upvotes: 0

Reaz Murshed
Reaz Murshed

Reputation: 24211

Yes there's a method to find the preferred sample rate for a device though it'll work for API level > 16. You can have a look at my answer here.

And about your SLDataFormat_PCM structure. You've initialized with sample rate 48k*1k! If you want to sample your PCM data in 48k, try using the code below.

// configure audio source
SLDataFormat_PCM format_pcm = {
        SL_DATAFORMAT_PCM,
        aChannels,
        SL_SAMPLINGRATE_48,
        SL_PCMSAMPLEFORMAT_FIXED_16,
        SL_PCMSAMPLEFORMAT_FIXED_16,
        aChannels == 2 ? SL_SPEAKER_FRONT_LEFT | SL_SPEAKER_FRONT_RIGHT
                       : SL_SPEAKER_FRONT_CENTER,
        SL_BYTEORDER_LITTLEENDIAN
};

I didn't work with Nexus 9 before, so I don't know if it supports 48k sampling rate. But, anyway, you can check if it supports.

Upvotes: 1

Related Questions