I want to change the code I wrote using AVAudioPCMBuffer on swift to objective-C.

Asked 2 months ago, Updated 2 months ago, 4 views

If you use AVAudioPCMBuffer in swift to write a value to the buffer and sound a sine wave
http://www.tmroyal.com/playing-sounds-in-swift-audioengine.html
It was made by referring to .
I'd like to write this as objective-C, but I'm having a hard time because I don't know how to send a message when I write a value on the buffer.
Here's the swift from the previous site.

for vari=0;i<Int(buffer.frameLength);i+=Int(n_channels){
        varval=sinf (441.0*Float(i)*2*Float(M_PI)/sr)

        buffer.floatChannelData.memory[i] = val * 0.5
    }

When I try to write this in objective-C, buffer.floatChannelData appears as a complement, but memory[i] does not appear as a complement.
Definitely,

 buffer.floatChannelData.memory[i]=val;

I thought I could write in , but how should I write it?

I look forward to your kind cooperation.

swift objective-c avfoundation

2022-09-30 11:54

1 Answers

From the AVAudioPCMBuffer, floatChannelData is declared as UnsafePointer<UnsafeMutablePointer<Float>>, but it means potter.

Swift cannot handle pointers directly, so it is accessed through memory, but is rewritten using an indirect operator as follows:

 *buffer.floatChannelData[i]=val;

Rather than Objective-C, you will need to know more about C language pointers.


2022-09-30 11:54

If you have any answers or tips


© 2022 OneMinuteCode. All rights reserved.