iOS Development

Audio Pan to maneuver sound from left proper and vice versa in iOS

Spread the love


I’m writing code the place consumer can set the pan worth from slider from -1 to 1 in decimals like

-1.0, -0.9, 0.8 …… 0 ….. 0.1 …. 0.9, 1.0

When worth is about a scheduler is being began that robotically units the pan worth in vary that consumer has chosen. Let say consumer has chosen -0.9, it means the schedular will regulate audio pan from -0.9 to 0.9

Concern:

When i modify the Pan in schedular,
let say i transfer the worth from -0.1 in direction of -1.0, it produces a pur / noise sound in proper speaker
and let say if i transfer the worth from 0.1 in direction of 1.0, it produces a pur / noise sound in left speaker

Evaluation:

i) Every time audio pan worth is about in direction of left audio system it generates a noise in reverse (proper) speaker

ii) Every time audio pan worth is about in direction of proper audio system it generates a noise in reverse (left) speaker

I’ve additionally added code for extra clarification

- (void) setupAutoPanAdjuster:(double)panValue velocity:(double)speedValue {
    self.velocity = speedValue;
    self.vary = (int)fabs((panValue*100.0));
    if (self.velocity == 0.0) {
        self.velocity = 0.1/kPanDivider;
    }
    [self startSliderUpdateLoop];
}

- (void) startSliderUpdateLoop {
    [self stopSliderUpdateLoop];
    self.sliderUpdateTimer = [NSTimer scheduledTimerWithTimeInterval:self.speed
                                                              target:self
                                                            selector:@selector(updateSlider)
                                                            userInfo:nil
                                                             repeats:YES];
}

- (void) stopSliderUpdateLoop {
    [self.sliderUpdateTimer invalidate];
    self.sliderUpdateTimer = nil;
}

- (void) resetPan {
    [self stopSliderUpdateLoop];
    [self updatePanValue:0.0];
}

- (void) updateRange:(double) panValue {
    self.vary = (int)((panValue*100.0));
    [self updatePanValue:(self.currentValue)/100.0];
}

// MARK: - HANDLE PAN

- (void) updateSlider {
    dispatch_async(dispatch_get_main_queue(), ^{
        if (self.isIncreasing) {
            self.currentValue++;
            if (self.currentValue >= self.vary) {
                self.isIncreasing = NO;
            }
        } else {
            self.currentValue--;
            if (self.currentValue <= -self.vary) {
                self.isIncreasing = YES;
            }
        }
        
        [self updatePanValue:(self.currentValue)/100.0];
    });
}

-(void) updatePanValue:(double) panValue {
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
        [self setPanForMixerInput:swPlayer.eqMixerUnit inputNum:envInputNum panValue: panValue];
        [self setPanForMixerInput:swPlayer.eqMixerUnit inputNum:alarmInputNum panValue: panValue];
        [self setPanForMixerInput:swPlayer.outputMixerUnit inputNum:renderInputNum panValue: panValue];
        [self setPanForMixerInput:swPlayer.outputMixerUnit inputNum:eqInputNum panValue: panValue];
        [self setPanForMixerInput:swPlayer.outputMixerUnit inputNum:alarmInputNum panValue: panValue];
    });
}

- (void)setPanForMixerInput:(AudioUnit)mixerUnit inputNum:(UInt32)inputBus panValue:(AudioUnitParameterValue)panValue {
    dispatch_async(dispatch_get_main_queue(), ^{
        CheckError(AudioUnitSetParameter(
                        mixerUnit,
                        kMultiChannelMixerParam_Pan,
                        kAudioUnitScope_Input,
                        inputBus,
                        panValue,
                        0
                        ), "Setting pan for mixer enter failed");
    });
}

4 thoughts on “Audio Pan to maneuver sound from left proper and vice versa in iOS

  1. I loved you better than you would ever be able to express here. The picture is beautiful, and your wording is elegant; nonetheless, you read it in a short amount of time. I believe that you ought to give it another shot in the near future. If you make sure that this trek is safe, I will most likely try to do that again and again.

  2. I loved you better than you would ever be able to express here. The picture is beautiful, and your wording is elegant; nonetheless, you read it in a short amount of time. I believe that you ought to give it another shot in the near future. If you make sure that this trek is safe, I will most likely try to do that again and again.

Leave a Reply

Your email address will not be published. Required fields are marked *