Debian Codegraph @

src/host/chuck_audio.h

raw symbols SCIP
1 /*----------------------------------------------------------------------------
2 ChucK Strongly-timed Audio Programming Language
3 Compiler, Virtual Machine, and Synthesis Engine
4
5 Copyright (c) 2003 Ge Wang and Perry R. Cook. All rights reserved.
6 http://chuck.stanford.edu/
7 http://chuck.cs.princeton.edu/
8
9 This program is free software; you can redistribute it and/or modify
10 it under the dual-license terms of EITHER the MIT License OR the GNU
11 General Public License (the latter as published by the Free Software
12 Foundation; either version 2 of the License or, at your option, any
13 later version).
14
15 This program is distributed in the hope that it will be useful and/or
16 interesting, but WITHOUT ANY WARRANTY; without even the implied warranty
17 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 MIT Licence and/or the GNU General Public License for details.
19
20 You should have received a copy of the MIT License and the GNU General
21 Public License (GPL) along with this program; a copy of the GPL can also
22 be obtained by writing to the Free Software Foundation, Inc., 59 Temple
23 Place, Suite 330, Boston, MA 02111-1307 U.S.A.
24 -----------------------------------------------------------------------------*/
25
26 //-----------------------------------------------------------------------------
27 // name: chuck_audio.h
28 // desc: chuck host digital audio I/O, using RtAudio (from Gary Scavone)
29 //
30 // author: Ge Wang ([email protected] | [email protected])
31 // Spencer Salazar ([email protected])
32 // RtAudio by: Gary Scavone
33 // date: Spring 2004
34 //-----------------------------------------------------------------------------
35 #ifndef __CHUCK_AUDIO_H__
36 #define __CHUCK_AUDIO_H__
37
38 #include "chuck_def.h"
39 #include <string>
40 #include "RtAudio/RtAudio.h"
41
42
43
44
45 //-----------------------------------------------------------------------------
46 // define, defaults, forward references
47 //-----------------------------------------------------------------------------
48 // sample rate defaults by platform
49 #if defined(__PLATFORM_LINUX__) // linux
50 #define CK_SAMPLE_RATE_DEFAULT 48000
51 #define CK_BUFFER_SIZE_DEFAULT 256
52 #elif defined(__PLATFORM_APPLE__) // macOS
53 #define CK_SAMPLE_RATE_DEFAULT 44100
54 #define CK_BUFFER_SIZE_DEFAULT 256
55 #else // windows & everywhere else
56 #define CK_SAMPLE_RATE_DEFAULT 44100
57 #define CK_BUFFER_SIZE_DEFAULT 512
58 #endif
59
60 // number of channels
61 #define CK_NUM_CHANNELS_DEFAULT 2
62 // number buffers
63 #define CK_NUM_BUFFERS_DEFAULT 8
64
65
66 //-----------------------------------------------------------------------------
67 // audio callback definition
68 //-----------------------------------------------------------------------------
69 typedef void (* ck_f_audio_cb)( SAMPLE * input, SAMPLE * output,
70 t_CKUINT numFrames, t_CKUINT numInChans, t_CKUINT numOutChans,
71 void * userData );
72
73
74 // real-time watch dog
75 extern t_CKBOOL g_do_watchdog;
76 // countermeasure
77 extern t_CKUINT g_watchdog_countermeasure_priority;
78 // watchdog timeout
79 extern t_CKFLOAT g_watchdog_timeout;
80
81
82
83
84 //-----------------------------------------------------------------------------
85 // name: class ChuckAudioDriverInfo
86 // desc: info pertaining to an audio driver
87 //-----------------------------------------------------------------------------
88 struct ChuckAudioDriverInfo
89 {
90 // driver API ID; e.g., RtAudio::Api values
91 // RtAudio::MACOSX_CORE or RtAudio::WINDOWS_DS or RtAudio::UNIX_JACK
92 // (see RtAudio.h for full list)
93 t_CKUINT driver;
94 // a short name of the driver, e.g., "DS"
95 std::string name;
96 // a longer name of the driver, e.g., "DirectSound"
97 std::string userFriendlyName;
98
99 // constructor
100 ChuckAudioDriverInfo()
101 : driver(0),
102 name("(unspecified)"),
103 userFriendlyName("(unspecified driver")
104 { }
105 };
106
107
108
109
110 //-----------------------------------------------------------------------------
111 // name: class ChuckAudio
112 // desc: chuck host audio I/O
113 //-----------------------------------------------------------------------------
114 class ChuckAudio
115 {
116 public:
117 static t_CKBOOL initialize( t_CKUINT dac_device,
118 t_CKUINT adc_device,
119 t_CKUINT num_dac_channels,
120 t_CKUINT num_adc_channels,
121 t_CKUINT sample_rate,
122 t_CKUINT buffer_size,
123 t_CKUINT num_buffers,
124 ck_f_audio_cb callback,
125 void * data,
126 t_CKBOOL force_srate, // force_srate | 1.3.1.2 (added)
127 const char * driver // NULL means default for build | 1.5.0.0 (added)
128 );
129 static void shutdown( t_CKUINT msWait = 0 );
130 static t_CKBOOL start();
131 static t_CKBOOL stop();
132
133 public: // watchdog stuff
134 static t_CKBOOL watchdog_start();
135 static t_CKBOOL watchdog_stop();
136
137 public: // driver related operations
138 // default audio driver number
139 static RtAudio::Api defaultDriverApi();
140 // default audio driver name
141 static const char * defaultDriverName();
142 // get API/driver enum from name
143 static RtAudio::Api driverNameToApi( const char * driver = NULL );
144 // get API/drive name from int assumed to be RtAudio::Api enum
145 static const char * driverApiToName( t_CKUINT driverNum );
146 // get number of compiled audio driver APIs
147 static t_CKUINT numDrivers();
148 // get info on a particular driver
149 static ChuckAudioDriverInfo getDriverInfo( t_CKUINT n );
150
151 public: // audio device related operations
152 // probe audio devices; NULL for driver means default for build
153 static void probe( const char * driver );
154 // get device number by name?
155 // 1.4.2.0: changed return type from t_CKUINT to t_CKINT
156 static t_CKINT device_named( const char * driver,
157 const std::string & name,
158 t_CKBOOL needs_dac = FALSE,
159 t_CKBOOL needs_adc = FALSE );
160
161 public:
162 static t_CKUINT srate() { return m_sample_rate; }
163 static t_CKUINT num_channels_out() { return m_num_channels_out; }
164 static t_CKUINT num_channels_in() { return m_num_channels_in; }
165 static t_CKUINT dac_num() { return m_dac_n; }
166 static t_CKUINT adc_num() { return m_adc_n; }
167 static t_CKUINT bps() { return m_bps; }
168 static t_CKUINT buffer_size() { return m_buffer_size; }
169 static t_CKUINT num_buffers() { return m_num_buffers; }
170 static RtAudio * audio() { return m_rtaudio; }
171
172 static void set_extern( SAMPLE * in, SAMPLE * out )
173 { m_extern_in = in; m_extern_out = out; }
174 static int cb( void * output_buffer, void * input_buffer, unsigned int buffer_size,
175 double streamTime, RtAudioStreamStatus status, void * user_data );
176
177 public: // data
178 static t_CKBOOL m_init;
179 static t_CKBOOL m_start;
180 static t_CKBOOL m_go; // counter of # of times callback called
181 static t_CKBOOL m_silent; // if true, will output silence
182 static t_CKBOOL m_expand_in_mono2stereo; // 1.4.0.1 for in:1 out:2
183 static t_CKUINT m_num_channels_out;
184 static t_CKUINT m_num_channels_in;
185 static t_CKUINT m_num_channels_max; // the max of out/in
186 static t_CKUINT m_sample_rate;
187 static t_CKUINT m_bps;
188 static t_CKUINT m_buffer_size;
189 static t_CKUINT m_num_buffers;
190 static SAMPLE * m_buffer_out;
191 static SAMPLE * m_buffer_in;
192 static SAMPLE * m_extern_in; // for things like audicle
193 static SAMPLE * m_extern_out; // for things like audicle
194
195 static RtAudio * m_rtaudio;
196 static t_CKINT m_dac_n; // 1.5.0.3 (ge) changed to signed
197 static t_CKINT m_adc_n; // 1.5.0.3 (ge) changed to signed
198 static std::string m_dac_name;
199 static std::string m_adc_name;
200 static std::string m_driver_name;
201 static ck_f_audio_cb m_audio_cb;
202 static void * m_cb_user_data;
203 };
204
205
206
207
208 #endif