19#include "pa_win_wasapi.h"
64 if (hostIndex < 0 || hostIndex >= Pa_GetHostApiCount()) {
68 const struct PaHostApiInfo *apiinfo = Pa_GetHostApiInfo(hostIndex);
71 int targetDevice = isInput ? apiinfo->defaultInputDevice : apiinfo->defaultOutputDevice;
73 for (i = 0; i < maps.size(); i++) {
74 if (maps[i].deviceIndex == targetDevice)
78 wxLogDebug(
wxT(
"GetDefaultDevice() no default device"));
96 const void *WXUNUSED(input),
void * WXUNUSED(output),
97 unsigned long WXUNUSED(frameCount),
98 const PaStreamCallbackTimeInfo* WXUNUSED(timeInfo),
100 void *WXUNUSED(userData) )
107 wxString hostapiName = wxSafeConvertMB2WX(Pa_GetHostApiInfo(info->hostApi)->name);
108 wxString infoName = wxSafeConvertMB2WX(info->name);
114 map->
numChannels = isInput ? info->maxInputChannels : info->maxOutputChannels;
130 PxMixer *portMixer = Px_OpenMixer(stream, deviceIndex, -1, 0);
132 maps->push_back(map);
146 maps->push_back(map);
153 map.
sourceString = wxString(wxSafeConvertMB2WX(Px_GetInputSourceName(portMixer, i)));
154 maps->push_back(map);
157 Px_CloseMixer(portMixer);
168 static int lastHostApiTypeId = -1;
169 int hostApiTypeId = Pa_GetHostApiInfo(info->hostApi)->type;
170 if(hostApiTypeId != lastHostApiTypeId &&
171 (hostApiTypeId == paMME || hostApiTypeId == paDirectSound)) {
172 lastHostApiTypeId = hostApiTypeId;
180static void AddSources(
int deviceIndex,
int rate, std::vector<DeviceSourceMap> *maps,
int isInput)
184 const PaDeviceInfo *info = Pa_GetDeviceInfo(deviceIndex);
192 PaStreamParameters parameters;
194 parameters.device = deviceIndex;
195 parameters.sampleFormat = paFloat32;
196 parameters.hostApiSpecificStreamInfo = NULL;
197 parameters.channelCount = 1;
207 parameters.suggestedLatency = info->defaultLowInputLatency;
209 parameters.suggestedLatency = 10.0;
211 error = Pa_OpenStream(&stream,
214 rate, paFramesPerBufferUnspecified,
215 paClipOff | paDitherOff,
219 if (stream && !error) {
221 Pa_CloseStream(stream);
226 maps->push_back(map);
230 wxLogDebug(
wxT(
"PortAudio stream error creating device list: ") +
232 wxString(wxSafeConvertMB2WX(Pa_GetErrorText((
PaError)error))));
250 if (gAudioIO->IsMonitoring())
252 using namespace std::chrono;
253 gAudioIO->StopStream();
254 while (gAudioIO->IsBusy())
255 std::this_thread::sleep_for(100ms);
266 int nDevices = Pa_GetDeviceCount();
271 for (
int i = 0; i < nDevices; i++) {
272 const PaDeviceInfo *info = Pa_GetDeviceInfo(i);
273 if (info->maxOutputChannels > 0) {
277 if (info->maxInputChannels > 0) {
292 auto now = std::chrono::steady_clock::now();
293 auto dur = std::chrono::duration_cast<std::chrono::duration<float>>(now -
mRescanTime);
300#if defined(EXPERIMENTAL_DEVICE_CHANGE_HANDLER)
301#if defined(HAVE_DEVICE_CHANGE)
302: DeviceChangeHandler()
307 mRescanTime = std::chrono::steady_clock::now();
319#if defined(EXPERIMENTAL_DEVICE_CHANGE_HANDLER)
320#if defined(HAVE_DEVICE_CHANGE)
321 DeviceChangeHandler::Enable(
true);
326#if defined(EXPERIMENTAL_DEVICE_CHANGE_HANDLER)
327#if defined(HAVE_DEVICE_CHANGE)
328void DeviceManager::DeviceChangeNotification()
unsigned long PaStreamCallbackFlags
static bool IsInputDeviceAMapperDevice(const PaDeviceInfo *info)
static void AddSourcesFromStream(int deviceIndex, const PaDeviceInfo *info, std::vector< DeviceSourceMap > *maps, PaStream *stream)
static void AddSources(int deviceIndex, int rate, std::vector< DeviceSourceMap > *maps, int isInput)
wxString MakeDeviceSourceString(const DeviceSourceMap *map)
static void FillHostDeviceInfo(DeviceSourceMap *map, const PaDeviceInfo *info, int deviceIndex, int isInput)
static int DummyPaStreamCallback(const void *WXUNUSED(input), void *WXUNUSED(output), unsigned long WXUNUSED(frameCount), const PaStreamCallbackTimeInfo *WXUNUSED(timeInfo), PaStreamCallbackFlags WXUNUSED(statusFlags), void *WXUNUSED(userData))
static AudioIOBase * Get()
A singleton that manages the audio devices known to Audacity.
DeviceSourceMap * GetDefaultInputDevice(int hostIndex)
const std::vector< DeviceSourceMap > & GetInputDeviceMaps()
const std::vector< DeviceSourceMap > & GetOutputDeviceMaps()
static DeviceManager * Instance()
Gets the singleton instance.
std::chrono::duration< float > GetTimeSinceRescan()
DeviceSourceMap * GetDefaultDevice(int hostIndex, int isInput)
std::chrono::time_point< std::chrono::steady_clock > mRescanTime
std::vector< DeviceSourceMap > mOutputDeviceSourceMaps
std::vector< DeviceSourceMap > mInputDeviceSourceMaps
DeviceSourceMap * GetDefaultOutputDevice(int hostIndex)
CallbackReturn Publish(const Message &message)
Send a message to connected callbacks.