History

Fixes for new --driver commandline option.

Dana Batali committed 5 years ago

Commit f2b7d9e1 parent 04676c23 files · +44 −22Browse files

Unified · Split

3 files
  1. src/host/chuck_audio.cpp +35 −13
  2. src/host/chuck_audio.h +5 −4
  3. src/host/chuck_main.cpp +4 −5
src/host/chuck_audio.cpp+35−13
@@ -130,6 +130,23 @@ static RtAudio::Api driverNameToApi(char const *driver) · 129 unmodified lines
130130 return api;
131131 }
132132
133+static char const *apiToDriverName(RtAudio::Api api)
134+{
135+ static char const *drivers[] = {
136+ "unspecified",
137+ "ALSA",
138+ "Pulse",
139+ "OSS",
140+ "JACK",
141+ "MacOSXCore",
142+ "ASIO",
143+ "DS",
144+ "DUMMY",
145+ "Invalid"
146+ };
147+ return drivers[(int) api];
148+}
149+
133150 //-----------------------------------------------------------------------------
134151 // name: print()
135152 // desc: ...
@@ -179,7 +196,8 @@ void print( const RtAudio::DeviceInfo & info ) · 43 unmodified lines
179196 //-----------------------------------------------------------------------------
180197 void ChuckAudio::probe(char const *driver)
181198 {
182− RtAudio::Api api = driverNameToApi(driver);
199+ RtAudio::Api api = driverNameToApi(driver); // handles driver=NULL case
200+ char const *dnm = apiToDriverName(api);
183201 // rtaduio pointer
184202 RtAudio * audio = NULL;
185203 // device info struct
@@ -190,13 +208,13 @@ void ChuckAudio::probe(char const *driver) · 4 unmodified lines
190208 catch( RtAudioError err )
191209 {
192210 // problem finding audio devices, most likely
193− EM_error2b( 0, "%s", err.getMessage().c_str() );
211+ EM_error2b( 0, "%s: %s", dnm, err.getMessage().c_str() );
194212 return;
195213 }
196214
197215 // get count
198216 int devices = audio->getDeviceCount();
199− EM_error2b( 0, "found %d device(s) ...", devices );
217+ EM_error2b( 0, "%s found %d device(s) ...", dnm, devices );
200218
201219 // reset -- what does this do
202220 EM_reset_msg();
@@ -235,16 +253,19 @@ void ChuckAudio::probe(char const *driver) · 32 unmodified lines
235253 // desc: get device number by name; needs_dac/adc prompts further checks on
236254 // requested device having > 0 channels
237255 //-----------------------------------------------------------------------------
238−t_CKUINT ChuckAudio::device_named( const std::string & name, t_CKBOOL needs_dac,
256+t_CKUINT ChuckAudio::device_named( char const *driver,
257+ const std::string & name, t_CKBOOL needs_dac,
239258 t_CKBOOL needs_adc )
240259 {
241260 // rtaudio pointer
242261 RtAudio * audio = NULL;
243262 // device info struct
244263 RtAudio::DeviceInfo info;
264+ RtAudio::Api api = driverNameToApi(driver); // handles driver=NULL case
265+ char const *dnm = apiToDriverName(api);
245266
246267 // allocate RtAudio
247− try { audio = new RtAudio(); }
268+ try { audio = new RtAudio(api); }
248269 catch( RtAudioError err )
249270 {
250271 // problem finding audio devices, most likely
@@ -469,15 +490,15 @@ t_CKBOOL ChuckAudio::watchdog_stop() · 218 unmodified lines
469490 // name: initialize()
470491 // desc: ...
471492 //-----------------------------------------------------------------------------
472−t_CKBOOL ChuckAudio::initialize( t_CKUINT num_dac_channels,
493+t_CKBOOL ChuckAudio::initialize( char const *driver,
494+ t_CKUINT num_dac_channels,
473495 t_CKUINT num_adc_channels,
474496 t_CKUINT sample_rate,
475497 t_CKUINT buffer_size,
476498 t_CKUINT num_buffers,
477499 f_audio_cb callback,
478500 void * data,
479− t_CKBOOL force_srate,
480− char const *driver )
501+ t_CKBOOL force_srate )
481502 {
482503 if( m_init )
483504 return FALSE;
@@ -506,11 +527,12 @@ t_CKBOOL ChuckAudio::initialize( t_CKUINT num_dac_channels, · 22 unmodified lines
506527
507528 // allocate RtAudio
508529 RtAudio::Api api = driverNameToApi(driver);
530+ char const *dnm = apiToDriverName(api);
509531 try { m_rtaudio = new RtAudio(api); }
510532 catch( RtAudioError err )
511533 {
512534 // problem finding audio devices, most likely
513− EM_error2( 0, "%s", err.getMessage().c_str() );
535+ EM_error2( 0, "%s: %s", dnm, err.getMessage().c_str() );
514536 // clean up
515537 goto error;
516538 }
@@ -735,8 +757,8 @@ t_CKBOOL ChuckAudio::initialize( t_CKUINT num_dac_channels, · 218 unmodified lines
735757 // open device
736758 try {
737759 // log
738− EM_log( CK_LOG_FINE, "trying %d input %d output...",
739− m_num_channels_in, m_num_channels_out );
760+ EM_log( CK_LOG_FINE, "%s trying %d input %d output...",
761+ dnm, m_num_channels_in, m_num_channels_out );
740762
741763 RtAudio::StreamParameters output_parameters;
742764 output_parameters.deviceId = m_dac_n;
@@ -763,8 +785,8 @@ t_CKBOOL ChuckAudio::initialize( t_CKUINT num_dac_channels, · 20 unmodified lines
763785 &stream_options );
764786 } catch( RtAudioError err ) {
765787 // log
766− EM_log( CK_LOG_INFO, "exception caught: '%s'...", err.getMessage().c_str() );
767− EM_error2( 0, "%s", err.getMessage().c_str() );
788+ EM_log( CK_LOG_INFO, "%s exception caught: '%s'...", dnm, err.getMessage().c_str() );
789+ EM_error2( 0, "%s: %s", dnm, err.getMessage().c_str() );
768790 SAFE_DELETE( m_rtaudio );
769791 // clean up
770792 goto error;
src/host/chuck_audio.h+5−4
@@ -89,7 +89,8 @@ extern t_CKFLOAT g_watchdog_timeout; · 88 unmodified lines
8989 class ChuckAudio
9090 {
9191 public:
92− static t_CKBOOL initialize( t_CKUINT num_dac_channels,
92+ static t_CKBOOL initialize( char const *driver, // NULL means default for build
93+ t_CKUINT num_dac_channels,
9394 t_CKUINT num_adc_channels,
9495 t_CKUINT sample_rate,
9596 t_CKUINT buffer_size,
@@ -97,8 +98,7 @@ public: · 1 unmodified line
9798 f_audio_cb callback,
9899 void * data,
99100 // force_srate added 1.3.1.2
100− t_CKBOOL force_srate,
101− char const *driver // NULL means default for build
101+ t_CKBOOL force_srate
102102 );
103103 static void shutdown();
104104 static t_CKBOOL start();
@@ -112,7 +112,8 @@ public: // device info · 7 unmodified lines
112112 // probe audio devices
113113 static void probe(char const *driver); // NULL means default for build
114114 // get device number by name?
115− static t_CKUINT device_named( const std::string & name,
115+ static t_CKUINT device_named( char const *driver,
116+ const std::string & name,
116117 t_CKBOOL needs_dac = FALSE,
117118 t_CKBOOL needs_adc = FALSE );
118119
src/host/chuck_main.cpp+4−5
@@ -848,7 +848,7 @@ bool go( int argc, const char ** argv ) · 847 unmodified lines
848848 if( dac_name.size() > 0 )
849849 {
850850 // check with RtAudio
851− int dev = ChuckAudio::device_named( dac_name, TRUE, FALSE );
851+ int dev = ChuckAudio::device_named( audioDriver, dac_name, TRUE, FALSE );
852852 if( dev >= 0 )
853853 {
854854 dac = dev;
@@ -865,7 +865,7 @@ bool go( int argc, const char ** argv ) · 10 unmodified lines
865865 if( adc_name.size() > 0 )
866866 {
867867 // check with RtAudio
868− int dev = ChuckAudio::device_named( adc_name, FALSE, TRUE );
868+ int dev = ChuckAudio::device_named( audioDriver, adc_name, FALSE, TRUE );
869869 if( dev >= 0 )
870870 {
871871 adc = dev;
@@ -921,9 +921,8 @@ bool go( int argc, const char ** argv ) · 49 unmodified lines
921921 // TODO: refactor initialize() to take in the dac and adc nums
922922 ChuckAudio::m_adc_n = adc;
923923 ChuckAudio::m_dac_n = dac;
924− t_CKBOOL retval = ChuckAudio::initialize( dac_chans, adc_chans,
925− srate, buffer_size, num_buffers, cb, (void *)the_chuck, force_srate,
926− audioDriver );
924+ t_CKBOOL retval = ChuckAudio::initialize( audioDriver, dac_chans, adc_chans,
925+ srate, buffer_size, num_buffers, cb, (void *)the_chuck, force_srate);
927926 // check
928927 if( !retval )
929928 {

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t