gyetvan-andras / cocoa-waveform

A cocoa audio player component which displays the waveform of the audio file.
260 stars 58 forks source link

Using NSData possible? #7

Closed MattW86 closed 11 years ago

MattW86 commented 11 years ago

Hello,

I have NSData representation of some audio files.. Can I still use this extension?

Thanks.. Matt

gyetvan-andras commented 11 years ago

Hello,

the current implementation expects an URL to open the AudioFile. I do not know if you can create an URL to your NSData, so you should take a look at WaveSampleProvider::processSample. This method loads the audio data and convert it to PCM format. At the beginning there is a call to ExtAudioFileOpenURL (line 116), which initializes an ExtAudioFileRef parameter (named extAFRef), which is used to load the audio data. If you want to get audio data from an NSData source, you should use ExtAudioFileWrapAudioFileID to initialize that ExtAudioFileRef. This API call expects and AudioFileID, which can be obtained from AudioFileOpenWithCallbacks. Please note that there is a similar call in line 123, AudioFileOpenURL, which creates an AudioFileID from the URL, you should remove this call, of course.

So, if you replace the ExtAudioFileOpenURL-AudioFileOpenURL with ExtAudioFileWrapAudioFileID-AudioFileOpenWithCallbacks you should be able to use the rest of the code. (I'm just googled and there is a thread at http://stackoverflow.com/questions/17330135/decode-mp3-file-from-nsdata)

Hope this helps, Andras