Android 卡拉OK
protected void arp() {
int sampleRateInHz = 44100;
int rec_bufsize = AudioRecord.getMinBufferSize(sampleRateInHz, AudioFormat.CHANNEL_IN_MONO, AudioFormat.ENCODING_PCM_16BIT);
int play_bufsize = AudioTrack.getMinBufferSize(sampleRateInHz, AudioFormat.CHANNEL_OUT_MONO, AudioFormat.ENCODING_PCM_16BIT);
// MediaRecorder.AudioSource.MIC
AudioRecord audioRecord = new AudioRecord(
MediaRecorder.AudioSource.MIC,
sampleRateInHz,
AudioFormat.CHANNEL_IN_MONO,
AudioFormat.ENCODING_PCM_16BIT,
rec_bufsize);
AudioTrack audioTrack = new AudioTrack(
AudioManager.STREAM_MUSIC,
sampleRateInHz,
AudioFormat.CHANNEL_OUT_MONO,
AudioFormat.ENCODING_PCM_16BIT,
play_bufsize,
AudioTrack.MODE_STREAM);
byte[] temp = new byte[16];
audioRecord.startRecording();
audioTrack.play();
while (!stop) {
audioRecord.read(temp, 0, temp.length);
audioTrack.write(temp, 0, temp.length);
}
audioTrack.stop();
audioRecord.stop();
audioRecord.release();
}
0 件のコメント:
コメントを投稿