real time - Android Realtime mic data to array -
i want data mic , store in byte array processing. have tried code given below gives errors on recorder.record function.
i have tried lot of stuff not worth it. please me.
public class audiorecordthread implements runnable { @override public void run() { int bufferlength = 0; int buffersize; short[] audiodata; int bufferreadresult; mediarecorder recorder=new mediarecorder(); recorder.start(); try { int sampleaudiobitrate=44100; buffersize = audiorecord.getminbuffersize(sampleaudiobitrate, audioformat.channel_configuration_mono, audioformat.encoding_pcm_16bit); if (buffersize <= 2048) { bufferlength = 2048; } else if (buffersize <= 4096) { bufferlength = 4096; } audiorecord audiorecord; /* set audio recorder parameters, , start recording */ audiorecord = new audiorecord(mediarecorder.audiosource.mic, sampleaudiobitrate, audioformat.channel_configuration_mono, audioformat.encoding_pcm_16bit, bufferlength); audiodata = new short[bufferlength]; audiorecord.startrecording(); log.d("my activity", "audiorecord.startrecording()"); boolean isaudiorecording = true; boolean isrecorderstart=true; /* ffmpeg_audio encoding loop */ while (isaudiorecording) { bufferreadresult = audiorecord.read(audiodata, 0, audiodata.length); if (bufferreadresult == 1024 && isrecorderstart) { buffer realaudiodata1024 = shortbuffer.wrap(audiodata, 0, 1024); *********************************** recorder.record(realaudiodata1024); *********************************** } else if (bufferreadresult == 2048 && isrecorderstart) { buffer realaudiodata2048_1=shortbuffer.wrap(audiodata, 0, 1024); buffer realaudiodata2048_2=shortbuffer.wrap(audiodata, 1024, 1024); (int = 0; < 2; i++) { if (i == 0) { *********************************** recorder.record(realaudiodata2048_1); *********************************** } else if (i == 1) { *********************************** recorder.record(realaudiodata2048_2); *********************************** } } } } /* encoding finish, release recorder */ if (audiorecord != null) { try { audiorecord.stop(); audiorecord.release(); } catch (exception e) { e.printstacktrace(); } audiorecord = null; } if (recorder != null && isrecorderstart) { try { recorder.stop(); recorder.release(); } catch (exception e) { e.printstacktrace(); } recorder = null; } } catch (exception e) { log.e("my activity", "get audio data failed:"+e.getmessage()+e.getcause()+e.tostring()); } } }
Comments
Post a Comment