android - AudioRecord returns some empty data after start -
i wrote standard code receiving data microphone using audiorecord. here code:
audioreceiver() { int minhardwarebuffersize = audiorecord.getminbuffersize(sample_rate, channel_config, audio_format); log.d(tag, "minhardwarebuffersize = " + minhardwarebuffersize); int buffersizebytes = (minhardwarebuffersize > min_buffer_size_bytes) ? minhardwarebuffersize : min_buffer_size_bytes; buffersizeshorts = buffersizebytes / 2; //резервируем буфер с запасом в 2 раза audiorecorder = new audiorecord(mediarecorder.audiosource.mic, sample_rate, channel_config, audio_format, buffersizebytes * 2); teststack = new short[buffersizeshorts * 4]; arrays.fill(teststack, (short) 2000); } boolean startreceive() { audiorecorder.startrecording(); isreceiving = true; int recordingstate = audiorecorder.getrecordingstate(); log.d(tag, "recordingstate = " + recordingstate); new thread(receivingrunnable).start(); return (recordingstate == audiorecord.recordstate_recording); } boolean stopreceive() { isreceiving = false; audiorecorder.stop(); int recordingstate = audiorecorder.getrecordingstate(); log.d(tag, "recordingstate = " + recordingstate); return (recordingstate == audiorecord.recordstate_stopped); } private runnable receivingrunnable = new runnable() { @override public void run() { int readcount = 0; short[] databuffer = new short[buffersizeshorts]; while (isreceiving) { testbusy = true; (int j = 0; j < 4; j++) { readcount = audiorecorder.read(databuffer, 0, databuffer.length); log.d(tag, "receive " + readcount + " bytes"); system.arraycopy(databuffer, 0, teststack, buffersizeshorts * j, readcount); } isreceiving = false; testbusy = false; } } };
but noticed after first start of startreceive function, @ beginning of teststack buffer, there empty data (about 1000 samples on nexus 4, see data graph).
between initialization of audioreceiver , launch of startreceive takes long time. cause of problem?
Comments
Post a Comment