Skip to content
This repository has been archived by the owner on Jul 17, 2024. It is now read-only.

Popping when playing multiple sounds #15

Open
NickCulbertson opened this issue Jun 1, 2011 · 3 comments
Open

Popping when playing multiple sounds #15

NickCulbertson opened this issue Jun 1, 2011 · 3 comments

Comments

@NickCulbertson
Copy link

Hey Zoel,
I've been trying to go off of your Finch Code to play multiple sounds at the same time. If the first sound is playing a pop occurs when the second sound begins which I think is a result of the sound not being preloaded to a buffer. I found some other source codes for openal around the web but they negate the ease of Finch.

here is how I create and play the sounds

string1 = [[Sound alloc] initWithFile:[[NSBundle mainBundle] URLForResource:@"Sound1" withExtension:@"wav"]];
string2 = [[Sound alloc] initWithFile:[[NSBundle mainBundle] URLForResource:@"Sound2" withExtension:@"wav"]];
[string1 play];
[string2 play];

also in Sound.m I tried commenting out the stop.

- (void) play
{
    // if (self.playing)
    // [self stop];
    CLEAR_ERROR_FLAG;
    alSourcePlay(source);
    [self checkSuccessOrLog:@"Failed to start sound"];
}

This eliminates the pop from the sounds if the sound is currently playing.

play1 
play2 *pop*
play1 (play1 and play2 still playing) no pop
play2 (play1 and play2 still playing) no pop
play1 (play1 NOT currently playing and play2 still playing) *pop*

I hope that kind of makes sense. The pop occurs when a sound goes from a non playing state to a playing state while the other sound is playing.

Any advice would be appreciated. I'm been on this thing for weeks now.
Thanks,
Nick

@zoul
Copy link
Owner

zoul commented Jun 13, 2011

Same problem experienced by pwightman:

I'm essentially using Finch as a sampler of sorts for when users press notes, it plays the sample I've recorded
corresponding to that note. But every time I call "Stop" on the sound, I get a small but noticeable popping sound. It
happens sometimes when multiple sounds are played at once when the sound begins, but always happens when you
release the sound. Any idea why it might be? I'm not necessarily sure if it has much to do with your code, but I've
searched and searched for why this might be happening and can't find anything that fixes it anywhere.

@NickCulbertson
Copy link
Author

I have a hacky fix. I found that the pop occurs when alSourceStop(source) occurs. Pausing the sound does not cause a pop but you must pause the sound before the sound ends naturally and call the play function again to get the sound to the rest.

so I have

- (void) rewind 
{
    CLEAR_ERROR_FLAG;
    alSourcePlay (source);
    alSourcePause(source);
    // [self performSelector:@selector(rewind2) withObject:self afterDelay:1.1];
}

- (void) play
{
    // if (self.playing)
    // [self stop];
    CLEAR_ERROR_FLAG;
    alSourcePlay(source);
    [self checkSuccessOrLog:@"Failed to start sound"];
}

and when I stop the sound now I call.

sitar.gain=0.01;
[self rewind];

This plays the sound from the start and pauses it instantly. When I play the sound again there are no pops.

Nick

@zoul zoul reopened this Jun 15, 2011
@zoul
Copy link
Owner

zoul commented Jun 15, 2011

Nick, thanks for the info! I’ll leave the issue open until it’s fixed here on GitHub. (Not sure when I’ll have the time yet.)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants