• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Sound Level
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Sound Level


  • Subject: Re: Sound Level
  • From: Shaun Wexler <email@hidden>
  • Date: Mon, 7 Apr 2003 18:14:19 -0700

On Monday, April 7, 2003, at 05:46 AM, Lorenzo wrote:

Hi, how to control the sound level of the Mac, and
ho to control the sound level of my Cocoa application?

NSSound is not the answer. So please, what?


Use some simple CoreAudio HAL calls:

UInt32 direction = 0; // 0 = output, 1 = input
UInt32 left = 0, right = 1;
UInt32 deviceID;
UInt32 propertySize;
UInt32 stereoChannels[2];
float channelVolume[2];
OSStatus status;

// get the deviceID for the default system output device
propertySize = sizeof(deviceID);
status = AudioHardwareGetProperty(kAudioHardwarePropertyDefaultSystemOutputDevice , & propertySize, &deviceID);

// get channel numbers, so you know which channels are left and right
propertySize = sizeof(stereoChannels);
status = AudioDeviceGetProperty(deviceID, NULL, direction, kAudioDevicePropertyPreferredChannelsForStereo, &propertySize, &stereoChannels);

// read the current volume scalar settings [0..1]
propertySize = sizeof(float);
status = AudioDeviceGetProperty(deviceID, stereoChannels[left], direction, kAudioDevicePropertyVolumeScalar, &propertySize, &channelVolume[left]);
status = AudioDeviceGetProperty(deviceID, stereoChannels[right], direction, kAudioDevicePropertyVolumeScalar, &propertySize, &channelVolume[right]);

// adjust the volumes to taste (example)
channelVolume[left] *= 0.50f; // set left output volume to 50% of current value
channelVolume[right] *= 0.50f; // set right output volume to 50% of current value

// apply the new settings
//propertySize = sizeof(float); // if needed
status = AudioDeviceSetProperty(deviceID, stereoChannels[left], direction, kAudioDevicePropertyVolumeScalar, propertySize, &channelVolume[left]);
status = AudioDeviceSetProperty(deviceID, stereoChannels[right], direction, kAudioDevicePropertyVolumeScalar, propertySize, &channelVolume[right]);


Disclaimer: normal result status/error checking deleted for brevity, written in Mail.app, untested. Enjoy!
--
Shaun Wexler
MacFOH
http://www.macfoh.com
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
References: 
 >Sound Level (From: Lorenzo <email@hidden>)

  • Prev by Date: Re: Broken Nib
  • Next by Date: Reading a legacy file format
  • Previous by thread: Re: Sound Level
  • Next by thread: Re: Sound Level
  • Index(es):
    • Date
    • Thread