FFT音频输入 [英] FFT audio input

查看:303
本文介绍了FFT音频输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想申请FFT上记录AudioRecorder并保存为WAV文件的信号。我现在用的FFT有一个复杂的[]输入参数。我很困惑,有没有从字节COMLEX分割的实部将通过32768,并只需添加0的虚部转换,并留下一个字节之间的区别是什么?

编辑:

 公共复杂[] convertToComplex(byte []的文件)
{


    INT大小= file.length;
    双[]×=新的双[尺寸]
    复[]数据=新的复杂【尺寸】;
    的for(int i = 0; I<大小;我++)
    {
        X [i] =文件[I] /32768.0;
        数据[I] =新复合物(X [I]中,0);
        // Log.d(标签,指数之+ I +:+数据[I]);
    }
    返回的数据;
}
 

解决方案

如果您正在使用音频位深度为16位(每个样品有16位),然后每个字节只会有一半sample.What的你需要做的是投你的字节到16位采样,然后通过32768除以得到的数字(这是最小号的幅度的2的补16位的数字可以存储即2 ^ 15),以获得实际的音频采样这是一种介于-1和1。你数量将随后通过它的虚分量设置为0这个数转换为复数。

一个小的C#示例可以看出以下(指示code):

 字节[] myAudioBytes = readAudio();
    INT的numBytes = myAudioBytes.Length;

    VAR myAudioSamples =名单,其中,短期>();

    的for(int i = 0; I<的numBytes; I = I + 2)
    {
      //强制转换为16位音频,然后加样
       短样本=(短)((myAudioBytes [1]  - ;&所述; 8 | myAudioBytes [I + 1])/ 32768);
       myAudioSamples.Add(样品);
    }

    //改变真实音频到复杂的音频

    复[] complexAudio =新的复杂[myAudioSamples.Length]

    INT I = 0;
    的foreach(在myAudioSamples短样品)
       complexAudio [我+ +] =新的复杂(){实=样品,虚= 0};

   //现在您可以继续让你的音频的FFT这里
 

望code具有引导你,你应该如何处理您的声音。

I want to apply FFT on a signal recorded by AudioRecorder and saved to a wav file. the FFT i am using has a Complex[] input parameter. I am confused, is there a difference between converting from bytes to comlex dividing by 32768, and converting by just adding 0 to the imaginary part and leaving the real part as a byte?

Edit:

public Complex[] convertToComplex(byte[] file)
{


    int size= file.length;
    double[]x=new double[size];
    Complex[]data= new Complex[size];
    for(int i=0;i<size;i++)
    {
        x[i]=file[i]/32768.0;
        data[i]=new Complex(x[i],0);
        //  Log.d("tag", "indice"+i+":"+data[i]);
    }
    return data;
}

解决方案

If you are working with audio with a bit depth of 16 bits (each sample has 16 bits), then each byte will only have half of a sample.What you need to do is cast your bytes to 16 bit samples then divide the resulting number by 32768 (This is the magnitude of the smallest number a 2's complement 16 bit number can store i.e 2^15) to get the actual audio sample which is a number between -1 and 1.You will then convert this number to a complex number by setting it's imaginary component to 0.

A small C# sample can be seen below (indicative code):

    byte[] myAudioBytes = readAudio();
    int numBytes = myAudioBytes.Length;

    var myAudioSamples = List<short>();

    for( int i = 0; i < numBytes; i = i + 2)
    {
      //Cast to 16 bit audio and then add sample
       short sample = (short) ((myAudioBytes[i] << 8 | myAudioBytes[i + 1]) / 32768 ); 
       myAudioSamples.Add(sample);
    }

    //Change real audio to Complex audio

    Complex[] complexAudio = new Complex[myAudioSamples.Length];

    int i = 0;
    foreach(short sample in myAudioSamples)
       complexAudio[i++] = new Complex(){ Real = sample, Imaginary = 0 };

   //Now you can proceed to getting the FFT of your Audio here

Hope the code has guided you on how you should handle your audio.

这篇关于FFT音频输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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