/[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 56 - (hide annotations) (download) (as text)
Tue Apr 27 09:21:58 2004 UTC (19 years, 11 months ago) by schoenebeck
File MIME type: text/x-c++hdr
File size: 8830 byte(s)
updated copyright header for 2004

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     // abstract methods
51     // (these have to be implemented by the descendant)
52    
53     /**
54     * Start playback of audio signal on the audio device. It's the
55     * responsibility of the implementing audio device to call the
56     * RenderAudio(uint Samples) method of all connected engines.
57     * This will cause the engines to continue to render 'Samples'
58     * number of audio sample points and the engines will
59     * automatically add their audio signals to the audio buffers of
60     * the audio channels of this audio device. So the implementing
61     * audio device just has to access the buffers of it's audio
62     * channels.
63     *
64     * @throws AudioOutputException if playback can not be started
65     * @see AudioChannel
66     */
67     virtual void Play() = 0;
68    
69     /**
70     * Returns true if the audio device is currently playing back.
71     */
72     virtual bool IsPlaying() = 0;
73    
74     /**
75     * Stop playback of audio signal on the audio device. The
76     * implementing audio device will stop calling the RenderAudio()
77     * method of all connected engines and close it's connection to
78     * audio output system.
79     */
80     virtual void Stop() = 0;
81    
82     /**
83     * This method will usually be called by the sampler engines that
84     * are connected to this audio device to inform the audio device
85     * how much audio channels the engine(s) need. It's the
86     * responsibility of the audio device to offer that amount of
87     * audio channels - again: this is not an option this is a must!
88     * The engines will assume to be able to access those audio
89     * channels right after. If the audio driver is not able to offer
90     * that much channels, it can simply create mix channels which
91     * are then just mixed to the 'real' audio channels. See
92     * AudioChannel.h for details about channels and mix channels.
93     *
94     * @param Channels - amount of output channels required by
95     * a sampler engine
96     * @throws AudioOutputException if desired amount of channels
97     * cannot be offered
98     * @see AudioChannel
99     */
100     virtual void AcquireChannels(uint Channels) = 0;
101    
102     /**
103     * Maximum amount of sample points the implementing audio
104     * device will ever demand the sampler engines to write in one
105     * fragment cycle / period. Simple audio device drivers usually
106     * have a fixed fragment size, so those devices just would return
107     * the fragment size in this method.
108     *
109     * @returns max. amount of sample points ever
110     */
111     virtual uint MaxSamplesPerCycle() = 0;
112    
113     /**
114     * Playback samplerate the audio device uses. The sampler engines
115     * currently assume this to be a constant value for the whole
116     * life time of an instance of the implementing audio device.
117     *
118     * @returns sample rate in Hz
119     */
120     virtual uint SampleRate() = 0;
121    
122    
123    
124     /////////////////////////////////////////////////////////////////
125     // normal methods
126     // (usually not to be overriden by descendant)
127    
128     /**
129     * Connect given sampler engine to this audio output device. The
130     * engine will be added to the Engines container of this audio
131     * device and the engine will also automatically be informed
132     * about the connection.
133     *
134     * @param pEngine - sampler engine
135     */
136     void Connect(Engine* pEngine);
137    
138     /**
139     * Disconnect given sampler engine from this audio output device.
140     * Removes given sampler engine reference from the Engines
141     * container of this audio device.
142     *
143     * @param pEngine - sampler engine
144     */
145     void Disconnect(Engine* pEngine);
146    
147     /**
148     * Returns audio channel with index \a ChannelIndex or NULL if
149     * index out of bounds.
150     */
151     AudioChannel* Channel(uint ChannelIndex);
152    
153     protected:
154     std::set<Engine*> Engines; ///< All sampler engines that are connected to the audio output device.
155     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.
156    
157     /**
158     * This method should be called by the AudioOutputDevice
159     * descendant to let all connected engines proceed to render the
160     * given amount of sample points. The engines will place their
161     * calculated audio data by themselfes into the buffers of the
162     * respective AudioChannel objects, so the implementing audio
163     * output device just has to copy the AudioChannel buffers to
164     * the output buffer(s) of its audio system.
165     *
166     * @returns 0 on success or the last error return code of one
167     * engine
168     */
169     int RenderAudio(uint Samples);
170    
171     /**
172     * This can be called as an alternative to RenderAudio() for
173     * just writing silence to the audio output buffers and not
174     * calling the connected sampler engines for rendering audio, so
175     * to provide a method to stop playback if the used audio output
176     * system doesn't provide a better way.
177     *
178     * @returns 0 on success
179     */
180     int RenderSilence(uint Samples);
181     };
182    
183     /**
184     * Audio output exception that should be thrown by the AudioOutputDevice
185     * descendants in case initialization of the audio output system failed
186     * (which should be done in the constructor of the AudioOutputDevice
187     * descendant).
188     */
189     class AudioOutputException : public LinuxSamplerException {
190     public:
191     AudioOutputException(const std::string& msg) : LinuxSamplerException(msg) {}
192     };
193     }
194    
195     #endif // __LS_AUDIOOUTPUTDEVICE_H__

  ViewVC Help
Powered by ViewVC