Artem Sherbachuk
Artem Sherbachuk

Reputation: 131

how to write block with arg. "UnsafeMutablePointer<UnsafeMutablePointer<Float>>" in Swift closure

please help with syntax:

__weak typeof (self) weakSelf = self;
[self.audioFile getWaveformDataWithCompletionBlock:^(float **waveformData,
                                                     int length)
{
    [weakSelf.audioPlot updateBuffer:waveformData[0]
                      withBufferSize:length];
}];

The waveform data itself will be an array of float arrays, one for each channel, and the length indicates the total length of each float array. @param waveformData An array of float arrays, each representing a channel of audio data from the file @param length An int representing the length of each channel of float audio data

in swift I have:

cell.audioFile.getWaveformDataWithCompletionBlock { (UnsafeMutablePointer<UnsafeMutablePointer<Float>>, Int32) -> Void 

}

I stuck on UnsafeMutablePointer>

I need to use this arg. in:

cell.audioWaveView.updateBuffer(buffer: UnsafeMutablePointer, withBufferSize: Int32)

Upvotes: 1

Views: 464

Answers (2)

John Patrick Sloan
John Patrick Sloan

Reputation: 1

Similar to what @FelipeDev.- posted, this question is old but still helped me today (Thanks Felipe!). However, there is a slightly updated answer to this now with the newer versions of EZAudio and Swift. I got this to work with the following code:

var waveClosure: EZAudioWaveformDataCompletionBlock = {
        (waveformData: UnsafeMutablePointer<UnsafeMutablePointer<Float>>, length: Int32) in
        //Do something like update the audio plot buffer if you are plotting the waveform
        self.audioPlot.updateBuffer(waveformData[0], withBufferSize: UInt32(length))
    }
self.audioFile.getWaveformDataWithCompletionBlock(waveClosure)

Hope this helps!

Upvotes: 0

FelipeDev.-
FelipeDev.-

Reputation: 3133

I know this may be an old question, but I was struggling with the same thing and I finally solved:

You need to pass the argument to the block as a WaveformDataCompletionBlock closure, and your parameters should be an UnsafeMutablePointer and a UInt32. So the code should be something like this:

self.audioFile = EZAudioFile(URL: self.soundFileURL)
var waveClosure: WaveformDataCompletionBlock = {
  (waveForData: UnsafeMutablePointer<Float>, length: UInt32) in
  //Do something
}
self.audioFile.getWaveformDataWithCompletionBlock(waveClosure)

I hope this could be useful to somebody :)

Upvotes: 1

Related Questions