0

我正在使用此代码 https://stackoverflow.com/questions/23432398/audio-recorder-in-android-process-the-audio-bytes来捕获麦克风音频,但我正在将数据写入 ByteArrayOutputStream。完成记录后,我想对使用 Goertzel 算法捕获的信号进行解模块。FSK 信号由 2 个频率组成,“1”为 800Hz,“0”为 400Hz,每个位使用 100 个样本进行模块化。我正在使用此类 Goertzel:http ://courses.cs.washington.edu/courses/cse477/projectwebs04sp/cse477m/code/public/Goertzel.java我正在尝试使用 150 的 bin 大小。

这是我尝试做的事情:完成录制后的代码:

private void stopRecording()
{
    if(recorder != null)
    {
        isRecording= false;
        recorder.stop();
        recorder.release();
        recorder = null;
        recordingThread = null;

        int BlockSize = 150;
        float HighToneFrequency = 800;
        float LowToneFrequency = 400;
        byte[] byteArrayData = ByteArrayAudioData.toByteArray();

        /*final AudioTrack audioTrack = new AudioTrack(AudioManager.STREAM_MUSIC,
        8000, AudioFormat.CHANNEL_OUT_MONO,
        AudioFormat.ENCODING_PCM_16BIT, byteArrayData.length,
        AudioTrack.MODE_STATIC);
        audioTrack.write(byteArrayData, 0, byteArrayData.length);

        audioTrack.play();*/

        double[] daOriginalSine = convertSample2Sine(byteArrayData);

        int i = 0;

        while(i < daOriginalSine.length)
        {
             double t1 = testSpecificFrequency(i, HighToneFrequency,BlockSize, daOriginalSine);
             double t2 = testSpecificFrequency(i, LowToneFrequency,BlockSize, daOriginalSine);
             i+=BlockSize;
        }



    }

}

和函数testSpecificFrequency:

private double testSpecificFrequency(int startIndex, float ToneFreq, int BlockSize, double[] sample) 
    {
         Goertzel g = new Goertzel(RECORDER_SAMPLERATE, ToneFreq, BlockSize, false);
         g.initGoertzel();
         for(int j=startIndex ; j<startIndex+BlockSize ; j++)
         {
             g.processSample(sample[j]);
         }

         double res= Math.sqrt(g.getMagnitudeSquared());
         return res;
    }

我只是想看看会是什么结果,通过向构造函数发送 800Hz,然后发送 400Hz,真的不知道如何从这一点开始 =\

有任何想法吗?

4

0 回答 0