Quantcast
Channel: Android Mode - Processing 2.x and 3.x Forum
Viewing all articles
Browse latest Browse all 941

A problem with performance using AudioRecord class

$
0
0

Greetings! In fact it is not a real problem, but i need some explanations about the reason causing that issue. So, i was making some simple dictaphone for my android device with a realtime waveform drawing. When i initialize AudioRecord object using stereo channels it's working fine, i got ~30 fps. But when i'm trying to use mono regime my fps falls to 12-15. Here is some code:

constants i'm using:

final int RECORDER_SAMPLERATE = 44100;
final int RECORDER_CHANNELS = AudioFormat.CHANNEL_IN_STEREO;
final int RECORDER_AUDIO_ENCODING = AudioFormat.ENCODING_PCM_16BIT;

recorder initializing:

bufferSize = AudioRecord.getMinBufferSize(RECORDER_SAMPLERATE,RECORDER_CHANNELS,RECORDER_AUDIO_ENCODING);
audioRecord = new AudioRecord(MediaRecorder.AudioSource.MIC,
                            RECORDER_SAMPLERATE, RECORDER_CHANNELS,RECORDER_AUDIO_ENCODING, bufferSize);

drawing waveform:

bufferReadResult = audioRecord.read(buffer, 0, inShorts);
x = 0;
    for(int i = 0; i < buffer.length; i += inc){
        newY = height/2 + (int)map(buffer[i], -40000,40000, -300,300);
        newX = x+1;
        line(x,y,newX, newY);
        x = newX;
        y = newY;
    }

inShorts it's just bufferSize/2 cause i'm using short arrays. In fact, i should divide mybuffer array in two arrays for each channel, but here where the problem is. When i'm trying to draw a single channel or use AudioFormat.CHANNEL_IN_MONO instead of stereo, i've got very low performance. The question is: why it is so? I checked that my microphone is a mono device.


Viewing all articles
Browse latest Browse all 941

Trending Articles