2 // Copyright (C) 2005, 2006, 2007, 2008 Tim Blechmann
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.
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
25 #include "utilities/utils.hpp"
26 #include "server/sample_types.hpp"
27 #include "simd_memory.hpp"
31 /** \brief the Device struct represents information of an audio 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
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)>
78 /** \brief abstract base class for audio backends
82 template <void(*dsp_cb
)(void)>
91 virtual ~audio_backend(void)
95 /** \brief deliver data to dac */
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);
105 virtual void zero_dac_output(uint channel
, uint frames
) = 0;
107 /** \brief fetch data from adc */
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);
117 /** \brief activate audio_backend */
118 virtual void activate(void)
123 /** \brief deactivate audio_backend */
124 virtual void deactivate(void)
129 /** \brief query activation state */
135 /** \brief get dac blocksize */
136 uint
get_blocksize(void)
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() */
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)>
169 public audio_backend
<dsp_cb
>
176 void open_audio_stream(Device
const & indevice
, uint inchannels
, Device
const & outdevice
, uint outchannels
,
183 void close_audio_stream(void)
189 bool audiostream_ready(void)
194 device_list
list_devices(void)
196 Device
dummydevice(0, "Dummy", 256, 256, 44100, 0, 0, 0, 0);
199 ret
.push_back(dummydevice
);
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
);
221 } /* namespace nova */
225 #endif /* _AUDIO_BACKEND_HPP */