1
votes

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.

1
Do you mean you want to convert it back to the time-domain? If yes, then your fft library surely have an inverse-fft method for spectrum-to-time-domain transformation. (wav file is the standard of an audio file format, it's got nothing to do with converting back from spectral to time domain) - Itamar Katz
And btw, by "process myFFT.inputData[i]" you mean doing the fft transform, right...? - Itamar Katz
yes i mean i want to convert to time domain back i used - (void)doIFFT { rdft(self.dataLength, -1, self.inputData, ip, w); self.dataIsFrequency = NO; } but i not know about result from this process and i not know how to make it to wav file or play it. thank you - Ibos
myFFT.inputData[i] is not FFT fucntion tranform this is my project mediafire.com/?j7f7ibo2481b1h7 - Ibos

1 Answers

0
votes

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