1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-07-16 08:37:42 +02:00

DeviceToolbar.cpp: cleanup and add debug diagnostics

This commit is contained in:
mchinen 2011-01-12 21:16:29 +00:00
parent 26d18dc248
commit c183075a01

@ -95,7 +95,7 @@ static int DummyPaStreamCallback(
return 0; return 0;
} }
static void FillHostDeviceInfo(DeviceSourceMap *map, const PaDeviceInfo *info, int deviceIndex) static void FillHostDeviceInfo(DeviceSourceMap *map, const PaDeviceInfo *info, int deviceIndex, int isInput)
{ {
wxString hostapiName(Pa_GetHostApiInfo(info->hostApi)->name, wxConvLocal); wxString hostapiName(Pa_GetHostApiInfo(info->hostApi)->name, wxConvLocal);
wxString infoName(info->name, wxConvLocal); wxString infoName(info->name, wxConvLocal);
@ -104,7 +104,7 @@ static void FillHostDeviceInfo(DeviceSourceMap *map, const PaDeviceInfo *info, i
map->hostIndex = info->hostApi; map->hostIndex = info->hostApi;
map->deviceString = infoName; map->deviceString = infoName;
map->hostString = hostapiName; map->hostString = hostapiName;
map->numChannels = info->maxInputChannels; map->numChannels = isInput ? info->maxInputChannels : info->maxOutputChannels;
} }
static void AddSourcesFromStream(int deviceIndex, const PaDeviceInfo *info, std::vector<DeviceSourceMap> *maps, PaStream *stream) static void AddSourcesFromStream(int deviceIndex, const PaDeviceInfo *info, std::vector<DeviceSourceMap> *maps, PaStream *stream)
@ -115,7 +115,8 @@ static void AddSourcesFromStream(int deviceIndex, const PaDeviceInfo *info, std:
map.sourceIndex = -1; map.sourceIndex = -1;
map.totalSources = 0; map.totalSources = 0;
FillHostDeviceInfo(&map, info, deviceIndex); // Only inputs have sources, so we call FillHostDeviceInfo with a 1 to indicate this
FillHostDeviceInfo(&map, info, deviceIndex, 1);
portMixer = Px_OpenMixer(stream, 0); portMixer = Px_OpenMixer(stream, 0);
if (!portMixer) { if (!portMixer) {
maps->push_back(map); maps->push_back(map);
@ -145,12 +146,10 @@ static void AddSourcesFromStream(int deviceIndex, const PaDeviceInfo *info, std:
static void AddSources(int deviceIndex, int rate, wxArrayString *hosts, std::vector<DeviceSourceMap> *maps, int isInput) static void AddSources(int deviceIndex, int rate, wxArrayString *hosts, std::vector<DeviceSourceMap> *maps, int isInput)
{ {
int error; int error = 0;
DeviceSourceMap map; DeviceSourceMap map;
wxString hostDevName;
const PaDeviceInfo *info = Pa_GetDeviceInfo(deviceIndex); const PaDeviceInfo *info = Pa_GetDeviceInfo(deviceIndex);
hostDevName = DeviceName(info);
// This tries to open the device with the samplerate worked out above, which // This tries to open the device with the samplerate worked out above, which
// will be the highest available for play and record on the device, or // will be the highest available for play and record on the device, or
// 44.1kHz if the info cannot be fetched. // 44.1kHz if the info cannot be fetched.
@ -171,28 +170,34 @@ static void AddSources(int deviceIndex, int rate, wxArrayString *hosts, std::vec
// portaudio indecies) // portaudio indecies)
if (isInput) { if (isInput) {
if (info) if (info)
parameters.suggestedLatency = isInput ? info->defaultLowInputLatency: parameters.suggestedLatency = info->defaultLowInputLatency;
info->defaultLowOutputLatency;
else else
parameters.suggestedLatency = DEFAULT_LATENCY_CORRECTION/1000.0; parameters.suggestedLatency = DEFAULT_LATENCY_CORRECTION/1000.0;
// try opening for record and playback
error = Pa_OpenStream(&stream, error = Pa_OpenStream(&stream,
isInput ? &parameters : NULL, &parameters,
isInput ? NULL : &parameters, NULL,
rate, paFramesPerBufferUnspecified, rate, paFramesPerBufferUnspecified,
paClipOff | paDitherOff, paClipOff | paDitherOff,
DummyPaStreamCallback, NULL); DummyPaStreamCallback, NULL);
} }
if (stream) { if (stream && !error) {
AddSourcesFromStream(deviceIndex, info, maps, stream); AddSourcesFromStream(deviceIndex, info, maps, stream);
Pa_CloseStream(stream); Pa_CloseStream(stream);
} else { } else {
map.sourceIndex = -1; map.sourceIndex = -1;
map.totalSources = 0; map.totalSources = 0;
FillHostDeviceInfo(&map, info, deviceIndex); FillHostDeviceInfo(&map, info, deviceIndex, isInput);
maps->push_back(map); maps->push_back(map);
} }
if(error) {
wxLogDebug(wxT("PortAudio stream error creating device list: ") +
map.hostString + wxT(":") + map.deviceString + wxT(": ") +
wxString(Pa_GetErrorText( (PaError)error), wxConvLocal));
}
//add the host to the list if it isn't there yet //add the host to the list if it isn't there yet
wxString hostName(Pa_GetHostApiInfo(info->hostApi)->name, wxConvLocal); wxString hostName(Pa_GetHostApiInfo(info->hostApi)->name, wxConvLocal);
if (hosts->Index(hostName) == wxNOT_FOUND) { if (hosts->Index(hostName) == wxNOT_FOUND) {