clean up indentation and spacing
[supercollider.git] / server / supernova / audio_backend / audio_backend.hpp
blob655e0abfcb9e68a3da9d5ee7a706402c98b2f076
1 // audio interface
2 // Copyright (C) 2005, 2006, 2007, 2008 Tim Blechmann
3 //
4 // This program is free software; you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation; either version 2 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with this program; see the file COPYING. If not, write to
16 // the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 // Boston, MA 02111-1307, USA.
19 #ifndef _AUDIO_BACKEND_HPP
20 #define _AUDIO_BACKEND_HPP
22 #include <string>
23 #include <vector>
25 #include "utilities/utils.hpp"
26 #include "server/sample_types.hpp"
27 #include "simd_memory.hpp"
29 namespace nova
31 /** \brief the Device struct represents information of an audio device
33 * \ingroup kernel
35 struct Device
37 Device(uint apiIndex, std::string const & name, uint inchannels, uint outchannels, uint defaultSampleRate,
38 float LowInputLatency, float HighInputLatency, float LowOutputLatency, float HighOutputLatency):
39 apiIndex(apiIndex), name(name), inchannels(inchannels), outchannels(outchannels),
40 defaultSampleRate(defaultSampleRate), LowInputLatency(LowInputLatency), HighInputLatency(HighInputLatency),
41 LowOutputLatency(LowOutputLatency), HighOutputLatency(HighOutputLatency)
44 Device(Device const & rhs):
45 apiIndex(rhs.apiIndex), name(rhs.name), inchannels(rhs.inchannels), outchannels(rhs.outchannels),
46 defaultSampleRate(rhs.defaultSampleRate), LowInputLatency(rhs.LowInputLatency),
47 HighInputLatency(rhs.HighInputLatency), LowOutputLatency(rhs.LowOutputLatency),
48 HighOutputLatency(rhs.HighOutputLatency)
51 void operator=(Device const & rhs)
53 apiIndex = rhs.apiIndex, name = rhs.name, inchannels = rhs.inchannels, outchannels = rhs.outchannels,
54 defaultSampleRate = rhs.defaultSampleRate, LowOutputLatency = rhs.LowOutputLatency,
55 LowInputLatency = rhs.LowInputLatency, HighOutputLatency = rhs.HighOutputLatency,
56 HighInputLatency = rhs.HighInputLatency;
59 bool operator==(Device const & rhs)
61 return (apiIndex == rhs.apiIndex) and
62 (name == rhs.name);
65 uint apiIndex;
66 std::string name;
67 unsigned short inchannels, outchannels;
68 uint defaultSampleRate;
69 float LowInputLatency, HighInputLatency;
70 float LowOutputLatency, HighOutputLatency;
73 typedef std::vector<Device> device_list;
75 template <void(*dsp_cb)(void)>
76 class audio_frontend;
78 /** \brief abstract base class for audio backends
80 * \ingroup kernel
82 template <void(*dsp_cb)(void)>
83 class audio_backend:
84 public noncopyable
86 protected:
87 audio_backend(void):
88 active(false)
91 virtual ~audio_backend(void)
94 public:
95 /** \brief deliver data to dac */
96 /* { */
97 virtual void deliver_dac_output(const_restricted_sample_ptr source, uint channel, uint frames) = 0;
99 virtual void deliver_dac_output_64(const_restricted_sample_ptr source, uint channel)
101 this->deliver_dac_output(source, channel, 64);
103 /* } */
105 virtual void zero_dac_output(uint channel, uint frames) = 0;
107 /** \brief fetch data from adc */
108 /* { */
109 virtual void fetch_adc_input(restricted_sample_ptr destination, uint channel, uint frames) = 0;
111 virtual void fetch_adc_input_64(restricted_sample_ptr destination, uint channel)
113 this->fetch_adc_input(destination, channel, 64);
115 /* } */
117 /** \brief activate audio_backend */
118 virtual void activate(void)
120 active = true;
123 /** \brief deactivate audio_backend */
124 virtual void deactivate(void)
126 active = false;
129 /** \brief query activation state */
130 bool is_active(void)
132 return active;
135 /** \brief get dac blocksize */
136 uint get_blocksize(void)
138 return dacblocksize;
141 /** \brief list devices */
142 virtual device_list list_devices(void) = 0;
144 /** \brief open audio stream */
145 virtual void open_audio_stream(Device const & indevice, uint inchannels, Device const & outdevice, uint outchannels,
146 uint samplerate) = 0;
148 /** \brief close the active audio stream */
149 virtual void close_audio_stream(void) = 0;
151 virtual bool audiostream_ready(void) = 0;
153 /** \brief wrapper for Scheduler::Tick() */
154 void tick(void)
156 (*dsp_cb)();
159 protected:
160 friend class audio_frontend<dsp_cb>;
162 bool active; /**< \brief is this interface active? */
163 unsigned short dacblocksize;
167 template <void(*dsp_cb)(void)>
168 class dummy_backend:
169 public audio_backend<dsp_cb>
171 public:
172 dummy_backend(void):
173 ready(false)
176 void open_audio_stream(Device const & indevice, uint inchannels, Device const & outdevice, uint outchannels,
177 uint samplerate)
179 assert(not ready);
180 ready = true;
183 void close_audio_stream(void)
185 assert(ready);
186 ready = false;
189 bool audiostream_ready(void)
191 return ready;
194 device_list list_devices(void)
196 Device dummydevice(0, "Dummy", 256, 256, 44100, 0, 0, 0, 0);
198 device_list ret;
199 ret.push_back(dummydevice);
200 return ret;
203 /** \brief noop */
204 virtual void deliver_dac_output(const_restricted_sample_ptr source, uint channel, uint frames)
207 virtual void zero_dac_output(uint channel, uint frames)
210 /** \brief wipe buffer */
211 virtual void fetch_adc_input(restricted_sample_ptr destination, uint channel, uint frames)
213 zerovec_simd(destination, audio_backend<dsp_cb>::dacblocksize);
216 private:
217 bool ready;
221 } /* namespace nova */
225 #endif /* _AUDIO_BACKEND_HPP */