13
0

Refactor PortAudioIO::discover into three private methods

This commit is contained in:
Tim Mayberry 2015-05-04 13:28:41 +10:00
parent 4e370feeb1
commit ff1d4d5c67
2 changed files with 38 additions and 15 deletions

View File

@ -211,29 +211,36 @@ PortAudioIO::get_default_output_device ()
} }
void void
PortAudioIO::discover() PortAudioIO::clear_device_list ()
{ {
if (!initialize_pa()) return;
for (std::map<int, paDevice*>::const_iterator i = _devices.begin (); i != _devices.end(); ++i) { for (std::map<int, paDevice*>::const_iterator i = _devices.begin (); i != _devices.end(); ++i) {
delete i->second; delete i->second;
} }
_devices.clear(); _devices.clear();
}
void
PortAudioIO::add_default_device ()
{
const PaHostApiInfo* info = Pa_GetHostApiInfo (_host_api_index); const PaHostApiInfo* info = Pa_GetHostApiInfo (_host_api_index);
if (info == NULL) return; if (info == NULL) return;
{ const PaDeviceInfo* nfo_i = Pa_GetDeviceInfo(get_default_input_device());
const PaDeviceInfo* nfo_i = Pa_GetDeviceInfo(get_default_input_device()); const PaDeviceInfo* nfo_o = Pa_GetDeviceInfo(get_default_output_device());
const PaDeviceInfo* nfo_o = Pa_GetDeviceInfo(get_default_output_device()); if (nfo_i && nfo_o) {
if (nfo_i && nfo_o) { _devices.insert (std::pair<int, paDevice*> (-1,
_devices.insert (std::pair<int, paDevice*> (-1, new paDevice("Default",
new paDevice("Default", nfo_i->maxInputChannels,
nfo_i->maxInputChannels, nfo_o->maxOutputChannels
nfo_o->maxOutputChannels )));
)));
}
} }
}
void
PortAudioIO::add_devices ()
{
const PaHostApiInfo* info = Pa_GetHostApiInfo (_host_api_index);
if (info == NULL) return;
int n_devices = Pa_GetDeviceCount(); int n_devices = Pa_GetDeviceCount();
#ifndef NDEBUG #ifndef NDEBUG
@ -259,6 +266,7 @@ PortAudioIO::discover()
if ( nfo->maxInputChannels == 0 && nfo->maxOutputChannels == 0) { if ( nfo->maxInputChannels == 0 && nfo->maxOutputChannels == 0) {
continue; continue;
} }
_devices.insert (std::pair<int, paDevice*> (i, new paDevice( _devices.insert (std::pair<int, paDevice*> (i, new paDevice(
nfo->name, nfo->name,
nfo->maxInputChannels, nfo->maxInputChannels,
@ -267,6 +275,16 @@ PortAudioIO::discover()
} }
} }
void
PortAudioIO::discover()
{
if (!initialize_pa()) return;
clear_device_list ();
add_default_device ();
add_devices ();
}
void void
PortAudioIO::pcm_stop () PortAudioIO::pcm_stop ()
{ {

View File

@ -75,7 +75,13 @@ public:
int get_capture_channel (uint32_t chn, float *input, uint32_t n_samples); int get_capture_channel (uint32_t chn, float *input, uint32_t n_samples);
int set_playback_channel (uint32_t chn, const float *input, uint32_t n_samples); int set_playback_channel (uint32_t chn, const float *input, uint32_t n_samples);
private: private: // Methods
void clear_device_list ();
void add_default_device ();
void add_devices ();
private: // Data
int _state; int _state;
bool _initialized; bool _initialized;
@ -91,7 +97,6 @@ private:
uint32_t _cur_input_latency; uint32_t _cur_input_latency;
uint32_t _cur_output_latency; uint32_t _cur_output_latency;
struct paDevice { struct paDevice {
std::string name; std::string name;
uint32_t n_inputs; uint32_t n_inputs;