2
// AudioSettings.cs: Implements strongly typed access for AV audio settings
4
// Authors: Marek Safar (marek.safar@gmail.com)
6
// Copyright 2012, Xamarin Inc.
8
// Permission is hereby granted, free of charge, to any person obtaining
9
// a copy of this software and associated documentation files (the
10
// "Software"), to deal in the Software without restriction, including
11
// without limitation the rights to use, copy, modify, merge, publish,
12
// distribute, sublicense, and/or sell copies of the Software, and to
13
// permit persons to whom the Software is furnished to do so, subject to
14
// the following conditions:
16
// The above copyright notice and this permission notice shall be
17
// included in all copies or substantial portions of the Software.
19
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
22
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
23
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
24
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
25
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30
using MonoMac.Foundation;
31
using MonoMac.CoreFoundation;
32
using MonoMac.ObjCRuntime;
33
using MonoMac.AudioToolbox;
35
namespace MonoMac.AVFoundation {
37
// Should be called AVAudioSetting but AVAudioSetting has been already used by keys class
39
public class AudioSettings : DictionaryContainer
42
public AudioSettings ()
43
: base (new NSMutableDictionary ())
47
public AudioSettings (NSDictionary dictionary)
52
public AudioFormatType? Format {
54
SetNumberValue (AVAudioSettings.AVFormatIDKey, (int?) value);
57
return (AudioFormatType?)GetInt32Value (AVAudioSettings.AVFormatIDKey);
61
public float? SampleRate {
63
SetNumberValue (AVAudioSettings.AVSampleRateKey, value);
66
return GetFloatValue (AVAudioSettings.AVSampleRateKey);
70
public int? NumberChannels {
72
SetNumberValue (AVAudioSettings.AVNumberOfChannelsKey, value);
75
return GetInt32Value (AVAudioSettings.AVNumberOfChannelsKey);
79
public int? LinearPcmBitDepth {
81
if (!(value == 8 || value == 16 || value == 24 || value == 32))
82
throw new ArgumentOutOfRangeException ("value must be of 8, 16, 24 or 32");
84
SetNumberValue (AVAudioSettings.AVLinearPCMBitDepthKey, value);
87
return GetInt32Value (AVAudioSettings.AVLinearPCMBitDepthKey);
91
public bool? LinearPcmBigEndian {
93
SetBooleanValue (AVAudioSettings.AVLinearPCMIsBigEndianKey, value);
96
return GetBoolValue (AVAudioSettings.AVLinearPCMIsBigEndianKey);
100
public bool? LinearPcmFloat {
102
SetBooleanValue (AVAudioSettings.AVLinearPCMIsFloatKey, value);
105
return GetBoolValue (AVAudioSettings.AVLinearPCMIsFloatKey);
109
public bool? LinearPcmNonInterleaved {
111
SetBooleanValue (AVAudioSettings.AVLinearPCMIsNonInterleaved, value);
114
return GetBoolValue (AVAudioSettings.AVLinearPCMIsNonInterleaved);
118
public AVAudioQuality? AudioQuality {
120
SetNumberValue (AVAudioSettings.AVEncoderAudioQualityKey, (int?) value);
123
return (AVAudioQuality?) GetInt32Value (AVAudioSettings.AVEncoderAudioQualityKey);
127
public AVAudioQuality? SampleRateConverterAudioQuality {
129
SetNumberValue (AVAudioSettings.AVSampleRateConverterAudioQualityKey, (int?) value);
132
return (AVAudioQuality?) GetInt32Value (AVAudioSettings.AVSampleRateConverterAudioQualityKey);
136
public int? EncoderBitRate {
138
SetNumberValue (AVAudioSettings.AVEncoderBitRateKey, value);
141
return GetInt32Value (AVAudioSettings.AVEncoderBitRateKey);
145
public int? EncoderBitRatePerChannel {
147
SetNumberValue (AVAudioSettings.AVEncoderBitRatePerChannelKey, value);
150
return GetInt32Value (AVAudioSettings.AVEncoderBitRatePerChannelKey);
154
public int? EncoderBitDepthHint {
156
if (value < 8 || value > 32)
157
throw new ArgumentOutOfRangeException ("value is required to be between 8 and 32");
159
SetNumberValue (AVAudioSettings.AVEncoderBitDepthHintKey, value);
162
return GetInt32Value (AVAudioSettings.AVEncoderBitDepthHintKey);
166
public AudioChannelLayout ChannelLayout {
168
SetNativeValue (AVAudioSettings.AVChannelLayoutKey, value == null ? null : value.AsData ());