ソースの表示以前のリビジョンバックリンク全て展開する/折り畳む文書の先頭へ Share via Share via... Twitter LinkedIn Facebook Pinterest Telegram WhatsApp Yammer Reddit Teams最近の変更Send via e-Mail印刷パーマリンク × 目次 QA1016: オーディオ装置の音量変更 質問: オーディオ装置の音量を変更するにはどうすればよいのでしょうか。 関連項目 改訂履歴 QA1016: オーディオ装置の音量変更 原文 Technical Q&A QA1016: Changing the volume of audio devices http://developer.apple.com/qa/qa2006/qa1016.html 質問: オーディオ装置の音量を変更するにはどうすればよいのでしょうか。 回答: オーディオハードウェアの音量を変更するには、まずAudioDeviceを取得し、その装置が音量調節が出来るかどうかを確認しなければなりません。 AudioHardwareGetPropertyメソッドとkAudioHardwarePropertyDefaultOutputDevice / kAudioHardwarePropertyDefaultSystemOutputDevice定数を使うことで、デフォルト出力装置やシステム出力装置を得ることが出来ます。 全ての装置がマスターボリューム調節や各チャンネルごとの調節に対応しているとは限りません。 Listing 1: デフォルト出力装置を取得する UInt32 size; AudioDeviceID outputDevice; AudioHardwareGetProperty(kAudioHardwarePropertyDefaultOuputDevice, &size, &outputDevice); 装置を取得してから、その装置が音量コントロールを持っているか、そしてその内容を書き換えられるかどうか確認します。 Listing 2: 装置の能力を取得する bool CAAudioHardwareDevice::HasProperty( UInt32 inChannel, CAAudioHardwareDeviceSectionID inSection, AudioHardwarePropertyID inPropertyID) const { OSStatus theError = AudioDeviceGetPropertyInfo(mAudioDeviceID, inChannel, inSection, inPropertyID, NULL, NULL); return theError == 0; } bool CAAudioHardwareDevice::PropertyIsSettable( UInt32 inChannel, CAAudioHardwareDeviceSectionID inSection, AudioHardwarePropertyID inPropertyID) const { Boolean isWritable = false; OSStatus theError = AudioDeviceGetPropertyInfo(mAudioDeviceID, inChannel, inSection, inPropertyID, NULL, &isWritable); ThrowIfError(theError, CAException(theError), "CAAudioHardwareDevice::PropertyIsSettable: " "プロパティ情報取得中にエラー発生"); return isWritable != 0; } bool CAAudioHardwareDevice::HasVolumeControl( UInt32 inChannel, CAAudioHardwareDeviceSectionID inSection) const { return HasProperty(inChannel, inSection, kAudioDevicePropertyVolumeScalar); } bool CAAudioHardwareDevice::VolumeControlIsSettable( UInt32 inChannel, CAAudioHardwareDeviceSectionID inSection) const { return PropertyIsSettable(inChannel, inSection, kAudioDevicePropertyVolumeScalar); } kAudioDevicePropertyVolumeScalar定数を引数にAudioDeviceSetPropertyメソッドを呼ぶと、装置の音量を設定することが出来ます。 音量は0~1のFloat32値で表し、装置の音量値へとスケーリングされます。 Listing 3: マスターチャンネルの音量を設定する AudioDeviceSetProperty(theDevice, NULL, // タイムスタンプ(必要ありません) 0, // チャンネル0がマスターチャンネル false, // 出力装置用 kAudioDevicePropertyVolumeScalar, sizeof(Float32), &theValue ); 関連項目 CoreAudio Documentation CoreAudio Mailing List CAAudioHardwareDevice - /Developer/Examples/CoreAudio/PublicUtility/CAAudioHardwareDevice PublicUtility - /Developer/Examples/CoreAudio/PublicUtility/ 改訂履歴 Date Notes 2006-05-02 第1版 掲載日: 2006-05-02 translation/adc/audio/technical_qa/qa1016_changing_the_volume_of_audio_devices.txt 最終更新: 2015-01-06 11:51(外部編集)