简体   繁体   中英

How to lower sound on the iphone's sdk Audioqueue?

I'm using Aran Mulhollan' RemoteIOPlayer, using audioqueues in the SDK iphone. I can without problems: - adding two signals to mix sounds - increasing sound volume by multiplying the UInt32 I get from the wav files

BUT every other operation gives me warped and distorted sound, and in particular I can't divide the signal. I can't seem to figure out what I'm doing wrong, the actual result of the division seems fine; some aspect of sound / signal processing must obviously be eluding me :)

Any help appreciated !

Have you tried something like this?

- (void)setQueue:(AudioQueueRef)ref toVolume:(float)newValue {
  OSStatus rc = AudioQueueSetParameter(ref, kAudioQueueParam_Volume, newValue);
  if (rc) {
    NSLog(@"AudioQueueSetParameter returned %d when setting the volume.\n", rc);
  }
}

First of all the code you mention does not use AudioQueues, it uses AudioUnits. The best way to mix audio in the iphone is using the mixer units that are inbuilt, there is some code on the site you downloaded your original example from here . Other than that what i would check in your code os that you have the correct data type. Are you trying your operations on Unsigned ints when you should be using signed ones? often that produces warped results (understandably)

The iPhone handles audio as 16-bit integer. Most audio files are already normalized so that the peak sample values are the maximum that fit in a 16-bit signed integer. That means if you add two such samples together, you get overflow, or in this case, audio clipping. If you want to mix two audio sources together and ensure there's no clipping, you must average the samples: add them together and divide by two. Or you set the volume to half. If you're using decibels, that would be about a -6 dB change.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM