文書の表示以前のリビジョンバックリンク全て展開する/折り畳む文書の先頭へ この文書は読取専用です。文書のソースを閲覧することは可能ですが、変更はできません。もし変更したい場合は管理者に連絡してください。 ====== QA1016: オーディオ装置の音量変更 ====== 原文 //Technical Q&A QA1016: Changing the volume of audio devices [[http://developer.apple.com/qa/qa2006/qa1016.html]]// ===== 質問: オーディオ装置の音量を変更するにはどうすればよいのでしょうか。 ===== 回答: オーディオハードウェアの音量を変更するには、まずAudioDeviceを取得し、その装置が音量調節が出来るかどうかを確認しなければなりません。 <html><code>AudioHardwareGetProperty</code></html>メソッドと<html><code>kAudioHardwarePropertyDefaultOutputDevice</code></html> / <html><code>kAudioHardwarePropertyDefaultSystemOutputDevice</code></html>定数を使うことで、デフォルト出力装置やシステム出力装置を得ることが出来ます。 <note> 全ての装置がマスターボリューム調節や各チャンネルごとの調節に対応しているとは限りません。 </note> **Listing 1:** デフォルト出力装置を取得する <code c++> UInt32 size; AudioDeviceID outputDevice; AudioHardwareGetProperty(kAudioHardwarePropertyDefaultOuputDevice, &size, &outputDevice); </code> 装置を取得してから、その装置が音量コントロールを持っているか、そしてその内容を書き換えられるかどうか確認します。 **Listing 2:** 装置の能力を取得する <code c++> 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); } </code> <html><code>kAudioDevicePropertyVolumeScalar</code></html>定数を引数に<html><code>AudioDeviceSetProperty</code></html>メソッドを呼ぶと、装置の音量を設定することが出来ます。 音量は0~1のFloat32値で表し、装置の音量値へとスケーリングされます。 **Listing 3:** マスターチャンネルの音量を設定する <code c++> AudioDeviceSetProperty(theDevice, NULL, // タイムスタンプ(必要ありません) 0, // チャンネル0がマスターチャンネル false, // 出力装置用 kAudioDevicePropertyVolumeScalar, sizeof(Float32), &theValue ); </code> ===== 関連項目 ===== * [[http://developer.apple.com/documentation/MusicAudio/CoreAudio-date.html|CoreAudio Documentation]] * [[http://lists.apple.com/mailman/listinfo/coreaudio-api|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(外部編集)