/usr/include/svxlink/AsyncAudioDevice.h is in libasyncaudio-dev 14.08.1-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 | /**
@file AsyncAudioDevice.h
@brief Base class for handling audio devices
@author Tobias Blomberg / SM0SVX
@date 2009-07-18
\verbatim
Async - A library for programming event driven applications
Copyright (C) 2004-2009 Tobias Blomberg / SM0SVX
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
\endverbatim
*/
#ifndef ASYNC_AUDIO_DEVICE_INCLUDED
#define ASYNC_AUDIO_DEVICE_INCLUDED
/****************************************************************************
*
* System Includes
*
****************************************************************************/
#include <sigc++/sigc++.h>
#include <stdint.h>
#include <string>
#include <map>
#include <list>
/****************************************************************************
*
* Project Includes
*
****************************************************************************/
/****************************************************************************
*
* Local Includes
*
****************************************************************************/
/****************************************************************************
*
* Forward declarations
*
****************************************************************************/
/****************************************************************************
*
* Namespace
*
****************************************************************************/
namespace Async
{
/****************************************************************************
*
* Forward declarations of classes inside of the declared namespace
*
****************************************************************************/
class AudioIO;
class FdWatch;
/****************************************************************************
*
* Defines & typedefs
*
****************************************************************************/
/****************************************************************************
*
* Exported Global Variables
*
****************************************************************************/
/****************************************************************************
*
* Class definitions
*
****************************************************************************/
/**
@brief Base class for handling audio devices
@author Tobias Blomberg / SM0SVX
@date 2004-03-20
This class implements a base class for supporting different audio devices. This
class is not intended to be used by the end user of the Async library. It is
used by the Async::AudioIO class, which is the Async API frontend for using
audio in an application.
*/
class AudioDevice : public sigc::trackable
{
public:
/**
* @brief The different modes to open a device in
*/
typedef enum
{
MODE_NONE, ///< No mode. The same as close
MODE_RD, ///< Read
MODE_WR, ///< Write
MODE_RDWR ///< Both read and write
} Mode;
/**
* @brief Register an AudioIO object with the given device name
* @param dev_designator The name of the audio device
* @param audio_io A previously created AudioIO object
* @return Returns an AudioDevice object associated with the given device
*
* This function is used to register an AudioIO object with the given
* audio device. If an AudioDevice object already exist for the given
* device, it is returned. If there is no AudioDevice object for the
* given device, a new one is created.
*/
static AudioDevice *registerAudioIO(const std::string& dev_designator,
AudioIO *audio_io);
/**
* @brief Unregister a previously registered AudioIO object
* @param audio_io A previously registered AudioIO object
*/
static void unregisterAudioIO(AudioIO *audio_io);
/**
* @brief Set the sample rate used when doing future opens
* @param rate The sampling rate to use
*
* Use this function to set the sample rate used when opening audio
* devices.
* This is a global setting so all sound cards will be affected. Already
* opened sound cards will not be affected.
*/
static void setSampleRate(int rate) { sample_rate = rate; }
/**
* @brief Set the blocksize used when opening audio devices
* @param size The blocksize, in samples per channel, to use
* @return Returns the blocksize actually set
*
* Use this function to set the block size used when opening audio
* devices. The block size is the size of the blocks used when reading
* and writing audio to/from the sound card. Smaller blocks give less
* delay but could cause choppy audio if the computer is too slow.
* The blocksize is set as samples per channel. For example, a blocksize
* of 256 samples at 8kHz sample rate will give a delay of 256/8000 = 32ms.
* This is a global setting so all sound cards will be affected. Already
* opened sound cards will not be affected.
*/
static void setBlocksize(int size)
{
block_size_hint = size;
}
/**
* @brief Find out what the blocksize is set to
* @return Returns the currently set blocksize in samples per channel
*/
virtual int blocksize(void) = 0;
/**
* @brief Set the buffer count used when opening audio devices
* @param count The buffer count to use
* @return Returns the buffer count actually set
*
* Use this function to set the buffer count used when opening audio
* devices. The buffer count is the maximum number of blocks the driver
* will buffer when reading and writing audio to/from the sound card.
* Lower numbers give less delay but could cause choppy audio if the
* computer is too slow.
* This is a global setting so all sound cards will be affected. Already
* opened sound cards will not be affected.
*/
static void setBlockCount(int count)
{
block_count_hint = (count <= 0) ? 0 : count;
}
/**
* @brief Set the number of channels used when doing future opens
* @param channels The number of channels to use
*
* Use this function to set the number of channels used when opening audio
* devices.
* This is a global setting so all sound cards will be affected. Already
* opened sound cards will not be affected.
*/
static void setChannels(int channels)
{
AudioDevice::channels = channels;
}
/**
* @brief Check if the audio device has full duplex capability
* @return Returns \em true if the device has full duplex capability
* or else \em false
*/
virtual bool isFullDuplexCapable(void) = 0;
/**
* @brief Open the audio device
* @param mode The mode to open the audio device in (See AudioIO::Mode)
* @return Returns \em true on success or else \em false
*/
bool open(Mode mode);
/**
* @brief Close the audio device
*/
void close(void);
/**
* @brief Get the current operating mode of this audio device
* @return Returns the current mode (See AudioIO::Mode)
*/
Mode mode(void) const { return current_mode; }
/**
* @brief Tell the audio device handler that there are audio to be
* written in the buffer
*/
virtual void audioToWriteAvailable(void) = 0;
/*
* @brief Tell the audio device to flush its buffers
*/
virtual void flushSamples(void) = 0;
/**
* @brief Find out how many samples there are in the output buffer
* @return Returns the number of samples in the output buffer on
* success or -1 on failure.
*
* This function can be used to find out how many samples there are
* in the output buffer at the moment. This can for example be used
* to find out how long it will take before the output buffer has
* been flushed.
*/
virtual int samplesToWrite(void) const = 0;
/**
* @brief Return the sample rate
* @return Returns the sample rate
*/
int sampleRate(void) const { return sample_rate; }
/**
* @brief Return the device name
* @return Returns the device name
*/
const std::string& devName(void) const { return dev_name; }
protected:
static int sample_rate;
static int block_size_hint;
static int block_count_hint;
static int channels;
std::string dev_name;
/**
* @brief Constuctor
* @param dev_name The name of the device to associate this object with
*/
explicit AudioDevice(const std::string& dev_name);
/**
* @brief Destructor
*/
virtual ~AudioDevice(void);
/**
* @brief Open the audio device
* @param mode The mode to open the audio device in (See AudioIO::Mode)
* @return Returns \em true on success or else \em false
*/
virtual bool openDevice(Mode mode) = 0;
/**
* @brief Close the audio device
*/
virtual void closeDevice(void) = 0;
void putBlocks(int16_t *buf, int frame_cnt);
int getBlocks(int16_t *buf, int block_cnt);
private:
static const int DEFAULT_SAMPLE_RATE = INTERNAL_SAMPLE_RATE;
static const int DEFAULT_CHANNELS = 2;
static const int DEFAULT_BLOCK_COUNT_HINT = 4;
static const int DEFAULT_BLOCK_SIZE_HINT = 256; // Samples/channel/block
static std::map<std::string, AudioDevice*> devices;
Mode current_mode;
int use_count;
std::list<AudioIO*> aios;
}; /* class AudioDevice */
} /* namespace */
#endif /* ASYNC_AUDIO_DEVICE_INCLUDED */
/*
* This file has not been truncated
*/
|