tanhakabir / SwiftAudioPlayer

Streaming and realtime audio manipulation with AVAudioEngine
https://medium.com/chameleon-podcast/creating-an-advanced-streaming-audio-engine-for-ios-9fbc7aef4115
MIT License
561 stars 109 forks source link

1 'AVAudioPlayerNode' instance per engine? #54

Open NI92 opened 3 years ago

NI92 commented 3 years ago

The engine currently has a single playerNode = AVAudioPlayerNode(). Are there plans to allow streaming of multiple sounds at the same time?

I see that SAPlayer uses player = AudioStreamEngine(withRemoteUrl: url, delegate: presenter) to initiate streaming data into the engine itself. But the engine only has a single AVAudioPlayerNode pointer (playerNode). How difficult would it be to create an array of AVAudioPlayerNode ?


Next day follow up:

I created a StreamingAudioPlayerNode object & an accompanying AudioURLStream object & carried logic out of the AudioStreamEngine (& some logic out of the AudioEngine) & placed it inside the AudioURLStream object.

Now AudioEngine has an array of StreamingAudioPlayerNode objects. I pass a URL into the engine & it creates an StreamingAudioPlayerNode instance. Calling play makes the streamed audio work on a device (I even used URL's from your example project for testing). However, streaming of multiple audio sources still does NOT work.

I'm guessing the issue lies deeper within the library (haven't completely studied it) & how buffers are created, or something like that. Any ideas what I can try doing?

nt4f04uNd commented 3 years ago

Create multiple SAPlayer instances? Is that not possible?

I get what you mean, the SAPlayer essentially creates the instance of AVAudioEngine, but as a workaround to your problem.

NI92 commented 3 years ago

The biggest issue is I'm trying to 'connect' the underlying AVAudioPlayer to another node. Which means the there can only be 1 AVAudioEngine for all the nodes I connect.

tanhakabir commented 3 years ago

Hey! Sorry and caching up to these issues now. Could you elaborate on the exact use case you're trying to do? You have an AVAudioPlayer that you want to connect to this engine?

kuamanet commented 2 years ago

Hi @tanhakabir, I think that he's having the same "issue" I'm running into, basically it would be nice to have multiple AVAudioPlayerNode on the main engine, while keeping all of the features you already developed (awesome job btw).

You think that we can achieve that adding support directly to the AudioEngine classes? Or rather adding a new engine that adheres to the AudioEngineProtocol?

Problem with the second approach would be that we (probably) want all of the behaviours of the AudioDiskEngine and AudioStreamEngine, as in "I would like to play in the same time a local file and a remote file".

What do you think? I can help with this if you want!