/[svn]/linuxsampler/trunk/src/audiodriver/AudioOutputDevice.h
ViewVC logotype

Annotation of /linuxsampler/trunk/src/audiodriver/AudioOutputDevice.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 64 - (hide annotations) (download) (as text)
Thu May 6 20:06:20 2004 UTC (19 years, 11 months ago) by schoenebeck
File MIME type: text/x-c++hdr
File size: 9765 byte(s)
* src/Sampler.cpp: fixed 3 stupid but fatal bugs that left in the rush (in
  method SamplerChannels(), CreateAudioOutputDevice() and
  CreateMidiInputDevice())
* src/network/lscpserver.cpp: implemented LSCP command
  'SET CHANNEL MIDI_INPUT_CHANNEL'
* src/Sampler.h: moved enums 'audio_output_type_t', 'midi_input_type_t'
  and 'engine_type_t' into the respective base classes
  ('AudioOutputDevice', 'MidiInputDevice', 'Engine')

1 schoenebeck 53 /***************************************************************************
2     * *
3     * LinuxSampler - modular, streaming capable sampler *
4     * *
5 schoenebeck 56 * Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck *
6 schoenebeck 53 * *
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 __LS_AUDIOOUTPUTDEVICE_H__
24     #define __LS_AUDIOOUTPUTDEVICE_H__
25    
26     #include <set>
27     #include <vector>
28     #include <stdexcept>
29    
30     #include "../common/global.h"
31     #include "../common/LinuxSamplerException.h"
32     #include "../engines/common/Engine.h"
33     #include "AudioChannel.h"
34    
35     namespace LinuxSampler {
36    
37     // just symbol prototyping
38     class Engine;
39    
40     /** Abstract base class for audio output drivers in LinuxSampler
41     *
42     * This class will be derived by specialized classes which implement the
43     * connection to a specific audio output system (e.g. Alsa, Jack,
44     * CoreAudio).
45     */
46     class AudioOutputDevice {
47     public:
48    
49     /////////////////////////////////////////////////////////////////
50 schoenebeck 64 // type definitions
51    
52     /**
53     * List of all currently implemented audio output drivers.
54     */
55     enum type_t {
56     type_alsa,
57     type_jack
58     };
59    
60    
61    
62     /////////////////////////////////////////////////////////////////
63 schoenebeck 53 // abstract methods
64     // (these have to be implemented by the descendant)
65    
66     /**
67     * Start playback of audio signal on the audio device. It's the
68     * responsibility of the implementing audio device to call the
69     * RenderAudio(uint Samples) method of all connected engines.
70     * This will cause the engines to continue to render 'Samples'
71     * number of audio sample points and the engines will
72     * automatically add their audio signals to the audio buffers of
73     * the audio channels of this audio device. So the implementing
74     * audio device just has to access the buffers of it's audio
75     * channels.
76     *
77     * @throws AudioOutputException if playback can not be started
78     * @see AudioChannel
79     */
80     virtual void Play() = 0;
81    
82     /**
83     * Returns true if the audio device is currently playing back.
84     */
85     virtual bool IsPlaying() = 0;
86    
87     /**
88     * Stop playback of audio signal on the audio device. The
89     * implementing audio device will stop calling the RenderAudio()
90     * method of all connected engines and close it's connection to
91     * audio output system.
92     */
93     virtual void Stop() = 0;
94    
95     /**
96     * This method will usually be called by the sampler engines that
97     * are connected to this audio device to inform the audio device
98     * how much audio channels the engine(s) need. It's the
99     * responsibility of the audio device to offer that amount of
100     * audio channels - again: this is not an option this is a must!
101     * The engines will assume to be able to access those audio
102     * channels right after. If the audio driver is not able to offer
103     * that much channels, it can simply create mix channels which
104     * are then just mixed to the 'real' audio channels. See
105     * AudioChannel.h for details about channels and mix channels.
106     *
107     * @param Channels - amount of output channels required by
108     * a sampler engine
109     * @throws AudioOutputException if desired amount of channels
110     * cannot be offered
111     * @see AudioChannel
112     */
113     virtual void AcquireChannels(uint Channels) = 0;
114    
115     /**
116     * Maximum amount of sample points the implementing audio
117     * device will ever demand the sampler engines to write in one
118     * fragment cycle / period. Simple audio device drivers usually
119     * have a fixed fragment size, so those devices just would return
120     * the fragment size in this method.
121     *
122     * @returns max. amount of sample points ever
123     */
124     virtual uint MaxSamplesPerCycle() = 0;
125    
126     /**
127     * Playback samplerate the audio device uses. The sampler engines
128     * currently assume this to be a constant value for the whole
129     * life time of an instance of the implementing audio device.
130     *
131     * @returns sample rate in Hz
132     */
133     virtual uint SampleRate() = 0;
134    
135    
136    
137     /////////////////////////////////////////////////////////////////
138     // normal methods
139     // (usually not to be overriden by descendant)
140    
141     /**
142     * Connect given sampler engine to this audio output device. The
143     * engine will be added to the Engines container of this audio
144     * device and the engine will also automatically be informed
145     * about the connection.
146     *
147     * @param pEngine - sampler engine
148     */
149     void Connect(Engine* pEngine);
150    
151     /**
152     * Disconnect given sampler engine from this audio output device.
153     * Removes given sampler engine reference from the Engines
154     * container of this audio device.
155     *
156     * @param pEngine - sampler engine
157     */
158     void Disconnect(Engine* pEngine);
159    
160     /**
161     * Returns audio channel with index \a ChannelIndex or NULL if
162     * index out of bounds.
163     */
164     AudioChannel* Channel(uint ChannelIndex);
165    
166 schoenebeck 64 /**
167     * Returns the ID that identifies the implementing audio output
168     * driver.
169     */
170     type_t Type();
171    
172 schoenebeck 53 protected:
173     std::set<Engine*> Engines; ///< All sampler engines that are connected to the audio output device.
174     std::vector<AudioChannel*> Channels; ///< All audio channels of the audio output device. This is just a container; the descendant has to create channels by himself.
175 schoenebeck 64 type_t AudioOutputType;
176 schoenebeck 53
177     /**
178 schoenebeck 64 * Constructor. Has to be called by the implementing audio
179     * output driver to define the ID of the driver. When a new
180     * audio output driver is implemented, the
181     * AudioOutputDevice::type_t enumeration has to be extended with
182     * a new ID for the new audio output driver.
183     */
184     AudioOutputDevice(type_t Type);
185    
186     /**
187 schoenebeck 53 * This method should be called by the AudioOutputDevice
188     * descendant to let all connected engines proceed to render the
189     * given amount of sample points. The engines will place their
190     * calculated audio data by themselfes into the buffers of the
191     * respective AudioChannel objects, so the implementing audio
192     * output device just has to copy the AudioChannel buffers to
193     * the output buffer(s) of its audio system.
194     *
195     * @returns 0 on success or the last error return code of one
196     * engine
197     */
198     int RenderAudio(uint Samples);
199    
200     /**
201     * This can be called as an alternative to RenderAudio() for
202     * just writing silence to the audio output buffers and not
203     * calling the connected sampler engines for rendering audio, so
204     * to provide a method to stop playback if the used audio output
205     * system doesn't provide a better way.
206     *
207     * @returns 0 on success
208     */
209     int RenderSilence(uint Samples);
210     };
211    
212     /**
213     * Audio output exception that should be thrown by the AudioOutputDevice
214     * descendants in case initialization of the audio output system failed
215     * (which should be done in the constructor of the AudioOutputDevice
216     * descendant).
217     */
218     class AudioOutputException : public LinuxSamplerException {
219     public:
220     AudioOutputException(const std::string& msg) : LinuxSamplerException(msg) {}
221     };
222     }
223    
224     #endif // __LS_AUDIOOUTPUTDEVICE_H__

  ViewVC Help
Powered by ViewVC