3 |
* LinuxSampler - modular, streaming capable sampler * |
* LinuxSampler - modular, streaming capable sampler * |
4 |
* * |
* * |
5 |
* Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck * |
* Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck * |
6 |
|
* Copyright (C) 2005 Christian Schoenebeck * |
7 |
* * |
* * |
8 |
* This program is free software; you can redistribute it and/or modify * |
* This program is free software; you can redistribute it and/or modify * |
9 |
* it under the terms of the GNU General Public License as published by * |
* it under the terms of the GNU General Public License as published by * |
135 |
// obtain information from given sound card |
// obtain information from given sound card |
136 |
String pcm_name = "hw:" + Parameters["CARD"]; |
String pcm_name = "hw:" + Parameters["CARD"]; |
137 |
snd_pcm_t* pcm_handle = NULL; |
snd_pcm_t* pcm_handle = NULL; |
138 |
if (snd_pcm_open(&pcm_handle, pcm_name.c_str(), SND_PCM_STREAM_PLAYBACK, 0) < 0) return optional<int>::nothing; |
if (snd_pcm_open(&pcm_handle, pcm_name.c_str(), SND_PCM_STREAM_PLAYBACK, SND_PCM_NONBLOCK) < 0) return optional<int>::nothing; |
139 |
snd_pcm_hw_params_t* hwparams; |
snd_pcm_hw_params_t* hwparams; |
140 |
snd_pcm_hw_params_alloca(&hwparams); |
snd_pcm_hw_params_alloca(&hwparams); |
141 |
if (snd_pcm_hw_params_any(pcm_handle, hwparams) < 0) { |
if (snd_pcm_hw_params_any(pcm_handle, hwparams) < 0) { |
158 |
// obtain information from given sound card |
// obtain information from given sound card |
159 |
String pcm_name = "hw:" + Parameters["CARD"]; |
String pcm_name = "hw:" + Parameters["CARD"]; |
160 |
snd_pcm_t* pcm_handle = NULL; |
snd_pcm_t* pcm_handle = NULL; |
161 |
if (snd_pcm_open(&pcm_handle, pcm_name.c_str(), SND_PCM_STREAM_PLAYBACK, 0) < 0) return optional<int>::nothing; |
if (snd_pcm_open(&pcm_handle, pcm_name.c_str(), SND_PCM_STREAM_PLAYBACK, SND_PCM_NONBLOCK) < 0) return optional<int>::nothing; |
162 |
snd_pcm_hw_params_t* hwparams; |
snd_pcm_hw_params_t* hwparams; |
163 |
snd_pcm_hw_params_alloca(&hwparams); |
snd_pcm_hw_params_alloca(&hwparams); |
164 |
if (snd_pcm_hw_params_any(pcm_handle, hwparams) < 0) { |
if (snd_pcm_hw_params_any(pcm_handle, hwparams) < 0) { |
228 |
// obtain information from given sound card |
// obtain information from given sound card |
229 |
String pcm_name = "hw:" + Parameters["CARD"]; |
String pcm_name = "hw:" + Parameters["CARD"]; |
230 |
snd_pcm_t* pcm_handle = NULL; |
snd_pcm_t* pcm_handle = NULL; |
231 |
if (snd_pcm_open(&pcm_handle, pcm_name.c_str(), SND_PCM_STREAM_PLAYBACK, 0) < 0) return optional<int>::nothing; |
if (snd_pcm_open(&pcm_handle, pcm_name.c_str(), SND_PCM_STREAM_PLAYBACK, SND_PCM_NONBLOCK) < 0) return optional<int>::nothing; |
232 |
snd_pcm_hw_params_t* hwparams; |
snd_pcm_hw_params_t* hwparams; |
233 |
snd_pcm_hw_params_alloca(&hwparams); |
snd_pcm_hw_params_alloca(&hwparams); |
234 |
if (snd_pcm_hw_params_any(pcm_handle, hwparams) < 0) { |
if (snd_pcm_hw_params_any(pcm_handle, hwparams) < 0) { |
251 |
// obtain information from given sound card |
// obtain information from given sound card |
252 |
String pcm_name = "hw:" + Parameters["CARD"]; |
String pcm_name = "hw:" + Parameters["CARD"]; |
253 |
snd_pcm_t* pcm_handle = NULL; |
snd_pcm_t* pcm_handle = NULL; |
254 |
if (snd_pcm_open(&pcm_handle, pcm_name.c_str(), SND_PCM_STREAM_PLAYBACK, 0) < 0) return optional<int>::nothing; |
if (snd_pcm_open(&pcm_handle, pcm_name.c_str(), SND_PCM_STREAM_PLAYBACK, SND_PCM_NONBLOCK) < 0) return optional<int>::nothing; |
255 |
snd_pcm_hw_params_t* hwparams; |
snd_pcm_hw_params_t* hwparams; |
256 |
snd_pcm_hw_params_alloca(&hwparams); |
snd_pcm_hw_params_alloca(&hwparams); |
257 |
if (snd_pcm_hw_params_any(pcm_handle, hwparams) < 0) { |
if (snd_pcm_hw_params_any(pcm_handle, hwparams) < 0) { |
300 |
uint Fragments = ((DeviceCreationParameterInt*)Parameters["FRAGMENTS"])->ValueAsInt(); |
uint Fragments = ((DeviceCreationParameterInt*)Parameters["FRAGMENTS"])->ValueAsInt(); |
301 |
String Card = ((DeviceCreationParameterString*)Parameters["CARD"])->ValueAsString(); |
String Card = ((DeviceCreationParameterString*)Parameters["CARD"])->ValueAsString(); |
302 |
|
|
303 |
dmsg(1,("Checking if hw parameters supported...\n")); |
dmsg(2,("Checking if hw parameters supported...\n")); |
304 |
if (HardwareParametersSupported(Card, uiAlsaChannels, uiSamplerate, Fragments, FragmentSize)) { |
if (HardwareParametersSupported(Card, uiAlsaChannels, uiSamplerate, Fragments, FragmentSize)) { |
305 |
pcm_name = "hw:" + Card; |
pcm_name = "hw:" + Card; |
306 |
} |
} |
307 |
else { |
else { |
308 |
printf("Warning: your soundcard doesn't support chosen hardware parameters; "); |
fprintf(stderr, "Warning: your soundcard doesn't support chosen hardware parameters; "); |
309 |
printf("trying to compensate support lack with plughw..."); |
fprintf(stderr, "trying to compensate support lack with plughw..."); |
310 |
fflush(stdout); |
fflush(stdout); |
311 |
pcm_name = "plughw:" + Card; |
pcm_name = "plughw:" + Card; |
312 |
} |
} |
313 |
dmsg(1,("HW check completed.\n")); |
dmsg(2,("HW check completed.\n")); |
314 |
|
|
315 |
int err; |
int err; |
316 |
|
|
431 |
* Checks if sound card supports the chosen parameters. |
* Checks if sound card supports the chosen parameters. |
432 |
* |
* |
433 |
* @returns true if hardware supports it |
* @returns true if hardware supports it |
434 |
|
* @throws AudioOutputException - if device cannot be accessed |
435 |
*/ |
*/ |
436 |
bool AudioOutputDeviceAlsa::HardwareParametersSupported(String card, uint channels, int samplerate, uint numfragments, uint fragmentsize) { |
bool AudioOutputDeviceAlsa::HardwareParametersSupported(String card, uint channels, int samplerate, uint numfragments, uint fragmentsize) throw (AudioOutputException) { |
437 |
pcm_name = "hw:" + card; |
pcm_name = "hw:" + card; |
438 |
if (snd_pcm_open(&pcm_handle, pcm_name.c_str(), stream, 0) < 0) return false; |
int err; |
439 |
|
if ((err = snd_pcm_open(&pcm_handle, pcm_name.c_str(), stream, SND_PCM_NONBLOCK)) < 0) { |
440 |
|
throw AudioOutputException(String("Error opening PCM device ") + pcm_name + ": " + snd_strerror(err)); |
441 |
|
} |
442 |
snd_pcm_hw_params_alloca(&hwparams); |
snd_pcm_hw_params_alloca(&hwparams); |
443 |
if (snd_pcm_hw_params_any(pcm_handle, hwparams) < 0) { |
if (snd_pcm_hw_params_any(pcm_handle, hwparams) < 0) { |
444 |
snd_pcm_close(pcm_handle); |
snd_pcm_close(pcm_handle); |
517 |
} |
} |
518 |
|
|
519 |
String AudioOutputDeviceAlsa::Version() { |
String AudioOutputDeviceAlsa::Version() { |
520 |
String s = "$Revision: 1.17 $"; |
String s = "$Revision: 1.20 $"; |
521 |
return s.substr(11, s.size() - 13); // cut dollar signs, spaces and CVS macro keyword |
return s.substr(11, s.size() - 13); // cut dollar signs, spaces and CVS macro keyword |
522 |
} |
} |
523 |
|
|