RE: Setting volume programmatically
RE: Setting volume programmatically
- Subject: RE: Setting volume programmatically
- From: "On Lee" <email@hidden>
- Date: Thu, 29 Jul 2010 11:00:08 -0700
I am currently not using mixer.
My experimental code is based on the example listed on
http://www.subfurther.com/blog/?p=1049 specifically the
AUPassThroughWithConnection. Below are the modified code snippets.
Thanks.
Best,
-- On Lee
-(void)setupRemoteIOInstance:(AudioUnit *)theRemoteIO {
// I/O unit description
AudioComponentDescription description;
description.componentType =
kAudioUnitType_Output;
description.componentSubType =
kAudioUnitSubType_RemoteIO; // Remote IO
description.componentManufacturer =
kAudioUnitManufacturer_Apple;
description.componentFlags = 0;
description.componentFlagsMask = 0;
// Get component
AudioComponent inputComponent = AudioComponentFindNext(NULL,
&description);
// Create an audio unit instance
OSStatus status = AudioComponentInstanceNew(inputComponent,
theRemoteIO);
NSAssert(status == noErr, @"AudioComponentInstanceNew fails");
}
-(void)setupEnableIO:(AudioUnit)theUnit {
// Enable input for the I/O unit, which is disabled by default.
OSStatus status = AudioUnitSetProperty(theUnit,
kAudioOutputUnitProperty_EnableIO, kAudioUnitScope_Input, AU_INPUT_BUS,
&enable, sizeof(enable));
NSAssert(status == noErr, @"AudioUnitSetProperty fails");
}
-(AudioStreamBasicDescription)setupStream:(AudioUnit)theUnit {
OSStatus status = noErr;
// Declare an ASBD and initialize its fields to 0. You later apply
this stream format to the output scope of the input element of the I/O unit
AudioStreamBasicDescription asbd = {0};
asbd.mSampleRate = AUDIO_SAMPLE_SAMPLE_RATE;
asbd.mFormatID = kAudioFormatLinearPCM;
asbd.mFormatFlags = kAudioFormatFlagsCanonical;
asbd.mBytesPerPacket = 2;
asbd.mFramesPerPacket = 1;
asbd.mBytesPerFrame = asbd.mBytesPerPacket *
asbd.mFramesPerPacket;
asbd.mChannelsPerFrame = AUDIO_SAMPLE_CHANNEL;
asbd.mBitsPerChannel = AUDIO_SAMPLE_RESOLUTION_IN_BIT;
// Set the format of the input scope of output bus 0
status = AudioUnitSetProperty(theUnit,
kAudioUnitProperty_StreamFormat, kAudioUnitScope_Input, AU_OUTPUT_BUS,
&asbd, sizeof(asbd));
NSAssert(status == noErr, @"AudioUnitSetProperty fails");
// Set the format of output scope of input bus 1
status = AudioUnitSetProperty(theUnit,
kAudioUnitProperty_StreamFormat, kAudioUnitScope_Output, AU_INPUT_BUS,
&asbd, sizeof(asbd));
NSAssert(status == noErr, @"AudioUnitSetProperty fails");
return asbd;
}
// From http://www.subfurther.com/blog/?p=1049 AUPassThroughWithConnection
-(void)setup {
// Create remote IO instance audio unit
[self setupRemoteIOInstance:&ioUnit];
// Enable IO
[self setupEnableIO:ioUnit];
// Setup stream
self.asbdFormat = [self setupStream:ioUnit];
// Callback
[self setupCallback:self];
// Initialize
OSStatus status = AudioUnitInitialize(ioUnit);
NSAssert(status == noErr, @"AudioUnitInitialize fails");
}
-----Original Message-----
From: Kyle Sluder [mailto:email@hidden]
Sent: Thursday, July 29, 2010 10:14 AM
To: On Lee
Cc: email@hidden
Subject: Re: Setting volume programmatically
On Thu, Jul 29, 2010 at 9:31 AM, On Lee <email@hidden> wrote:
> I found the following info:
>
> 1. http://www.subfurther.com/blog/?p=507,: RemoteIO does not have a
> gain or volume property. The mixer unit has volume properties on all input
> buses and its output bus (0). Therefore, setting the mixers output volume
> property could be a de facto volume control, if its the last thing before
> RemoteIO. And its somewhat more appealing than manually multiplying all
> your samples by a volume factor.
Well, I guess the first question is, are you doing anything like using
a mixer unit that might change the volume of your audio?
You should probably show your code, or else this conversation isn't
going to be much more instructive than what you've already read.
--Kyle Sluder
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Coreaudio-api mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden