分体式两种渠道CHANNEL_IN_STEREO的AudioRecord的 [英] split two channels of AudioRecord of CHANNEL_IN_STEREO

查看:1569
本文介绍了分体式两种渠道CHANNEL_IN_STEREO的AudioRecord的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用的Andr​​oid手机(注3)立体声录音的项目。但是,我需要从不同的渠道(左,右)分裂的数据。如何执行你知道吗?

现在,我用AudioRecord录制内置麦克风的声音。我可以记录,保存的声音.RAW和.wav文件。

有些codeS如下:

 私人INT audioSource = MediaRecorder.AudioSource.MIC;
私有静态诠释sampleRateInHz = 44100;
私有静态诠释channelConfig = AudioFormat.CHANNEL_IN_STEREO;
私有静态诠释AudioFormat的= AudioFormat.ENCODING_PCM_16BIT;


bufferSizeInBytes = AudioRecord.getMinBufferSize(sampleRateInHz,
            channelConfig,AudioFormat的);

audioRecord =新AudioRecord(audioSource,sampleRateInHz,
            channelConfig,AudioFormat的,bufferSizeInBytes);

//一些其他的codeS ....

//从audioRecord数据
READSIZE = audioRecord.read(audiodata,0,bufferSizeInBytes);
 

解决方案

最后,我得到了答案。我用的android手机立体声录音。而以AudioFormat是PCM_16BIT。

 私人INT audioSource = MediaRecorder.AudioSource.MIC;
私有静态诠释sampleRateInHz = 48000;
私有静态诠释channelConfig = AudioFormat.CHANNEL_IN_STEREO;
私有静态诠释AudioFormat的= AudioFormat.ENCODING_PCM_16BIT;
 

,这意味着存储在缓冲器中的数据如下:

  leftChannel数据:[0,1],[4,5] ...
rightChannel数据:[2,3],[6,7] ...
 

所以,立体声录音分裂数据的code。

  READSIZE = audioRecord.read(audioShortData,0,bufferSizeInBytes);
的for(int i = 0; I< READSIZE / 2,I = I + 2)
{
       leftChannelAudioData [i] = audiodata [2 * I]
       leftChannelAudioData [I + 1] = audiodata [2 * I + 1];
       rightChannelAudioData [I] = audiodata [2 * I + 2];
       rightChannelAudioData [I + 1] = audiodata [2 * i + 3中];
}
 

然后你就可以将数据写入到文件中。

  leftChannelFos =新的FileOutputStream(rawLeftChannelDataFile);
rightChannelFos =新的FileOutputStream(rawRightChannelDataFile);
leftChannelBos =新的BufferedOutputStream(leftChannelFos);
rightChannelBos =新的BufferedOutputStream(rightChannelFos);
leftChannelDos =新DataOutputStream类(leftChannelBos);
rightChannelDos =新DataOutputStream类(rightChannelBos);

leftChannelDos.write(leftChannelAudioData);
rightChannelDos.write(rightChannelAudioData);
 

编程快乐!

I'm working on a project using stereo record of the Android phones (note 3). But I need to split the data from different channels (right, left). Any idea of how to perform that?

Now, I use AudioRecord to record the sound of internal microphones. And I can record, save the sound to .raw and .wav files.

Some codes as follows.

private int audioSource = MediaRecorder.AudioSource.MIC;  
private static int sampleRateInHz = 44100;  
private static int channelConfig = AudioFormat.CHANNEL_IN_STEREO;  
private static int audioFormat = AudioFormat.ENCODING_PCM_16BIT;


bufferSizeInBytes = AudioRecord.getMinBufferSize(sampleRateInHz,  
            channelConfig, audioFormat);  

audioRecord = new AudioRecord(audioSource, sampleRateInHz,  
            channelConfig, audioFormat, bufferSizeInBytes);

// some other codes....

//get the data from audioRecord
readsize = audioRecord.read(audiodata, 0, bufferSizeInBytes); 

解决方案

Finally, I got the answers. I used stereo record of android phone. And the audioFormat is PCM_16BIT.

private int audioSource = MediaRecorder.AudioSource.MIC;  
private static int sampleRateInHz = 48000;  
private static int channelConfig = AudioFormat.CHANNEL_IN_STEREO;  
private static int audioFormat = AudioFormat.ENCODING_PCM_16BIT;  

which means the data stored in buffer as follows.

leftChannel data: [0,1],[4,5]...
rightChannel data: [2,3],[6,7]...

So the code of splitting data of stereo record.

readSize = audioRecord.read(audioShortData, 0, bufferSizeInBytes);
for(int i = 0; i < readSize/2; i = i + 2)
{
       leftChannelAudioData[i] = audiodata[2*i];
       leftChannelAudioData[i+1] = audiodata[2*i+1]; 
       rightChannelAudioData[i] =  audiodata[2*i+2];
       rightChannelAudioData[i+1] = audiodata[2*i+3];
}

Then you can write the data to file.

leftChannelFos = new FileOutputStream(rawLeftChannelDataFile);
rightChannelFos = new FileOutputStream(rawRightChannelDataFile);
leftChannelBos = new BufferedOutputStream(leftChannelFos);
rightChannelBos = new BufferedOutputStream(rightChannelFos);
leftChannelDos = new DataOutputStream(leftChannelBos);
rightChannelDos = new  DataOutputStream(rightChannelBos);

leftChannelDos.write(leftChannelAudioData);
rightChannelDos.write(rightChannelAudioData);

Happy coding!

这篇关于分体式两种渠道CHANNEL_IN_STEREO的AudioRecord的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆