对录音的基本了解

时间:2013-03-11 20:03:56

标签: android audio-recording

使用AudioRecord录制时,我在计算每帧的时间时遇到问题。因此,如果有人可以成为兄弟,并解释非常感谢的基础知识。

以下是什么意思?

  • sampleRate - 是您作为样本提供的字节数吗?或者成为要使用AudioRecord检查的样本的字节数
  • FFT - 简单来说是什么意思?
  • 你如何计算时间?你用buffersize / frameByteSize计算它吗?

参考从Jacquet Wong复制的示例代码

public class RecorderThread extends Thread {

private AudioRecord audioRecord;
private boolean isRecording;
private int channelConfiguration = AudioFormat.CHANNEL_CONFIGURATION_MONO;
private int audioEncoding = AudioFormat.ENCODING_PCM_16BIT;
private int sampleRate = 44100;
private int frameByteSize = 2048; // for 1024 fft size (16bit sample size)
byte[] buffer;

public RecorderThread(){
    int recBufSize = AudioRecord.getMinBufferSize(sampleRate, channelConfiguration, audioEncoding); // need to be larger than size of a frame
    audioRecord = new AudioRecord(MediaRecorder.AudioSource.MIC, sampleRate, channelConfiguration, audioEncoding, recBufSize);
    buffer = new byte[frameByteSize];
}

public AudioRecord getAudioRecord(){
    return audioRecord;
}

public boolean isRecording(){
    return this.isAlive() && isRecording;
}

public void startRecording(){
    try{
        audioRecord.startRecording();
        isRecording = true;
    } catch (Exception e) {
        e.printStackTrace();
    }
}

public void stopRecording(){
    try{
        audioRecord.stop();
        isRecording = false;
    } catch (Exception e) {
        e.printStackTrace();
    }
}

public byte[] getFrameBytes(){
    audioRecord.read(buffer, 0, frameByteSize);

    // analyze sound
    int totalAbsValue = 0;
    short sample = 0; 
    float averageAbsValue = 0.0f;

    for (int i = 0; i < frameByteSize; i += 2) {
        sample = (short)((buffer[i]) | buffer[i + 1] << 8);
        totalAbsValue += Math.abs(sample);
    }
    averageAbsValue = totalAbsValue / frameByteSize / 2;

    //System.out.println(averageAbsValue);

    // no input
    if (averageAbsValue < 30){
        return null;
    }

    return buffer;
}

public void run() {
    startRecording();
}

}

抱歉,我不是一个容易学习录音的人。我似乎无法点击它。希望你们能用这些问题来启发我。

0 个答案:

没有答案