audio - Android AudioRecord Noise Appear -


i use audiorecord class write audio data file.

problem: following code working well.but when encoding parameter changed encoding_pcm_8bit or encoding_pcm_float, noises appear.

question: why , reason?

does have working example encoding_pcm_float write audio data file? used float [] buffer, not write data file correctly.

example code:

    public void run() {         process.setthreadpriority(process.thread_priority_urgent_audio);         audiorecord audiorecord = null;         fileoutputstream wavout = null;         try {             audiorecord = new audiorecord(audio_source, sample_rate, channel_mask, encoding, buffer_size);             wavout = new fileoutputstream(wavfile);     // write title wav file             writewavheader(wavout, sample_rate, channel_mask, encoding);              bytebuffer bytebuffer = bytebuffer.allocatedirect(buffer_size);             int read;             long total = 0;             audiorecord.startrecording();      // todo: сalculate recording time              long max = math.min(4294967295l, (long)44100*16*10/8);              while (true) {                 read = audiorecord.read(bytebuffer, buffer_size, audiorecord.read_blocking);                  if (total + read > max) {                      // todo                     /*for (int = 0; < read && total <= lon; i++, total++) {                         wavout.write(buffer[i]);                     }*/                      break;                 } else {                     //byte [] = short2byte2(buffer, read);                     //byte [] = floatarray2bytearray(buffer, read);                      wavout.write(bytebuffer.array(), 0, read);                      total += read;                 }             }         } catch (ioexception e) {             // todo         } {             if (audiorecord != null) {                 if (audiorecord.getrecordingstate() == audiorecord.recordstate_recording) {                     audiorecord.stop();                 }                 if (audiorecord.getstate() == audiorecord.state_initialized) {                     audiorecord.release();                 }             }             if (wavout != null) {                 try {                     wavout.close();                 } catch (ioexception ignore) {                 }             }         }         try {             updatewavheader(wavfile);         } catch (ioexception ex) {             //wavfile.delete();         }     } 

at values:

audio_source = mediarecorder.audiosource.mic; sample_rate = 44100; channel_mask = audioformat.channel_in_mono; encoding = audioformat.encoding_pcm_16bit; buffer_size = 4 * audiorecord.getminbuffersize(sample_rate, channel_mask, encoding); 


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -