Note that there are some explanatory texts on larger screens.

plurals
  1. POWeird popping noise when playing different sounds with different volumes set through OpenAL on the iPhone
    primarykey
    data
    text
    <p>I'm using OpenAL sound framework on the iPhone, and I'm setting different volumes on individual sounds. I'm running into a problem where I'm hearing an initial popping/clicking noise when switching from one sound to the next.</p> <p>It's really noticeable when I have one sound that's got a high volume (1.0) and a second sound that has a low one (0.2). When I hit the loud sound, and then hit the soft sound, I hear the pop/click. But when I go from the soft sound to the loud, I don't notice anything. So the pop/click really happens when switching from loud to soft sounds.</p> <p>Here's the init sound method:</p> <pre><code> - (id) initWithSoundFile:(NSString *)file doesLoop:(BOOL)loops { self = [super init]; if (self != nil) { if(![self loadSoundFile:file doesLoop:loops]) { debug(@"Failed to load the sound file: %@...", file); [self release]; return nil; } self.sourceFileName = file; //temporary sound queue self.temporarySounds = [NSMutableArray array]; //default volume/pitch self.volume = 1.0; self.pitch = 1.0; } return self; } </code></pre> <p>and here's the play function:</p> <pre><code>- (BOOL) play { if([self isPlaying]) //see if the base source is busy... { //if so, create a new source NSUInteger tmpSourceID; alGenSources(1, &amp;tmpSourceID); //attach the buffer to the source alSourcei(tmpSourceID, AL_BUFFER, bufferID); alSourcePlay(tmpSourceID); //add the sound id to the play queue so we can dispose of it later [temporarySounds addObject: [NSNumber numberWithUnsignedInteger:tmpSourceID]]; //a "callback" for when the sound is done playing +0.1 secs [self performSelector:@selector(deleteTemporarySource) withObject:nil afterDelay:(duration * pitch) + 0.1]; return ((error = alGetError()) != AL_NO_ERROR); } //if the base source isn't busy, just use that one... alSourcePlay(sourceID); return ((error = alGetError()) != AL_NO_ERROR); } </code></pre> <p>and here's the function where i set the volume for each sound immediately after playing (ive tried setting it before playing too):</p> <pre><code>- (void) setVolume:(ALfloat)newVolume { volume = MAX(MIN(newVolume, 1.0f), 0.0f); //cap to 0-1 alSourcef(sourceID, AL_GAIN, volume); //now set the volume for any temporary sounds... for(NSNumber *tmpSourceID in temporarySounds) { //tmpSourceID is the source ID for the temporary sound alSourcef([tmpSourceID unsignedIntegerValue], AL_GAIN, volume); } } </code></pre> <p>Any help is greatly appreciated as I've tried everything I can think of. I would be so grateful.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload