syedhali / EZAudio

An iOS and macOS audio visualization framework built upon Core Audio useful for anyone doing real-time, low-latency audio processing and visualizations.
Other
4.96k stars 824 forks source link

Use EZAudioFloatConverter directly gets Error: Failed to fill complex buffer in float converter ('insz') error #236

Closed saiday closed 7 years ago

saiday commented 9 years ago

Trying to use EZAudioFFT by AudioBufferList from AVAudioPCMBuffer object, I mimic what EZAudioFFTExample does and convert my AudioBufferList buffers to floatBuffers.

At the time I called [EZAudioUtilities checkResult:AudioConverterFillComplexBuffer(...)]; I got Error: Failed to fill complex buffer in float converter ('insz') error, if I do anything wrong, please inform me!

        AVAudioFile *audioFile = [[AVAudioFile alloc] initForReading:[NSURL fileURLWithPath:tempFilePath] error:nil];
        AVAudioFormat *audioFormat = audioFile.processingFormat;
        UInt32 audioFrameCount = (UInt32) audioFile.length;
        AVAudioPCMBuffer *buffer = [[AVAudioPCMBuffer alloc] initWithPCMFormat:audioFormat frameCapacity:audioFrameCount];
        NSError *error;
        audioFile.framePosition = 50.f * 44100;
        [audioFile readIntoBuffer:buffer frameCount:44100 error:&error];

        EZAudioFFT *fft = [[EZAudioFFT alloc] initWithMaximumBufferSize:4096 sampleRate:44100];
        fft.delegate = self;
        AudioStreamBasicDescription description;
        description.mSampleRate = audioFormat.streamDescription->mSampleRate;
        description.mFormatID = audioFormat.streamDescription->mFormatID;
        description.mFormatFlags = audioFormat.streamDescription->mFormatFlags;
        description.mBytesPerPacket = audioFormat.streamDescription->mBytesPerPacket;
        description.mFramesPerPacket = audioFormat.streamDescription->mFramesPerPacket;
        description.mBytesPerFrame = audioFormat.streamDescription->mBytesPerFrame;
        description.mChannelsPerFrame = audioFormat.streamDescription->mChannelsPerFrame;
        description.mBitsPerChannel = audioFormat.streamDescription->mBitsPerChannel;
        description.mReserved = audioFormat.streamDescription->mReserved;
        EZAudioFloatConverter *floatConverter = [[EZAudioFloatConverter alloc] initWithInputFormat:description];
        float **floatData = [EZAudioUtilities floatBuffersWithNumberOfFrames:4096 numberOfChannels:description.mChannelsPerFrame];
        AudioBufferList *audioBufferList = [EZAudioUtilities audioBufferListWithNumberOfFrames:4096 numberOfChannels:description.mChannelsPerFrame interleaved:[EZAudioUtilities isInterleaved:description]];
        audioBufferList->mNumberBuffers = buffer.audioBufferList->mNumberBuffers;
        audioBufferList->mBuffers[0] = buffer.audioBufferList->mBuffers[0];

        [floatConverter convertDataFromAudioBufferList:audioBufferList withNumberOfFrames:4096 toFloatBuffers:floatData];
        [fft computeFFTWithBuffer:*floatData withBufferSize:1024];