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.94k stars 821 forks source link

Waveform of a audioFile (but not RMS) #332

Open noetits opened 8 years ago

noetits commented 8 years ago

Hello,

I would like do plot the data of a sound file. Not the RMS value of the signal but the signal itself. It would probably not be possible to draw the entire sound file on the screen and have something understandable but if we zoom a lot we could see the signal.

But I don't know how to do this in EZaudio. In the WaveformFromFile example I can see the code:

//------------------------------------------------------------------------------------- [self.audioFile getWaveformDataWithNumberOfPoints:1024 completion:^(float **waveformData, int length) { [weakSelf.audioPlot updateBuffer:waveformData[0] withBufferSize:length]; }]; //-------------------------------------------------------------------------------------

So I should probably put the raw data of the file for updateBuffer instead of waveFormData. I tried using an AudioBufferList to get the data (here only the 512 frames) of the audioFile like this :

//------------------------------------------------------------------------------------- // Allocate a buffer list to hold the file's data UInt32 frames = 512; AudioBufferList bufferList = [EZAudioUtilities audioBufferListWithNumberOfFrames:512 numberOfChannels:1 interleaved:YES]; UInt32 bufferSize=0; // Read function will populate this value BOOL eof; // Read function will populate this value // Reads 512 frames from the audio file [self.audioFile readFrames:frames audioBufferList:bufferList bufferSize:&bufferSize eof:&eof]; [weakSelf.audioPlot updateBuffer:(float )bufferList->mBuffers[0].mData withBufferSize:bufferSize]; //-------------------------------------------------------------------------------------

But I have this error : "Error: Failed to read audio data from file (-50)" . But I think I don't understand well how the AudioBufferList works.

I read in the issue of @nick-thompson : #323

Every time you call readFrames, it will read a certain number of frames and call through to the delegate method with the data for those frames. One approach you can take is to loop and read until eof while you process the data in the delegate.

answered by @dxclancy

Maybe this is what I should do too? I'm new to objective-c, therefore I don't understand well the working of a delegate method...

Thank you in advance !