We are about to switch to a new forum software. Until then we have removed the registration on this forum.
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.
Answers
@aiz7103::: there is (as for me!!!) not any "reason" why changing from stereo to mono makes the fps falls but as your code (which is a standard android one) is only for stereo i cannot guess what happens. (what is "inc"???, how do you you change from buffer to shorts[] and so on; why are you talking about buffer.size as you are using [inShorts]???) give a code which does not work...
@akenaton ok, here is the code that anyone can launch, it also has some answers on your questions:
it works great. All i need to make my fps to fall down it's just change:
final int RECORDER_CHANNELS = AudioFormat.CHANNEL_IN_STEREO;
with:final int RECORDER_CHANNELS = AudioFormat.CHANNEL_IN_MONO;
@MarcoReverse=== i tested your code with P3 and a real device; it works fine stereo or mono....in the two cases i get 26 or 27 fps. So i cannot see what to do...
@akenaton intresting. Maybe it's all about my device.
@aiz7103=== yes, probably, or with your os; android docs says that only stereo mode is "garanteed" to work, which means that some device with some os fail with mono.
@akenaton thanks for your time.