开发者

How to convert byte array to wav file <OOURAFFT>

I want to convert a byte array to a wav file

MyAudioFile  *audioFile = [[MyAudioFile alloc]init];
OSStatus result = [audioFile open:@"MySound" ofType:@"wav"];
int numFrequencies=16384;
int kNumFFTWindows=10;  

OouraFFT *myFFT = [[OouraFFT alloc] initForSignalsOfLength:numFrequencies*2 andNumWindows:kNumFFTWindows];
for(long i=0; i<myFFT.dataLength; i++)
{
    myFFT.inputData[i] = (double)audioFile.audioData[i];  开发者_运维知识库  
}

Then I process myFFT.inputData[i] to remove background noise, but i don't know HOW TO convert myFFT.inputData[i] back to a wav file.

Thank you for any help.


If you use an FFT to convert time domain data into frequency domain data, then you can use an inverse FFT or IFFT to convert complex frequency domain data back into the time domain.

If you only have a complex FFT routine, then for complex vector X of length N:

IFFT(X) = scale * complexConjugate(FFT(complexConjugate(X)))

where scale is usually 1/N, 1/sqrt(N), or 1.0, depending on the scale factor used in the forward FFT.

Note that the wave file header also contains the number of channels You might have to do some data (de)interleaving as well as data type conversion. Endianess may also be an issue depending on your computer's ISA.

ADDED:

Assuming a suitable data type for each PCM sample, and appropriate interleaving for stereo/mono, you can use this description of the canonical .wav (RIFF) file format to add/remove 44 bytes of header: WAVE PCM soundfile format

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜