mertguner / sound_generator

This plugin is a procedural sound generator.
MIT License
29 stars 26 forks source link

Issue with creating two instances of SoundGenerator #23

Closed gitmole7 closed 9 months ago

gitmole7 commented 1 year ago

I'm attempting to create two instances of the generator to play two different sounds at once, and having problems getting it to work, not sure if it is possible or if anyone has a workaround?

bhavesh379 commented 9 months ago

hi, @gitmole7 Did you get any chance to solve this issue, are you able to generate 2 sounds at the same time?

gitmole7 commented 9 months ago

Hi Bhavesh, yes I did figure out a workaround which has worked well for playing two sounds at once, although it may not be the best way of handling things if you wanted to add many more SoundGenerator instances.

It required some changes to the native code. For Android, in the SoundGeneratorPlugin.java I created a second instance:

private SoundGenerator soundGenerator = new SoundGenerator(); private SoundGenerator soundGenerator2 = new SoundGenerator(); // Second instance of SoundGenerator

For the new instance to work, I also added play, stop, volume methods .etc for the new instance:

if (call.method.equals("play2")) { soundGenerator2.startPlayback(); } else if (call.method.equals("stop2")) { soundGenerator2.stopPlayback(); .etc

Make sure to initialize the second instance, too:

if (call.method.equals("init")) { int sampleRate = call.argument("sampleRate"); result.success(soundGenerator.init(sampleRate)); soundGenerator2.init(sampleRate); // Initialize the second instance

For iOS, do the same thing in SwiftSoundGeneratorPlugin.swift, adding second instances of anything you want to be able to use independently on the second SoundGenerator instance:

var oscillator2: AKOscillator = AKOscillator(); var panner2: AKPanner?; var mixer2: AKMixer?; .etc

case "play2": self.oscillator2.start() result(nil); break; case "stop2": self.oscillator2.stop() result(nil); break;

I hope that helps!

bhavesh379 commented 9 months ago

Thanks a lot @gitmole7 yes it will help, I was supposed to do the same but was in doubt if straight forward approach is there. Your approach make sense. thanks again:).

moriciogithub commented 2 months ago

@gitmole7 Can you please provide the sample code you generated to get this thing done. I'm not that proficient in Java to do this.

Thanks in advance

Mauricio

bhavesh379 commented 1 month ago

@gitmole7 I am done with android multiple instances to generate and play multiple audios at a time but not able to do the same in iOS as there is single audiokit can play at a time. could you please help in that if anything you can do?

bhavesh379 commented 1 month ago

hi @moriciogithub are you done with multiple audio play?

moriciogithub commented 1 month ago

hi @moriciogithub are you done with multiple audio play?

I did it for Android not for iOS. I can share it with you.

bhavesh379 commented 1 month ago

Thanks @moriciogithub Same thing that I also did for Android but not for iOS. iOS needs help