3
我試圖從麥克風錄製聲音。聲音是根據在背景中運行的音色進行採樣的。在Android中混合揚聲器和麥克風的音頻
爲了清楚說明我想在背景中運行音調,並且當我從麥克風發出一些噪音時,應該將其與已播放的背景音調混合。
最終輸出應該是所演奏的音調和來自麥克風的噪音信號的混合。我怎樣才能做到這一點。
我在提到Android : recording audio using audiorecord class play as fast forwarded在stackoverflow記錄數據從麥克風。但我需要記錄背景音調以及麥克風輸入。
public class StartRecording {
private int samplePerSec = 8000;
public void Start(){
stopRecording.setEnabled(true);
bufferSize = AudioRecord.getMinBufferSize(samplePerSec, AudioFormat.CHANNEL_IN_MONO, AudioFormat.ENCODING_PCM_16BIT);
audioRecorder = new AudioRecord(MediaRecorder.AudioSource.MIC, this.samplePerSec, AudioFormat.CHANNEL_IN_MONO, AudioFormat.ENCODING_PCM_16BIT, bufferSize * 10);
audioRecorder.startRecording();
isRecording = true;
while (isRecording && audioRecorder.getRecordingState() == AudioRecord.RECORDSTATE_RECORDING)
{
short recordedData[] = new short[bufferSize];
audioRecorder.read(recordedData, 0, recordedData.length); // Reading from the audiorecorder
byte[] bData = shortTobyte(recordedData);
}
}
}
private byte[] shortTobyte(short[] recordedData) {
int tempBuff = recordedData.length;
byte[] bytes = new byte[tempBuff * 10];
for (int i = 0; i < tempBuff; i++) {
bytes[i * 2] = (byte) (recordedData[i] & 0x00FF);
bytes[(i * 2) + 1] = (byte) (recordedData[i] >> 8);
recordedData[i] = 0;
}
return bytes;
}
在此先感謝...
做到了嗎? – param