20 #include "JackPortAudioDevices.h"
21 #include "JackError.h"
26 PortAudioDevices::PortAudioDevices()
30 jack_log(
"Initializing PortAudio...");
35 for (
id = 0;
id < fNumDevice;
id++) {
38 fHostName =
new string[fNumHostApi];
39 for (
id = 0;
id < fNumHostApi;
id++) {
47 PortAudioDevices::~PortAudioDevices()
63 return fDeviceInfo[id];
68 return string(fDeviceInfo[
id]->name);
71 string PortAudioDevices::GetHostFromDevice(
PaDeviceInfo* device)
73 return fHostName[device->hostApi];
78 return fHostName[fDeviceInfo[id]->hostApi];
83 string hostname = GetHostFromDevice(
id);
84 string devicename = GetDeviceName(
id);
86 if (hostname.compare(
"Windows DirectSound") == 0) {
87 hostname = string(
"DirectSound");
89 return (hostname +
"::" + devicename);
92 string PortAudioDevices::GetFullName(std::string hostname, std::string devicename)
95 if (hostname.compare(
"Windows DirectSound") == 0) {
96 hostname = string(
"DirectSound");
98 return (hostname +
"::" + devicename);
105 if (fullname.size() == 0) {
109 string::size_type separator = fullname.find (
"::", 0);
110 if (separator == 0) {
113 char* hostname = (
char*)malloc(separator + 9);
114 fill_n (hostname, separator + 9, 0);
115 fullname.copy (hostname, separator);
118 if (strcmp (hostname,
"DirectSound") == 0) {
119 strcpy (hostname,
"Windows DirectSound");
121 string devicename = fullname.substr (separator + 2);
123 for (
PaDeviceIndex dev_id = 0; dev_id < fNumDevice; dev_id++) {
124 bool flag = (isInput) ? (fDeviceInfo[dev_id]->maxInputChannels > 0) : (fDeviceInfo[dev_id]->maxOutputChannels > 0);
125 if ((GetHostFromDevice(dev_id).compare(hostname) == 0)
126 && (GetDeviceName(dev_id).compare(devicename) == 0)
129 ret = fDeviceInfo[dev_id];
138 static double standardSampleRates[] =
140 8000.0, 9600.0, 11025.0, 12000.0, 16000.0, 22050.0, 24000.0, 32000.0,
141 44100.0, 48000.0, 88200.0, 96000.0, 192000.0, -1
147 for (i = 0; standardSampleRates[i] > 0; i++) {
150 if (printCount == 0) {
151 jack_info(
"\t%8.2f", standardSampleRates[i]);
153 }
else if (printCount == 4) {
154 jack_info(
",\n\t%8.2f", standardSampleRates[i]);
157 jack_info(
", %8.2f", standardSampleRates[i]);
169 int PortAudioDevices::GetInputDeviceFromName(
const char* devicename,
PaDeviceIndex&
id,
int& max_input)
171 string fullname = string (devicename);
172 PaDeviceInfo* device = GetDeviceFromFullName (fullname,
id,
true);
174 max_input = device->maxInputChannels;
177 if (fullname.size()) {
178 jack_error(
"Can't open %s, PortAudio will use default input device.", devicename);
183 max_input = GetDeviceInfo(
id)->maxInputChannels;
188 int PortAudioDevices::GetOutputDeviceFromName(
const char* devicename,
PaDeviceIndex&
id,
int& max_output)
190 string fullname = string (devicename);
191 PaDeviceInfo* device = GetDeviceFromFullName (fullname,
id,
false);
193 max_output = device->maxOutputChannels;
196 if (fullname.size()) {
197 jack_error(
"Can't open %s, PortAudio will use default output device.", devicename);
202 max_output = GetDeviceInfo(
id)->maxOutputChannels;
207 void PortAudioDevices::DisplayDevicesNames()
211 jack_info (
"********************** Devices list, %d detected **********************", fNumDevice);
213 for (
id = 0;
id < fNumDevice;
id++) {
214 jack_info (
"-------- device #%d ------------------------------------------------",
id);
218 }
else if (
id ==
Pa_GetHostApiInfo (fDeviceInfo[
id]->hostApi)->defaultInputDevice) {
225 }
else if (
id ==
Pa_GetHostApiInfo (fDeviceInfo[
id]->hostApi)->defaultOutputDevice) {
231 jack_info (
"Name = %s", GetFullName (
id).c_str());
232 jack_info (
"Max inputs = %d", fDeviceInfo[
id]->maxInputChannels);
233 jack_info (
"Max outputs = %d", fDeviceInfo[
id]->maxOutputChannels);
238 long minLatency, maxLatency, preferredLatency, granularity;
242 jack_info (
"ASIO minimum buffer size = %ld", minLatency);
243 jack_info (
"ASIO maximum buffer size = %ld", maxLatency);
244 jack_info (
"ASIO preferred buffer size = %ld", preferredLatency);
246 if (granularity == -1) {
247 jack_info (
"ASIO buffer granularity = power of 2");
249 jack_info (
"ASIO buffer granularity = %ld", granularity);
254 jack_info (
"Default sample rate = %8.2f", fDeviceInfo[
id]->defaultSampleRate);
257 inputParameters.
device = id;
258 inputParameters.
channelCount = fDeviceInfo[id]->maxInputChannels;
263 outputParameters.
device = id;
264 outputParameters.
channelCount = fDeviceInfo[id]->maxOutputChannels;
269 jack_info(
"**************************** End of list ****************************");
275 if (fDeviceInfo[
id]->maxInputChannels && fDeviceInfo[
id]->maxOutputChannels) {
280 if ((i !=
id) && (GetDeviceName (i) == GetDeviceName (
id))) {
281 if ((fDeviceInfo[i]->maxInputChannels && fDeviceInfo[
id]->maxOutputChannels)
282 || (fDeviceInfo[i]->maxOutputChannels && fDeviceInfo[
id]->maxInputChannels)) {