/[svn]/linuxsampler/trunk/src/drivers/audio/AudioOutputDeviceCoreAudio.h
ViewVC logotype

Contents of /linuxsampler/trunk/src/drivers/audio/AudioOutputDeviceCoreAudio.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1884 - (show annotations) (download) (as text)
Mon Apr 13 15:09:18 2009 UTC (12 years ago) by iliev
File MIME type: text/x-c++hdr
File size: 9180 byte(s)
* CoreAudio: the default value for BUFFERSIZE is now 256
* CoreAudio: use the internal 32-bit floating point rendering

1 /***************************************************************************
2 * *
3 * LinuxSampler - modular, streaming capable sampler *
4 * *
5 * Copyright (C) 2009 Grigor Iliev *
6 * *
7 * This program is free software; you can redistribute it and/or modify *
8 * it under the terms of the GNU General Public License as published by *
9 * the Free Software Foundation; either version 2 of the License, or *
10 * (at your option) any later version. *
11 * *
12 * This program is distributed in the hope that it will be useful, *
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15 * GNU General Public License for more details. *
16 * *
17 * You should have received a copy of the GNU General Public License *
18 * along with this program; if not, write to the Free Software *
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, *
20 * MA 02111-1307 USA *
21 ***************************************************************************/
22
23 #ifndef _AUDIOOUTPUTDEVICECOREAUDIO_H
24 #define _AUDIOOUTPUTDEVICECOREAUDIO_H
25
26 #include "../../common/atomic.h"
27 #include "../../common/Mutex.h"
28 #include "../../common/Thread.h"
29
30 #include "AudioOutputDevice.h"
31 #include "CAAudioDeviceModel.h"
32
33 #include <AudioToolbox/AudioToolbox.h>
34 #include <CoreAudio/CoreAudio.h>
35
36 namespace LinuxSampler {
37
38 /** Core Audio audio output driver
39 *
40 * Implements audio output to the Core Audio architecture.
41 */
42 class AudioOutputDeviceCoreAudio : public AudioOutputDevice,
43 public CAAudioDeviceModelListener, protected Thread {
44
45 private:
46 struct AQPlayerState {
47 AudioStreamBasicDescription mDataFormat;
48 AudioQueueRef mQueue;
49 AudioQueueBufferRef* mBuffers;
50 UInt32 bufferByteSize;
51 UInt32 mNumPacketsToRead;
52 atomic_t mIsRunning;
53 AudioOutputDeviceCoreAudio* pDevice; // needed for the callback
54 };
55
56 public:
57 AudioOutputDeviceCoreAudio(std::map<String,DeviceCreationParameter*> Parameters);
58 virtual ~AudioOutputDeviceCoreAudio();
59
60 virtual void DeviceChanged(); // from CAAudioDeviceModelListener
61
62 // derived abstract methods from class 'AudioOutputDevice'
63 virtual void Play();
64 virtual bool IsPlaying();
65 virtual void Stop();
66 virtual uint MaxSamplesPerCycle();
67 virtual uint SampleRate();
68 virtual String Driver();
69 virtual AudioChannel* CreateChannel(uint ChannelNr);
70
71 static String Name();
72 static String Description();
73 static String Version();
74
75
76 // *************** PARAMETERS ***************
77
78 /** Device Parameter 'DEVICE'
79 *
80 * Used to select the desired output device.
81 */
82 class ParameterDevice : public DeviceCreationParameterString {
83 public:
84 ParameterDevice();
85 ParameterDevice(String s) throw (Exception);
86 virtual String Description();
87 virtual bool Fix();
88 virtual bool Mandatory();
89 virtual std::map<String,DeviceCreationParameter*> DependsAsParameters();
90 virtual optional<String> DefaultAsString(std::map<String,String> Parameters);
91 virtual std::vector<String> PossibilitiesAsString(std::map<String,String> Parameters);
92 virtual void OnSetValue(String s) throw (Exception);
93 int GetDeviceIndex();
94 static String Name();
95
96 private:
97 String CreateDeviceName(int devIndex);
98 };
99
100 /** Device Parameter 'SAMPLERATE'
101 *
102 * Used to set the sample rate of the audio output device.
103 */
104 class ParameterSampleRate : public AudioOutputDevice::ParameterSampleRate {
105 public:
106 ParameterSampleRate();
107 ParameterSampleRate(String s);
108 virtual std::map<String,DeviceCreationParameter*> DependsAsParameters();
109 virtual optional<int> DefaultAsInt(std::map<String,String> Parameters);
110 virtual std::vector<int> PossibilitiesAsInt(std::map<String,String> Parameters);
111 };
112
113 /** Device Parameters 'CHANNELS'
114 *
115 * Used to increase / decrease the number of audio channels of
116 * audio output device.
117 */
118 class ParameterChannels : public AudioOutputDevice::ParameterChannels {
119 public:
120 ParameterChannels();
121 ParameterChannels(String s);
122 virtual optional<int> DefaultAsInt(std::map<String,String> Parameters);
123 virtual std::vector<int> PossibilitiesAsInt(std::map<String,String> Parameters);
124 };
125
126 /** Device Parameter 'BUFFERS'
127 *
128 * Used to select the number of audio buffers.
129 */
130 class ParameterBuffers : public DeviceCreationParameterInt {
131 public:
132 ParameterBuffers();
133 ParameterBuffers(String s) throw (Exception);
134 virtual String Description();
135 virtual bool Fix();
136 virtual bool Mandatory();
137 virtual std::map<String,DeviceCreationParameter*> DependsAsParameters();
138 virtual optional<int> DefaultAsInt(std::map<String,String> Parameters);
139 virtual optional<int> RangeMinAsInt(std::map<String,String> Parameters);
140 virtual optional<int> RangeMaxAsInt(std::map<String,String> Parameters);
141 virtual std::vector<int> PossibilitiesAsInt(std::map<String,String> Parameters);
142 virtual void OnSetValue(int i) throw (Exception);
143 static String Name();
144 };
145
146 /** Device Parameter 'BUFFERSIZE'
147 *
148 * Used to set the audio buffer size in sample frames.
149 */
150 class ParameterBufferSize : public DeviceCreationParameterInt {
151 public:
152 ParameterBufferSize();
153 ParameterBufferSize(String s) throw (Exception);
154 virtual String Description();
155 virtual bool Fix();
156 virtual bool Mandatory();
157 virtual std::map<String,DeviceCreationParameter*> DependsAsParameters();
158 virtual optional<int> DefaultAsInt(std::map<String,String> Parameters);
159 virtual optional<int> RangeMinAsInt(std::map<String,String> Parameters);
160 virtual optional<int> RangeMaxAsInt(std::map<String,String> Parameters);
161 virtual std::vector<int> PossibilitiesAsInt(std::map<String,String> Parameters);
162 virtual void OnSetValue(int i) throw (Exception);
163 static String Name();
164 };
165
166 protected:
167 int Main(); ///< Implementation of virtual method from class Thread
168
169 private:
170 CAAudioDeviceModel CurrentDevice;
171 uint uiCoreAudioChannels;
172 uint uiBufferNumber; // once initialized this value shouldn't be changed
173 uint uiBufferSize; // once initialized this value shouldn't be changed
174 AQPlayerState aqPlayerState;
175 atomic_t pausedNew;
176 uint pausedOld;
177 atomic_t restartQueue;
178 Mutex destroyMutex;
179
180 void CreateAndStartAudioQueue() throw(Exception);
181 void DestroyAudioQueue();
182 void FillBuffers();
183 void PrimeAudioQueue();
184
185 static void AudioQueueListener(void *inUserData, AudioQueueRef inAQ, AudioQueuePropertyID inID);
186 static void HandleOutputBuffer(void *aqData, AudioQueueRef inAQ, AudioQueueBufferRef inBuffer);
187 static void SetAudioDataFormat(AudioStreamBasicDescription* pDataFormat);
188 };
189 } // namespace LinuxSampler
190
191 #endif /* _AUDIOOUTPUTDEVICECOREAUDIO_H */

  ViewVC Help
Powered by ViewVC