close
// init
// recorder thread run
// thread end
參考網站
m_read_buf_size = AudioRecord.getMinBufferSize(Audio_Struct.WAV_SAMPLERATE,AudioFormat.CHANNEL_IN_MONO,AudioFormat.ENCODING_PCM_16BIT);
m_in_rec = new AudioRecord(MediaRecorder.AudioSource.MIC,
Audio_Struct.WAV_SAMPLERATE,
AudioFormat.CHANNEL_CONFIGURATION_MONO,
AudioFormat.ENCODING_PCM_16BIT,
m_read_buf_size);
randomAccessWriter = new RandomAccessFile(Environment.getExternalStorageDirectory().getPath() + "/my.wav", "rw");
randomAccessWriter.setLength(0);
randomAccessWriter.writeBytes("RIFF");
randomAccessWriter.writeInt(0); // Final file size not known yet, write 0
randomAccessWriter.writeBytes("WAVE");
randomAccessWriter.writeBytes("fmt ");
randomAccessWriter.writeInt(Integer.reverseBytes(16)); // Sub-chunk size, 16 for PCM
randomAccessWriter.writeShort(Short.reverseBytes((short) 1)); // AudioFormat, 1 for PCM
randomAccessWriter.writeShort(Short.reverseBytes((short) 1));// Number of channels, 1 for mono, 2 for stereo
randomAccessWriter.writeInt(Integer.reverseBytes(SampleRate)); // Sample rate
randomAccessWriter.writeInt(Integer.reverseBytes(SampleRate*NumberOfChannels*BitsPerSample/8)); // Byte rate
randomAccessWriter.writeShort(Short.reverseBytes((short)(NumberOfChannels*BitsPerSample/8))); // Block align
randomAccessWriter.writeShort(Short.reverseBytes((short) 16)); // Bits per sample
randomAccessWriter.writeBytes("data");
randomAccessWriter.writeInt(0); // Data chunk size not known yet, write 0
// recorder thread run
read_size = m_in_rec.read(m_in_bytes, 0, m_in_buf_size);
randomAccessWriter.write(m_in_bytes); // Write buffer to file
totalSize += read_size;
// thread end
randomAccessWriter.seek(4);
randomAccessWriter.writeInt(Integer.reverseBytes(36+totalSize);
randomAccessWriter.seek(40); // Write size to Subchunk2Size field
randomAccessWriter.writeInt(Integer.reverseBytes(totalSize));
randomAccessWriter.close();
參考網站
全站熱搜
留言列表