ccAudio
audio2.h
Go to the documentation of this file.
1// Copyright (C) 1999-2005 Open Source Telecom Corporation.
2// Copyright (C) 2006-2008 David Sugar, Tycho Softworks.
3//
4// This file is part of GNU ccAudio2.
5//
6// GNU ccAudio2 is free software: you can redistribute it and/or modify
7// it under the terms of the GNU Lesser General Public License as published
8// by the Free Software Foundation, either version 3 of the License, or
9// (at your option) any later version.
10//
11// GNU ccAudio2 is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14// GNU Lesser General Public License for more details.
15//
16// You should have received a copy of the GNU Lesser General Public License
17// along with GNU ccAudio2. If not, see <http://www.gnu.org/licenses/>.
18
23
24
25#ifndef CCXX_AUDIO_H_
26#define CCXX_AUDIO_H_
27
28#ifndef CCXX_PACKING
29#if defined(__GNUC__)
30#define CCXX_PACKED
31#elif !defined(__hpux) && !defined(_AIX)
32#define CCXX_PACKED
33#endif
34#endif
35
36#ifndef W32
37#if defined(_WIN32) && defined(_MSC_VER)
38#pragma warning(disable: 4996)
39#define W32
40#endif
41#if defined(__BORLANDC__) && defined(__Windows)
42#define W32
43#endif
44#endif
45
46#if !defined(__EXPORT) && defined(W32)
47#define __EXPORT __declspec(dllimport)
48#endif
49
50#ifndef __EXPORT
51#define __EXPORT
52#endif
53
54#ifdef W32
55#include <windows.h>
56#ifndef ssize_t
57#define ssize_t int
58#endif
59#else
60#include <cstddef>
61#include <cstdlib>
62#include <sys/types.h>
63#include <netinet/in.h>
64#endif
65
66#include <ctime>
67
68namespace ost {
69
70#define AUDIO_SIGNED_LINEAR_RAW 1
71#define AUDIO_LINEAR_CONVERSION 1
72#define AUDIO_CODEC_MODULES 1
73#define AUDIO_LINEAR_FRAMING 1
74#define AUDIO_NATIVE_METHODS 1
75#define AUDIO_RATE_RESAMPLER 1
76
77class __EXPORT AudioCodec;
78class __EXPORT AudioDevice;
79
89{
90public:
91#ifdef W32
92 typedef short Sample;
93 typedef short *Linear;
94 typedef short Level;
95 typedef DWORD timeout_t;
96 typedef WORD snd16_t;
97 typedef DWORD snd32_t;
98#else
99 typedef int16_t snd16_t;
100 typedef int32_t snd32_t;
101 typedef int16_t Level;
102 typedef int16_t Sample;
103 typedef int16_t *Linear;
104 typedef unsigned long timeout_t;
105#endif
106
107 static const unsigned ndata;
108
109 typedef struct {
110 float v2;
111 float v3;
112 float fac;
114
138
139 typedef struct {
140 float fac;
142
143 typedef unsigned char *Encoded;
144
148 enum Rate {
150 rate6khz = 6000,
151 rate8khz = 8000,
152 rate16khz = 16000,
153 rate32khz = 32000,
154 rate44khz = 44100
155 };
156
157 typedef enum Rate Rate;
158
174
175 typedef enum Mode Mode;
176
225 typedef enum Encoding Encoding;
226
237 typedef enum Format Format;
238
247 typedef enum DeviceMode DeviceMode;
248
274 typedef enum Error Error;
275
276
277#ifdef CCXX_PACKED
278#pragma pack(1)
279#endif
280
281 typedef struct {
282#if __BYTE_ORDER == __LITTLE_ENDIAN
283 unsigned char mp_sync1 : 8;
284 unsigned char mp_crc : 1;
285 unsigned char mp_layer : 2;
286 unsigned char mp_ver : 2;
287 unsigned char mp_sync2 : 3;
288
289 unsigned char mp_priv : 1;
290 unsigned char mp_pad : 1;
291 unsigned char mp_srate : 2;
292 unsigned char mp_brate : 4;
293
294 unsigned char mp_emp : 2;
295 unsigned char mp_original : 1;
296 unsigned char mp_copyright: 1;
297 unsigned char mp_extend : 2;
298 unsigned char mp_channels : 2;
299
300#else
301 unsigned char mp_sync1 : 8;
302
303 unsigned char mp_sync2 : 3;
304 unsigned char mp_ver : 2;
305 unsigned char mp_layer : 2;
306 unsigned char mp_crc : 1;
307
308 unsigned char mp_brate : 4;
309 unsigned char mp_srate : 2;
310 unsigned char mp_pad : 1;
311 unsigned char mp_priv : 1;
312
313 unsigned char mp_channels : 2;
314 unsigned char mp_extend : 2;
315 unsigned char mp_copyright : 1;
316 unsigned char mp_original : 1;
317 unsigned char mp_emp : 2;
318#endif
319 } mpeg_audio;
320
321 typedef struct {
322 char tag_id[3];
323 char tag_title[30];
324 char tag_artist[30];
325 char tag_album[30];
326 char tag_year[4];
327 char tag_note[30];
328 unsigned char genre;
329 } mpeg_tagv1;
330
331#ifdef CCXX_PACKED
332#pragma pack()
333#endif
334
339 {
340 public:
343 unsigned long rate;
344 unsigned long bitrate;
345 unsigned order;
349
351 void clear(void);
352 void set(void);
355 };
356
363 static Level tolevel(float dbm);
364
371 static float todbm(Level power);
372
380 static bool hasDevice(unsigned device = 0);
381
392 static AudioDevice *getDevice(unsigned device = 0, DeviceMode mode = PLAY);
393
399 static const char *getCodecPath(void);
400
408 static const char *getMIME(Info &info);
409
417 static const char *getName(Encoding encoding);
418
426 static const char *getExtension(Encoding encoding);
427
438 static Encoding getEncoding(const char *name);
439
446 static Encoding getStereo(Encoding encoding);
447
454 static Encoding getMono(Encoding encoding);
455
462 static bool isLinear(Encoding encoding);
463
472 static bool isBuffered(Encoding encoding);
473
480 static bool isMono(Encoding encoding);
481
488 static bool isStereo(Encoding encoding);
489
497 static Rate getRate(Encoding encoding);
498
507 static Rate getRate(Encoding e, Rate request);
508
516 static timeout_t getFraming(Encoding encoding, timeout_t timeout = 0);
517
525 static timeout_t getFraming(Info &info, timeout_t timeout = 0);
526
534 static bool isEndian(Encoding encoding);
535
543 static bool isEndian(Info &info);
544
554 static bool swapEndian(Encoding encoding, void *buffer, unsigned number);
555
564 static void swapEncoded(Info &info, Encoded data, size_t bytes);
565
576 static bool swapEndian(Info &info, void *buffer, unsigned number);
577
586 static Level getImpulse(Encoding encoding, void *buffer, unsigned number);
587
596 static Level getImpulse(Info &info, void *buffer, unsigned number = 0);
597
607 static Level getPeak(Encoding encoding, void *buffer, unsigned number);
608
618 static Level getPeak(Info &info, void *buffer, unsigned number = 0);
619
627 static void toTimestamp(timeout_t duration, char *address, size_t size);
628
635 static timeout_t toTimeout(const char *timestamp);
636
659 static int getFrame(Encoding encoding, int samples = 0);
660
673 static int getCount(Encoding encoding);
674
683 static unsigned long toSamples(Encoding encoding, size_t bytes);
684
693 static unsigned long toSamples(Info &info, size_t bytes);
694
703 static size_t toBytes(Info &info, unsigned long number);
704
713 static size_t toBytes(Encoding encoding, unsigned long number);
714
723 static void fill(unsigned char *address, int number, Encoding encoding);
724
731 static bool loadPlugin(const char *path);
732
740 static size_t maxFramesize(Info &info);
741};
742
751{
752protected:
753 unsigned mfact, dfact, max;
754 unsigned gpos, ppos;
757
758public:
761
762 size_t process(Linear from, Linear to, size_t count);
763 size_t estimate(size_t count);
764};
765
775{
776protected:
778 unsigned samples;
780 double df1, df2, p1, p2;
783
787 void silence(void);
788
792 void reset(void);
793
797 void cleanup(void);
798
805 void single(unsigned freq, Level level);
806
815 void dual(unsigned f1, unsigned f2, Level l1, Level l2);
816
817public:
823 inline Rate getRate(void)
824 {return rate;};
825
831 inline size_t getSamples(void)
832 {return samples;};
833
839 bool isSilent(void);
840
848 virtual Linear getFrame(void);
849
858 unsigned getFrames(Linear buffer, unsigned number);
859
866 virtual bool isComplete(void);
867
875
886 AudioTone(unsigned f1, unsigned f2, Level l1, Level l2,
887 timeout_t duration = 20, Rate sample = rate8khz);
888
897 AudioTone(unsigned freq, Level level, timeout_t duration = 20, Rate sample = rate8khz);
898
899 virtual ~AudioTone();
900};
901
909{
910protected:
912
913public:
918
925
929 virtual ~AudioBase();
930
937 {return info.encoding;};
938
944 inline unsigned getSampleRate(void)
945 {return info.rate;};
946
954 virtual ssize_t putBuffer(Encoded data, size_t size) = 0;
955
964 ssize_t putNative(Encoded data, size_t size);
965
973 virtual ssize_t getBuffer(Encoded data, size_t size) = 0;
974
981 inline ssize_t getPacket(Encoded data)
982 {return getBuffer(data, 0);};
983
991 ssize_t getNative(Encoded data, size_t size);
992};
993
1002{
1003public:
1004 AudioBuffer(Info *info, size_t size = 4096);
1005 virtual ~AudioBuffer();
1006
1014 ssize_t getBuffer(Encoded data, size_t number);
1015
1023 ssize_t putBuffer(Encoded data, size_t number);
1024
1025private:
1026 char *buf;
1027 size_t size, start, len;
1028 void *mutexObject;
1029
1030 void enter(void);
1031 void leave(void);
1032};
1033
1043{
1044protected:
1047 unsigned long header; // offset to start of audio
1048 unsigned long minimum; // minimum sample size required
1049 unsigned long length; // current size of file, including header
1050
1051 void initialize(void);
1052 void getWaveFormat(int size);
1054
1055 union {
1056 int fd;
1057 void *handle;
1058 } file;
1059
1061 unsigned long iolimit;
1062
1063 virtual bool afCreate(const char *path, bool exclusive = false);
1064 virtual bool afOpen(const char *path, Mode m = modeWrite);
1065 virtual bool afPeek(unsigned char *data, unsigned size);
1066
1068
1081 virtual int afRead(unsigned char *data, unsigned size);
1082
1094 virtual int afWrite(unsigned char *data, unsigned size);
1095
1105 virtual bool afSeek(unsigned long pos);
1106
1110 virtual void afClose(void);
1111
1119 virtual char *getContinuation(void)
1120 {return NULL;};
1121
1130 const char * getErrorStr(Error err);
1131
1133
1140 inline unsigned long getHeader(void)
1141 {return header;};
1142
1151 unsigned short getShort(unsigned char *data);
1152
1161 void setShort(unsigned char *data, unsigned short value);
1162
1171 unsigned long getLong(unsigned char *data);
1172
1181 void setLong(unsigned char *data, unsigned long value);
1182
1183public:
1190 AudioFile(const char *name, unsigned long offset = 0);
1191
1199 AudioFile(const char *name, Info *info, unsigned long minimum = 0);
1200
1204 inline AudioFile()
1205 {initialize();};
1206
1207 virtual ~AudioFile();
1208
1219 void open(const char *name, Mode mode = modeWrite, timeout_t framing = 0);
1220
1231 void create(const char *name, Info *info, bool exclusive = false, timeout_t framing = 0);
1232
1239 time_t getAge(void);
1240
1246 inline size_t getSize(void)
1247 {return maxFramesize(info);};
1248
1254 void close(void);
1255
1263 void clear(void);
1264
1276 ssize_t getBuffer(Encoded buffer, size_t len = 0);
1277
1286 unsigned getLinear(Linear buffer, unsigned request = 0);
1287
1299 ssize_t putBuffer(Encoded buffer, size_t len = 0);
1300
1309 unsigned putLinear(Linear buffer, unsigned request = 0);
1310
1325 Error getSamples(void *buffer, unsigned samples = 0);
1326
1340 Error putSamples(void *buffer, unsigned samples = 0);
1341
1349 Error skip(long number);
1350
1358 Error setPosition(unsigned long samples = ~0l);
1359
1367 Error position(const char *timestamp);
1368
1375 void getPosition(char *timestamp, size_t size);
1376
1384 Error setLimit(unsigned long maximum = 0l);
1385
1394
1403 Error setMinimum(unsigned long minimum);
1404
1414 unsigned long getAbsolutePosition(void);
1415
1427 unsigned long getPosition(void);
1428
1434 virtual bool isOpen(void);
1435
1443 virtual bool hasPositioning(void)
1444 {return true;};
1445
1452 {return info.encoding;};
1453
1459 inline Format getFormat(void)
1460 {return info.format;};
1461
1468 inline unsigned getSampleRate(void)
1469 {return info.rate;};
1470
1476 inline char *getAnnotation(void)
1477 {return info.annotation;};
1478
1484 inline Error getError(void)
1485 {return error;};
1486
1487 inline bool operator!(void)
1488 {return (bool)!isOpen();};
1489
1495 bool isSigned(void);
1496};
1497
1510{
1511protected:
1512 AudioCodec *codec; // if needed
1519 unsigned encSize, decSize;
1520
1521 unsigned bufAudio(Linear samples, unsigned count, unsigned size);
1522
1523public:
1528
1536 AudioStream(const char *name, Mode mode = modeRead, timeout_t framing = 0);
1537
1546 AudioStream(const char *name, Info *info, bool exclusive = false, timeout_t framing = 0);
1547
1548 virtual ~AudioStream();
1549
1557 ssize_t getBuffer(Encoded data, size_t count);
1558
1566 void open(const char *name, Mode mode = modeRead, timeout_t framing = 0);
1567
1576 void create(const char *name, Info *info, bool exclusive = false, timeout_t framing = 0);
1577
1581 void close(void);
1582
1586 void flush(void);
1587
1594 bool isStreamable(void);
1595
1599 unsigned getCount(void); // frame count
1600
1610 unsigned getEncoded(AudioCodec *codec, Encoded address, unsigned frames = 1);
1611
1621 unsigned putEncoded(AudioCodec *codec, Encoded address, unsigned frames = 1);
1622
1630 unsigned getEncoded(Encoded address, unsigned frames = 1);
1631
1639 unsigned putEncoded(Encoded address, unsigned frames = 1);
1640
1648 ssize_t getPacket(Encoded data);
1649
1658 unsigned getMono(Linear buffer, unsigned frames = 1);
1659
1668 unsigned getStereo(Linear buffer, unsigned frames = 1);
1669
1678 unsigned putMono(Linear buffer, unsigned frames = 1);
1679
1688 unsigned putStereo(Linear buffer, unsigned frames = 1);
1689
1699 unsigned bufMono(Linear buffer, unsigned count);
1700
1710 unsigned bufStereo(Linear buffer, unsigned count);
1711
1717 inline AudioCodec *getCodec(void)
1718 {return codec;};
1719};
1720
1734{
1735protected:
1739 const char *name;
1741
1743
1751 virtual AudioCodec *getByFormat(const char *format)
1752 {return this;};
1753
1761 {return this;};
1762
1763public:
1771
1772 virtual ~AudioCodec() {};
1773
1780 static void endCodec(AudioCodec *codec);
1781
1791 static AudioCodec *getCodec(Encoding encoding, const char *format = NULL, bool loaded = false);
1792
1801 static AudioCodec *getCodec(Info &info, bool loaded = false);
1802
1809 static bool load(const char *name);
1810
1818 static bool load(Encoding encoding);
1819
1828 virtual Level getImpulse(void *buffer, unsigned number = 0);
1829
1837 virtual Level getPeak(void *buffer, unsigned number = 0);
1838
1849 virtual bool isSilent(Level threashold, void *buffer, unsigned number = 0);
1850
1859 virtual unsigned encode(Linear buffer, void *dest, unsigned number = 0) = 0;
1860
1869 virtual unsigned encodeBuffered(Linear Buffer, Encoded dest, unsigned number);
1870
1879 virtual unsigned decode(Linear buffer, void *source, unsigned number = 0) = 0;
1880
1890 virtual unsigned decodeBuffered(Linear buffer, Encoded source, unsigned len);
1891
1897 virtual unsigned getEstimated(void);
1898
1904 virtual unsigned getRequired(void);
1905
1915 virtual unsigned getPacket(Encoded destination, Encoded data, unsigned size);
1916
1922 inline Info getInfo(void)
1923 {return info;};
1924};
1925
1927{
1928protected:
1930
1931public:
1932 virtual ~AudioDevice() {};
1933
1941 virtual unsigned putSamples(Linear buffer, unsigned count) = 0;
1942
1950 virtual unsigned getSamples(Linear buffer, unsigned count) = 0;
1951
1960 virtual ssize_t putBuffer(Encoded data, size_t count);
1961
1970 virtual ssize_t getBuffer(Encoded data, size_t count);
1971
1979 virtual bool setEncoded(Info &info)
1980 {return false;};
1981
1990 virtual bool setAudio(Rate rate = rate8khz, bool stereo = false, timeout_t framing = 20) = 0;
1991
1998 virtual void sync(void)
1999 {return;};
2000
2004 virtual void flush(void) = 0;
2005
2015 unsigned bufMono(Linear buffer, unsigned count);
2016
2026 unsigned bufStereo(Linear buffer, unsigned count);
2027
2033 inline Info *getInfo(void)
2034 {return &info;};
2035
2044 inline bool isEnabled(void)
2045 {return enabled;};
2046};
2047
2057{
2058public:
2059 typedef struct _tonedef {
2062 unsigned count;
2063 unsigned short f1, f2;
2064 } tonedef_t;
2065
2066 typedef struct _tonekey {
2070 char id[1];
2071 } tonekey_t;
2072
2083
2091
2098 bool isComplete(void);
2099
2100
2108 static bool load(const char *pathname, const char *locale = NULL);
2109
2117 static tonekey_t *find(const char *tone, const char *locale = NULL);
2118
2119protected:
2126};
2127
2138{
2139protected:
2142 const char *digits;
2145
2146public:
2155 DTMFTones(const char *digits, Level level, timeout_t duration = 20, timeout_t interdigit = 60);
2156
2158
2160 bool isComplete(void);
2161};
2162
2173{
2174protected:
2177 const char *digits;
2180
2181public:
2190 MFTones(const char *digits, Level level, timeout_t duration = 20, timeout_t interdigit = 60);
2191
2193
2195 bool isComplete(void);
2196};
2197
2198
2204{
2205public:
2208
2217 int putSamples(Linear buffer, int count);
2218
2225 int getResult(char *data, int size);
2226
2227protected:
2229 void goertzelUpdate(goertzel_state_t *s, Sample x[], int samples);
2231
2232private:
2233 dtmf_detect_state_t *state;
2234 tone_detection_descriptor_t dtmf_detect_row[4];
2235 tone_detection_descriptor_t dtmf_detect_col[4];
2236 tone_detection_descriptor_t dtmf_detect_row_2nd[4];
2237 tone_detection_descriptor_t dtmf_detect_col_2nd[4];
2238 tone_detection_descriptor_t fax_detect;
2239 tone_detection_descriptor_t fax_detect_2nd;
2240};
2241
2242}
2243
2244#endif
2245
#define __EXPORT
Definition audio2.h:51
Audio source description.
Definition audio2.h:339
Encoding encoding
Definition audio2.h:342
void set(void)
unsigned order
Definition audio2.h:345
timeout_t framing
Definition audio2.h:347
unsigned padding
Definition audio2.h:346
unsigned framesize
Definition audio2.h:346
unsigned long bitrate
Definition audio2.h:344
char * annotation
Definition audio2.h:348
unsigned headersize
Definition audio2.h:346
unsigned long rate
Definition audio2.h:343
Format format
Definition audio2.h:341
void setRate(Rate rate)
unsigned framecount
Definition audio2.h:346
void setFraming(timeout_t frame)
void clear(void)
ssize_t getPacket(Encoded data)
Get's a packet of audio data.
Definition audio2.h:981
unsigned getSampleRate(void)
Generic sample rate.
Definition audio2.h:944
AudioBase(Info *info)
Create audio base object with audio source description.
ssize_t putNative(Encoded data, size_t size)
Puts raw data and does native to refined endian swapping if needed based on encoding type and local m...
virtual ssize_t putBuffer(Encoded data, size_t size)=0
Abstract interface to put raw data.
AudioBase()
Create audio base object with no info.
ssize_t getNative(Encoded data, size_t size)
Get raw data and assure is in native machine endian.
virtual ~AudioBase()
Destroy an audio base object.
Info info
Definition audio2.h:911
virtual ssize_t getBuffer(Encoded data, size_t size)=0
Abstract interface to get raw data.
Encoding getEncoding(void)
Generic get encoding.
Definition audio2.h:936
ssize_t putBuffer(Encoded data, size_t number)
Put data into the audio buffer.
AudioBuffer(Info *info, size_t size=4096)
virtual ~AudioBuffer()
ssize_t getBuffer(Encoded data, size_t number)
save audio data from buffer data.
The codec class is a virtual used for transcoding audio samples between linear frames (or other known...
Definition audio2.h:1734
virtual Level getImpulse(void *buffer, unsigned number=0)
Get the impulse energy level of a frame of X samples in the specified codec format.
virtual unsigned getEstimated(void)
Get estimated data required for buffered operations.
static bool load(Encoding encoding)
Find and load a codec file by it's encoding type.
static AudioCodec * getCodec(Info &info, bool loaded=false)
Get the codec base class for accessing a specific derived codec identified by audio source descriptor...
virtual AudioCodec * getByInfo(Info &info)
get a codec by audio source info descriptor.
Definition audio2.h:1760
static AudioCodec * getCodec(Encoding encoding, const char *format=NULL, bool loaded=false)
Get the codec base class for accessing a specific derived codec identified by encoding type and optio...
virtual ~AudioCodec()
Definition audio2.h:1772
static AudioCodec * first
Definition audio2.h:1736
Info info
Definition audio2.h:1740
Info getInfo(void)
Get an info description for this codec.
Definition audio2.h:1922
virtual unsigned getPacket(Encoded destination, Encoded data, unsigned size)
Get a packet of data rather than decode.
Encoding encoding
Definition audio2.h:1738
const char * name
Definition audio2.h:1739
static bool load(const char *name)
Load a named codec set into process memory.
virtual unsigned decode(Linear buffer, void *source, unsigned number=0)=0
Decode the sample frame into linear samples.
virtual Level getPeak(void *buffer, unsigned number=0)
Get the peak energy level within the frame of X samples.
virtual AudioCodec * getByFormat(const char *format)
often used to create a "new" codec of a subtype based on encoding format, default returns the current...
Definition audio2.h:1751
virtual bool isSilent(Level threashold, void *buffer, unsigned number=0)
Signal if the current audio frame is silent.
virtual unsigned decodeBuffered(Linear buffer, Encoded source, unsigned len)
Buffer and decode data into linear samples.
virtual unsigned getRequired(void)
get required samples for encoding.
virtual unsigned encodeBuffered(Linear Buffer, Encoded dest, unsigned number)
Encode linear samples buffered into the coded.
AudioCodec * next
Definition audio2.h:1737
AudioCodec(const char *name, Encoding encoding)
Base for codecs, create a named coded of a specific encoding.
virtual unsigned encode(Linear buffer, void *dest, unsigned number=0)=0
Encode a linear sample frame into the codec sample buffer.
static void endCodec(AudioCodec *codec)
End use of a requested codec.
Definition audio2.h:1927
bool isEnabled(void)
Whether device is currently enabled.
Definition audio2.h:2044
unsigned bufMono(Linear buffer, unsigned count)
Process linear mono audio and automatically convert to the encoding format the audio device is curren...
virtual void sync(void)
Synchronize timing for audio device to next audio frame.
Definition audio2.h:1998
virtual unsigned putSamples(Linear buffer, unsigned count)=0
Copy linear samples to an audio device through its virtual.
virtual bool setAudio(Rate rate=rate8khz, bool stereo=false, timeout_t framing=20)=0
Set properties for audio device.
Info * getInfo(void)
Get audio device source descriptor in effect for the device.
Definition audio2.h:2033
virtual ssize_t getBuffer(Encoded data, size_t count)
Record audio encoded in the currently selected encoding for the audio device.
virtual unsigned getSamples(Linear buffer, unsigned count)=0
Copy linear samples from an audio device through its virtual.
bool enabled
Definition audio2.h:1929
virtual bool setEncoded(Info &info)
Use encoding source descriptor to select the audio encoding format the audio device should be using.
Definition audio2.h:1979
unsigned bufStereo(Linear buffer, unsigned count)
Process linear stereo audio and automatically convert to the encoding format the audio device is curr...
virtual ~AudioDevice()
Definition audio2.h:1932
virtual ssize_t putBuffer(Encoded data, size_t count)
Copy audio encoded in the currently selected encoding for the audio device.
virtual void flush(void)=0
Flush any pending buffered samples in audio device.
unsigned long getHeader(void)
Get number of bytes in the file header.
Definition audio2.h:1140
AudioCodec * getCodec(void)
AudioFile(const char *name, Info *info, unsigned long minimum=0)
Create and open a new audio file for writing.
virtual bool isOpen(void)
Test if the file is opened.
virtual void afClose(void)
Close the derived file handling system's file handle.
Error setPosition(unsigned long samples=~0l)
Seek a file position by sample count.
const char * getErrorStr(Error err)
Return a human-readable error message given a numeric error code of type Audio::Error.
Error getInfo(Info *info)
Copy the source description of the audio file into the specified object.
void setLong(unsigned char *data, unsigned long value)
Save a long as four byte binary data stored in the endian order specified in the source description.
unsigned getSampleRate(void)
Get audio encoding sample rate, in samples per second, for this audio file.
Definition audio2.h:1468
unsigned long header
Definition audio2.h:1047
ssize_t getBuffer(Encoded buffer, size_t len=0)
Retrieve bytes from the file into a memory buffer.
Error position(const char *timestamp)
Seek a file position by timestamp.
virtual bool afCreate(const char *path, bool exclusive=false)
void initialize(void)
unsigned long getAbsolutePosition(void)
Get the current file pointer in bytes relative to the start of the file.
time_t getAge(void)
Returns age since last prior access.
void getPosition(char *timestamp, size_t size)
Return the timestamp of the current absolute file position.
Error putSamples(void *buffer, unsigned samples=0)
Insert samples into the file from a memory buffer.
void * handle
Definition audio2.h:1057
unsigned long length
Definition audio2.h:1049
char * pathname
Definition audio2.h:1045
void mp3info(mpeg_audio *mp3)
void getWaveFormat(int size)
virtual char * getContinuation(void)
This function is used to splice multiple audio files together into a single stream of continues audio...
Definition audio2.h:1119
void open(const char *name, Mode mode=modeWrite, timeout_t framing=0)
Open an audio file and associate it with this object.
ssize_t putBuffer(Encoded buffer, size_t len=0)
Insert bytes into the file from a memory buffer.
Error error
Definition audio2.h:1046
unsigned getLinear(Linear buffer, unsigned request=0)
Retrieve and convert content to linear encoded audio data from it's original form.
virtual int afWrite(unsigned char *data, unsigned size)
Write a number of bytes into the file at the current file pointer.
Encoding getEncoding(void)
Return audio encoding format for this audio file.
Definition audio2.h:1451
AudioFile()
Construct an audio file without attaching to the filesystem.
Definition audio2.h:1204
Mode mode
Definition audio2.h:1060
Format getFormat(void)
Return base file format of containing audio file.
Definition audio2.h:1459
virtual bool afPeek(unsigned char *data, unsigned size)
bool isSigned(void)
Return if the current content is signed or unsigned samples.
unsigned short getShort(unsigned char *data)
Convert binary 2 byte data stored in the order specified in the source description into a short varia...
unsigned long minimum
Definition audio2.h:1048
void clear(void)
Clear the AudioFile structure.
Error getSamples(void *buffer, unsigned samples=0)
Retrieve samples from the file into a memory buffer.
Error getError(void)
Get last error code.
Definition audio2.h:1484
virtual bool afOpen(const char *path, Mode m=modeWrite)
Error setMinimum(unsigned long minimum)
Set minimum file size for a created file.
AudioFile(const char *name, unsigned long offset=0)
Construct and open an existing audio file for read/write.
bool operator!(void)
Definition audio2.h:1487
size_t getSize(void)
Get maximum size of frame buffer for data use.
Definition audio2.h:1246
unsigned putLinear(Linear buffer, unsigned request=0)
Convert and store content from linear encoded audio data to the format of the audio file.
void close(void)
Close an object associated with an open file.
virtual bool afSeek(unsigned long pos)
Seek to the given position relative to the start of the file and set the file pointer.
Error skip(long number)
Change the file position by skipping a specified number of audio samples of audio data.
unsigned long getLong(unsigned char *data)
Convert binary 4 byte data stored in the order specified in the source description into a long variab...
virtual ~AudioFile()
void setShort(unsigned char *data, unsigned short value)
Save a short as two byte binary data stored in the endian order specified in the source description.
virtual int afRead(unsigned char *data, unsigned size)
Read a given number of bytes from the file, starting from the current file pointer.
virtual bool hasPositioning(void)
Return true if underlying derived class supports direct access to file positioning.
Definition audio2.h:1443
char * getAnnotation(void)
Get annotation extracted from header of containing file.
Definition audio2.h:1476
int fd
Definition audio2.h:1056
unsigned long iolimit
Definition audio2.h:1061
Error setLimit(unsigned long maximum=0l)
Set the maximum file position for reading and writing of audio data by samples.
void create(const char *name, Info *info, bool exclusive=false, timeout_t framing=0)
Create a new audio file and associate it with this object.
Error setError(Error err)
unsigned long getPosition(void)
Get the current file pointer in samples relative to the start of the sample buffer.
Generic audio class to hold master data types and various useful class encapsulated friend functions ...
Definition audio2.h:89
static Level getPeak(Info &info, void *buffer, unsigned number=0)
Get the peak (highest energy) level found in a frame of audio data.
static const char * getExtension(Encoding encoding)
Get the preferred file extension name to use for a given audio encoding type.
static Rate getRate(Encoding encoding)
Return default sample rate associated with the specified audio encoding format.
int32_t snd32_t
Definition audio2.h:100
static const char * getMIME(Info &info)
Get the mime descriptive type for a given Audio encoding description, usually retrieved from a newly ...
static Level getPeak(Encoding encoding, void *buffer, unsigned number)
Get the peak (highest energy) level found in a frame of audio data.
static timeout_t toTimeout(const char *timestamp)
Convert ascii timestamp representation to a timeout number.
Format
Audio container file format.
Definition audio2.h:230
@ snd
Definition audio2.h:232
@ mpeg
Definition audio2.h:234
@ wave
Definition audio2.h:235
@ riff
Definition audio2.h:233
@ raw
Definition audio2.h:231
int16_t snd16_t
Definition audio2.h:99
static Level getImpulse(Encoding encoding, void *buffer, unsigned number)
Get the energey impulse level of a frame of audio data.
static void fill(unsigned char *address, int number, Encoding encoding)
Fill an audio buffer with "empty" (silent) audio data, based on the audio encoding format.
static const unsigned ndata
Definition audio2.h:107
static float todbm(Level power)
Convert integer power levels to dbm.
Rate
Audio encoding rate, samples per second.
Definition audio2.h:148
@ rate44khz
Definition audio2.h:154
@ rate6khz
Definition audio2.h:150
@ rateUnknown
Definition audio2.h:149
@ rate8khz
Definition audio2.h:151
@ rate16khz
Definition audio2.h:152
@ rate32khz
Definition audio2.h:153
static bool swapEndian(Info &info, void *buffer, unsigned number)
Optionally swap endian of audio data if the audio source description byte order is different from the...
static int getFrame(Encoding encoding, int samples=0)
Returns the number of bytes in a sample frame for the given encoding type, rounded up to the nearest ...
int16_t Level
Definition audio2.h:101
static int getCount(Encoding encoding)
Returns the number of samples in all channels for a frame in the given encoding.
static Encoding getMono(Encoding encoding)
Get the mono encoding format associated with the given format.
static size_t toBytes(Encoding encoding, unsigned long number)
Compute the number of bytes a given number of samples in a given audio encoding will occupy.
static void toTimestamp(timeout_t duration, char *address, size_t size)
Provide ascii timestamp representation of a timeout value.
static timeout_t getFraming(Info &info, timeout_t timeout=0)
Return frame time for an audio source description.
static Encoding getStereo(Encoding encoding)
Get the stereo encoding format associated with the given format.
unsigned char * Encoded
Definition audio2.h:143
static Level getImpulse(Info &info, void *buffer, unsigned number=0)
Get the energey impulse level of a frame of audio data.
static Rate getRate(Encoding e, Rate request)
Return optional rate setting effect.
static bool loadPlugin(const char *path)
Load a dso plugin (codec plugin), used internally...
DeviceMode
Audio device access mode.
Definition audio2.h:242
@ PLAYREC
Definition audio2.h:245
@ PLAY
Definition audio2.h:243
@ RECORD
Definition audio2.h:244
static timeout_t getFraming(Encoding encoding, timeout_t timeout=0)
Return frame timing for an audio encoding format.
static bool hasDevice(unsigned device=0)
Test for the presense of a specified (indexed) audio device.
static size_t maxFramesize(Info &info)
Maximum framesize for a given coding that may be needed to store a result.
static bool isLinear(Encoding encoding)
Test if the audio encoding format is a linear one.
int16_t * Linear
Definition audio2.h:103
static bool isEndian(Encoding encoding)
Test if the endian byte order of the encoding format is different from the machine's native byte orde...
static bool isStereo(Encoding encoding)
Test if the audio encoding format is a stereo format.
static bool isMono(Encoding encoding)
Test if the audio encoding format is a mono format.
static const char * getName(Encoding encoding)
Get the short ascii description used for the given audio encoding type.
Error
Audio error conditions.
Definition audio2.h:252
@ errEncodingInvalid
Definition audio2.h:259
@ errRateInvalid
Definition audio2.h:258
@ errReadFailure
Definition audio2.h:262
@ errNoCodec
Definition audio2.h:272
@ errWriteInterrupt
Definition audio2.h:261
@ errNotOpened
Definition audio2.h:255
@ errRequestInvalid
Definition audio2.h:266
@ errStartOfFile
Definition audio2.h:257
@ errNotPlaying
Definition audio2.h:271
@ errEndOfFile
Definition audio2.h:256
@ errWriteFailure
Definition audio2.h:263
@ errWriteIncomplete
Definition audio2.h:265
@ errInvalidTrack
Definition audio2.h:269
@ errReadInterrupt
Definition audio2.h:260
@ errSuccess
Definition audio2.h:253
@ errPlaybackFailed
Definition audio2.h:270
@ errReadIncomplete
Definition audio2.h:264
@ errTOCFailed
Definition audio2.h:267
@ errStatFailed
Definition audio2.h:268
@ errReadLast
Definition audio2.h:254
Mode
File processing mode, whether to skip missing files, etc.
Definition audio2.h:162
@ modeReadAny
Definition audio2.h:164
@ modeCreate
Definition audio2.h:172
@ modeReadOne
Definition audio2.h:165
@ modeWrite
Definition audio2.h:166
@ modeAppend
Definition audio2.h:171
@ modeFeed
Definition audio2.h:169
@ modeRead
Definition audio2.h:163
@ modeInfo
Definition audio2.h:168
@ modeCache
Definition audio2.h:167
static const char * getCodecPath(void)
Get pathname to where loadable codec modules are stored.
static bool isBuffered(Encoding encoding)
Test if the audio encoding format must be packetized (that is, has irregular sized frames) and must b...
static Encoding getEncoding(const char *name)
Get the audio encoding format that is specified by a short ascii name.
int16_t Sample
Definition audio2.h:102
static unsigned long toSamples(Encoding encoding, size_t bytes)
Compute byte counts of audio data into number of samples based on the audio encoding format used.
Encoding
Audio encoding formats.
Definition audio2.h:180
@ g722Audio
Definition audio2.h:183
@ mp1Audio
Definition audio2.h:193
@ speexUltra
Definition audio2.h:219
@ g729Audio
Definition audio2.h:217
@ cdaMono
Definition audio2.h:205
@ g723_3bit
Definition audio2.h:187
@ speexNarrow
Definition audio2.h:221
@ sx73Voice
Definition audio2.h:198
@ g722_6bit
Definition audio2.h:185
@ mp3Audio
Definition audio2.h:195
@ speexVoice
Definition audio2.h:214
@ cdaStereo
Definition audio2.h:204
@ pcm32Mono
Definition audio2.h:211
@ mulawAudio
Definition audio2.h:191
@ pcm8Stereo
Definition audio2.h:206
@ pcm32Stereo
Definition audio2.h:210
@ alawAudio
Definition audio2.h:192
@ speexAudio
Definition audio2.h:215
@ g723_4bit
Definition audio2.h:223
@ mp2Audio
Definition audio2.h:194
@ gsmVoice
Definition audio2.h:189
@ unknownEncoding
Definition audio2.h:181
@ g721ADPCM
Definition audio2.h:182
@ g722_7bit
Definition audio2.h:184
@ msgsmVoice
Definition audio2.h:190
@ okiADPCM
Definition audio2.h:196
@ g723_2bit
Definition audio2.h:186
@ voxADPCM
Definition audio2.h:197
@ pcm16Stereo
Definition audio2.h:208
@ sx96Voice
Definition audio2.h:199
@ g723_5bit
Definition audio2.h:188
@ pcm16Mono
Definition audio2.h:209
@ pcm8Mono
Definition audio2.h:207
@ ilbcAudio
Definition audio2.h:218
@ speexWide
Definition audio2.h:222
static size_t toBytes(Info &info, unsigned long number)
Compute the number of bytes a given number of samples in a given audio encoding will occupy.
static void swapEncoded(Info &info, Encoded data, size_t bytes)
Optionally swap endian of encoded audio data based on the audio encoding type, and relationship to na...
static Level tolevel(float dbm)
Convert dbm power level to integer value (0-32768).
unsigned long timeout_t
Definition audio2.h:104
static bool swapEndian(Encoding encoding, void *buffer, unsigned number)
Optionally swap endian of audio data if the encoding format endian byte order is different from the m...
static bool isEndian(Info &info)
Test if the endian byte order of the audio source description is different from the machine's native ...
static unsigned long toSamples(Info &info, size_t bytes)
Compute byte counts of audio data into number of samples based on the audio source description used.
static AudioDevice * getDevice(unsigned device=0, DeviceMode mode=PLAY)
Get a audio device object that can be used to play or record audio.
unsigned gpos
Definition audio2.h:754
unsigned ppos
Definition audio2.h:754
Sample last
Definition audio2.h:755
size_t estimate(size_t count)
AudioResample(Rate mul, Rate div)
unsigned dfact
Definition audio2.h:753
unsigned max
Definition audio2.h:753
unsigned mfact
Definition audio2.h:753
Linear buffer
Definition audio2.h:756
size_t process(Linear from, Linear to, size_t count)
Linear bufferFrame
Definition audio2.h:1515
void flush(void)
flush any unsaved buffered data to disk.
unsigned putMono(Linear buffer, unsigned frames=1)
Automatically convert and put mono linear audio data into the audio file.
virtual ~AudioStream()
bool streamable
Definition audio2.h:1514
unsigned getStereo(Linear buffer, unsigned frames=1)
Get and automatically convert audio file data into stereo (two channel) linear audio samples.
unsigned getEncoded(Encoded address, unsigned frames=1)
Get data from the streamed file in it's native encoding.
void open(const char *name, Mode mode=modeRead, timeout_t framing=0)
Open existing audio file for streaming.
unsigned encSize
Definition audio2.h:1519
ssize_t getBuffer(Encoded data, size_t count)
Virtual for packet i/o intercept.
AudioCodec * codec
Definition audio2.h:1512
unsigned getCount(void)
Get the number of samples expected in a frame.
AudioStream(const char *name, Info *info, bool exclusive=false, timeout_t framing=0)
Create an audio stream object and a new audio file.
unsigned putEncoded(Encoded address, unsigned frames=1)
Put data encoded in the native format of the stream file.
unsigned bufferChannels
Definition audio2.h:1517
unsigned decSize
Definition audio2.h:1519
void create(const char *name, Info *info, bool exclusive=false, timeout_t framing=0)
Create a new audio file for streaming.
unsigned putStereo(Linear buffer, unsigned frames=1)
Automatically convert and put stereo linear audio data into the audio file.
unsigned getMono(Linear buffer, unsigned frames=1)
Get and automatically convert audio file data into mono linear audio samples.
unsigned putEncoded(AudioCodec *codec, Encoded address, unsigned frames=1)
Stream audio data in an alternate codec into the currently opened file.
void close(void)
Close the currently open audio file for streaming.
unsigned getEncoded(AudioCodec *codec, Encoded address, unsigned frames=1)
Stream audio data from the file and convert into an alternate encoding based on the codec supplied.
unsigned bufMono(Linear buffer, unsigned count)
Automatically convert and put arbitrary linear mono data into the audio file.
Linear encBuffer
Definition audio2.h:1518
ssize_t getPacket(Encoded data)
Get a packet of data from the file.
Linear decBuffer
Definition audio2.h:1518
bool isStreamable(void)
Check if the audio file may be streamed.
AudioStream(const char *name, Mode mode=modeRead, timeout_t framing=0)
Create an audio stream object and open an existing audio file.
unsigned bufferPosition
Definition audio2.h:1516
unsigned bufAudio(Linear samples, unsigned count, unsigned size)
AudioStream()
Create a new audiostream object.
AudioCodec * getCodec(void)
Return the codec being used if there is one.
Definition audio2.h:1717
unsigned bufStereo(Linear buffer, unsigned count)
Automatically convert and put arbitrary linear stereo data into the audio file.
Encoded framebuf
Definition audio2.h:1513
Rate getRate(void)
Get the sample encoding rate being used for the tone generator.
Definition audio2.h:823
Rate rate
Definition audio2.h:777
AudioTone(unsigned f1, unsigned f2, Level l1, Level l2, timeout_t duration=20, Rate sample=rate8khz)
Construct a dual tone frame generator.
unsigned getFrames(Linear buffer, unsigned number)
This is used to copy one or more pages of framed audio quickly to an external buffer.
bool isSilent(void)
Test if the tone generator is currently set to silence.
bool silencer
Definition audio2.h:782
virtual ~AudioTone()
AudioTone(timeout_t duration=20, Rate rate=rate8khz)
Construct a silent tone generator of specific frame size.
size_t getSamples(void)
Get the frame size for the number of audio samples generated.
Definition audio2.h:831
double df2
Definition audio2.h:780
void single(unsigned freq, Level level)
Set frame to generate single tone...
Linear frame
Definition audio2.h:779
void dual(unsigned f1, unsigned f2, Level l1, Level l2)
Set frame to generate dual tone...
Level m2
Definition audio2.h:781
virtual Linear getFrame(void)
Iterate the tone frame, and extract linear samples in native frame.
Level m1
Definition audio2.h:781
double p2
Definition audio2.h:780
double df1
Definition audio2.h:780
void reset(void)
Reset the tone generator completely.
void cleanup(void)
Cleanup for virtual destructors to use.
void silence(void)
Set the frame to silent.
double p1
Definition audio2.h:780
unsigned samples
Definition audio2.h:778
AudioTone(unsigned freq, Level level, timeout_t duration=20, Rate sample=rate8khz)
Construct a single tone frame generator.
virtual bool isComplete(void)
See if at end of tone.
float goertzelResult(goertzel_state_t *s)
void goertzelInit(goertzel_state_t *s, tone_detection_descriptor_t *t)
void goertzelUpdate(goertzel_state_t *s, Sample x[], int samples)
int getResult(char *data, int size)
Copy detected dtmf results into a data buffer.
int putSamples(Linear buffer, int count)
This routine is used to push linear audio data into the dtmf tone detection analysizer.
bool isComplete(void)
Level level
Definition audio2.h:2143
unsigned remaining
Definition audio2.h:2140
DTMFTones(const char *digits, Level level, timeout_t duration=20, timeout_t interdigit=60)
Generate a dtmf dialer for a specified dialing string.
const char * digits
Definition audio2.h:2142
timeout_t frametime
Definition audio2.h:2141
Linear getFrame(void)
bool complete
Definition audio2.h:2144
unsigned dtmfframes
Definition audio2.h:2140
bool isComplete(void)
timeout_t frametime
Definition audio2.h:2176
Linear getFrame(void)
bool complete
Definition audio2.h:2179
const char * digits
Definition audio2.h:2177
unsigned remaining
Definition audio2.h:2175
Level level
Definition audio2.h:2178
bool kflag
Definition audio2.h:2179
unsigned mfframes
Definition audio2.h:2175
MFTones(const char *digits, Level level, timeout_t duration=20, timeout_t interdigit=60)
Generate a mf dialer for a specified dialing string.
unsigned remaining
Definition audio2.h:2122
static tonekey_t * find(const char *tone, const char *locale=NULL)
find an entry in the teltones database.
struct ost::TelTone::_tonedef tonedef_t
struct ost::TelTone::_tonekey tonekey_t
unsigned silent
Definition audio2.h:2122
timeout_t framing
Definition audio2.h:2123
tonekey_t * tone
Definition audio2.h:2120
TelTone(tonekey_t *key, Level level, timeout_t frame=20)
Create a tone sequencing object for a specific telephony tone key id.
Linear getFrame(void)
Generate and retrieve one frame of linear audio data for the telephony tone sequence being created.
tonedef_t * def
Definition audio2.h:2121
bool complete
Definition audio2.h:2125
Level level
Definition audio2.h:2124
bool isComplete(void)
Check if all audio frames for this tone has been created.
static bool load(const char *pathname, const char *locale=NULL)
Load a teltones database file into memory.
unsigned count
Definition audio2.h:2122
Definition audio2.h:68
Definition audio2.h:115
int hit1
Definition audio2.h:116
float energy
Definition audio2.h:128
int current_digits
Definition audio2.h:132
goertzel_state_t fax_tone2nd
Definition audio2.h:127
int lost_digits
Definition audio2.h:134
int digit_hits[16]
Definition audio2.h:135
goertzel_state_t fax_tone
Definition audio2.h:126
int fax_hits
Definition audio2.h:136
char digits[129]
Definition audio2.h:131
goertzel_state_t row_out2nd[4]
Definition audio2.h:124
int hit2
Definition audio2.h:117
goertzel_state_t col_out2nd[4]
Definition audio2.h:125
int detected_digits
Definition audio2.h:133
goertzel_state_t col_out[4]
Definition audio2.h:123
int current_sample
Definition audio2.h:130
int mhit
Definition audio2.h:120
int hit3
Definition audio2.h:118
int hit4
Definition audio2.h:119
goertzel_state_t row_out[4]
Definition audio2.h:122
Definition audio2.h:109
float fac
Definition audio2.h:112
float v2
Definition audio2.h:110
float v3
Definition audio2.h:111
Definition audio2.h:281
unsigned char mp_priv
Definition audio2.h:289
unsigned char mp_sync1
Definition audio2.h:283
unsigned char mp_extend
Definition audio2.h:297
unsigned char mp_channels
Definition audio2.h:298
unsigned char mp_layer
Definition audio2.h:285
unsigned char mp_ver
Definition audio2.h:286
unsigned char mp_emp
Definition audio2.h:294
unsigned char mp_srate
Definition audio2.h:291
unsigned char mp_crc
Definition audio2.h:284
unsigned char mp_sync2
Definition audio2.h:287
unsigned char mp_original
Definition audio2.h:295
unsigned char mp_brate
Definition audio2.h:292
unsigned char mp_copyright
Definition audio2.h:296
unsigned char mp_pad
Definition audio2.h:290
Definition audio2.h:321
unsigned char genre
Definition audio2.h:328
char tag_album[30]
Definition audio2.h:325
char tag_year[4]
Definition audio2.h:326
char tag_artist[30]
Definition audio2.h:324
char tag_note[30]
Definition audio2.h:327
char tag_title[30]
Definition audio2.h:323
char tag_id[3]
Definition audio2.h:322
float fac
Definition audio2.h:140
Definition audio2.h:2059
timeout_t duration
Definition audio2.h:2061
timeout_t silence
Definition audio2.h:2061
struct _tonedef * next
Definition audio2.h:2060
unsigned short f2
Definition audio2.h:2063
unsigned count
Definition audio2.h:2062
unsigned short f1
Definition audio2.h:2063
Definition audio2.h:2066
struct _tonedef * first
Definition audio2.h:2068
struct _tonekey * next
Definition audio2.h:2067
struct _tonedef * last
Definition audio2.h:2069