/[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 1829 - (show annotations) (download) (as text)
Fri Jan 30 19:22:36 2009 UTC (15 years, 2 months ago) by iliev
File MIME type: text/x-c++hdr
File size: 7488 byte(s)
* added (experimental) CoreAudio driver

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
32 #include <AudioToolbox/AudioToolbox.h>
33 #include <CoreAudio/CoreAudio.h>
34
35 namespace LinuxSampler {
36
37 /** Core Audio audio output driver
38 *
39 * Implements audio output to the Core Audio architecture.
40 */
41 class AudioOutputDeviceCoreAudio : public AudioOutputDevice, protected Thread {
42 private:
43 struct AQPlayerState {
44 AudioStreamBasicDescription mDataFormat;
45 AudioQueueRef mQueue;
46 AudioQueueBufferRef* mBuffers;
47 UInt32 bufferByteSize;
48 UInt32 mNumPacketsToRead;
49 atomic_t mIsRunning;
50 AudioOutputDeviceCoreAudio* pDevice; // needed for the callback
51 };
52
53 struct DeviceInfo {
54 uint uiSamplerate;
55 uint uiChannelNumber;
56 };
57
58 public:
59 AudioOutputDeviceCoreAudio(std::map<String,DeviceCreationParameter*> Parameters);
60 virtual ~AudioOutputDeviceCoreAudio();
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 'SAMPLERATE'
79 *
80 * Used to set the sample rate of the audio output device.
81 */
82 class ParameterSampleRate : public AudioOutputDevice::ParameterSampleRate {
83 public:
84 ParameterSampleRate();
85 ParameterSampleRate(String s);
86 virtual optional<int> DefaultAsInt(std::map<String,String> Parameters);
87 };
88
89 /** Device Parameters 'CHANNELS'
90 *
91 * Used to increase / decrease the number of audio channels of
92 * audio output device.
93 */
94 class ParameterChannels : public AudioOutputDevice::ParameterChannels {
95 public:
96 ParameterChannels();
97 ParameterChannels(String s);
98 virtual optional<int> DefaultAsInt(std::map<String,String> Parameters);
99 };
100
101 /** Device Parameter 'BUFFERS'
102 *
103 * Used to select the number of audio buffers.
104 */
105 class ParameterBuffers : public DeviceCreationParameterInt {
106 public:
107 ParameterBuffers();
108 ParameterBuffers(String s) throw (Exception);
109 virtual String Description();
110 virtual bool Fix();
111 virtual bool Mandatory();
112 virtual std::map<String,DeviceCreationParameter*> DependsAsParameters();
113 virtual optional<int> DefaultAsInt(std::map<String,String> Parameters);
114 virtual optional<int> RangeMinAsInt(std::map<String,String> Parameters);
115 virtual optional<int> RangeMaxAsInt(std::map<String,String> Parameters);
116 virtual std::vector<int> PossibilitiesAsInt(std::map<String,String> Parameters);
117 virtual void OnSetValue(int i) throw (Exception);
118 static String Name();
119 };
120
121 /** Device Parameter 'BUFFERSIZE'
122 *
123 * Used to set the audio buffer size in sample frames.
124 */
125 class ParameterBufferSize : public DeviceCreationParameterInt {
126 public:
127 ParameterBufferSize();
128 ParameterBufferSize(String s) throw (Exception);
129 virtual String Description();
130 virtual bool Fix();
131 virtual bool Mandatory();
132 virtual std::map<String,DeviceCreationParameter*> DependsAsParameters();
133 virtual optional<int> DefaultAsInt(std::map<String,String> Parameters);
134 virtual optional<int> RangeMinAsInt(std::map<String,String> Parameters);
135 virtual optional<int> RangeMaxAsInt(std::map<String,String> Parameters);
136 virtual std::vector<int> PossibilitiesAsInt(std::map<String,String> Parameters);
137 virtual void OnSetValue(int i) throw (Exception);
138 static String Name();
139 };
140
141 protected:
142 int Main(); ///< Implementation of virtual method from class Thread
143
144 private:
145 uint uiCoreAudioChannels;
146 uint uiBufferNumber; // once initialized this value shouldn't be changed
147 uint uiBufferSize; // once initialized this value shouldn't be changed
148 AQPlayerState aqPlayerState;
149 atomic_t pausedNew;
150 uint pausedOld;
151 Mutex destroyMutex;
152
153 static DeviceInfo* pDeviceInfo;
154
155 static void HandleOutputBuffer(void *aqData, AudioQueueRef inAQ, AudioQueueBufferRef inBuffer);
156 static void SetAudioDataFormat(AudioStreamBasicDescription* pDataFormat);
157 static DeviceInfo* GetDeviceInfo();
158 };
159 } // namespace LinuxSampler
160
161 #endif /* _AUDIOOUTPUTDEVICECOREAUDIO_H */

  ViewVC Help
Powered by ViewVC