0

I'm playing a prerecorded sound using a technique from an apple sample:

    // Set up the pieces needed to play a sound.
    if (clickSound == NULL) {
        NSBundle *mainBundle = [NSBundle mainBundle];
        clickSound = [[SoundEffect alloc] initWithContentsOfFile:[mainBundle pathForResource:@"clickdown" ofType:@"wav"]];
    }

    // Play the sound.
    [clickSound play];

This works, but the resulting sound is far louder than intended. This is not a problem with the sound volume for the device; the sound itself seems to have been amplified, and changing the amplitude of the original sound using a sound editor does not change the playback volume on the iPhone. I believe the original sound is being amplified by SoundEffect so the peak volume meets some system standard, but that's exactly what I don't want: I'm after a softer, gentler sound, to paraphrase an aging politician.

How do I set the volume of the sound for a prerecorded sound sample?

Mike
  • 3,084
  • 1
  • 25
  • 44

1 Answers1

2

Use the volume property of AVAudioPlayer. Like this:

  clickSound.volume = 0.5;  
OFRBG
  • 1,653
  • 14
  • 28
  • Thanks--that was close enough to get me to the answer. I was using an old class from a really old Apple sample, apparently predating iOS 2.2. It didn't support volume. AVAudioPlayer dropped in to replace it nicely, though, and didn't have the same issue described above, so I actually didn't need to adjust the volume, although the method you described worked just fine to do so. – Mike Jun 26 '12 at 16:04