105 |
} |
} |
106 |
|
|
107 |
String AudioOutputDeviceAlsa::ParameterCard::Name() { |
String AudioOutputDeviceAlsa::ParameterCard::Name() { |
108 |
return "card"; |
return "CARD"; |
109 |
} |
} |
110 |
|
|
111 |
|
|
144 |
} |
} |
145 |
|
|
146 |
optional<int> AudioOutputDeviceAlsa::ParameterFragments::RangeMinAsInt(std::map<String,String> Parameters) { |
optional<int> AudioOutputDeviceAlsa::ParameterFragments::RangeMinAsInt(std::map<String,String> Parameters) { |
147 |
return optional<int>::nothing; |
if (!Parameters.count("CARD")) return optional<int>::nothing; |
148 |
|
|
149 |
|
// obtain information from given sound card |
150 |
|
String pcm_name = "hw:" + Parameters["CARD"]; |
151 |
|
snd_pcm_t* pcm_handle = NULL; |
152 |
|
if (snd_pcm_open(&pcm_handle, pcm_name.c_str(), SND_PCM_STREAM_PLAYBACK, 0) < 0) return optional<int>::nothing; |
153 |
|
snd_pcm_hw_params_t* hwparams; |
154 |
|
snd_pcm_hw_params_alloca(&hwparams); |
155 |
|
if (snd_pcm_hw_params_any(pcm_handle, hwparams) < 0) { |
156 |
|
snd_pcm_close(pcm_handle); |
157 |
|
return optional<int>::nothing; |
158 |
|
} |
159 |
|
int dir = 0; |
160 |
|
uint periods_min; |
161 |
|
if (snd_pcm_hw_params_get_periods_min(hwparams, &periods_min, &dir) < 0) { |
162 |
|
snd_pcm_close(pcm_handle); |
163 |
|
return optional<int>::nothing; |
164 |
|
} |
165 |
|
snd_pcm_close(pcm_handle); |
166 |
|
return (int) periods_min; |
167 |
} |
} |
168 |
|
|
169 |
optional<int> AudioOutputDeviceAlsa::ParameterFragments::RangeMaxAsInt(std::map<String,String> Parameters) { |
optional<int> AudioOutputDeviceAlsa::ParameterFragments::RangeMaxAsInt(std::map<String,String> Parameters) { |
170 |
return optional<int>::nothing; |
if (!Parameters.count("CARD")) return optional<int>::nothing; |
171 |
|
|
172 |
|
// obtain information from given sound card |
173 |
|
String pcm_name = "hw:" + Parameters["CARD"]; |
174 |
|
snd_pcm_t* pcm_handle = NULL; |
175 |
|
if (snd_pcm_open(&pcm_handle, pcm_name.c_str(), SND_PCM_STREAM_PLAYBACK, 0) < 0) return optional<int>::nothing; |
176 |
|
snd_pcm_hw_params_t* hwparams; |
177 |
|
snd_pcm_hw_params_alloca(&hwparams); |
178 |
|
if (snd_pcm_hw_params_any(pcm_handle, hwparams) < 0) { |
179 |
|
snd_pcm_close(pcm_handle); |
180 |
|
return optional<int>::nothing; |
181 |
|
} |
182 |
|
int dir = 0; |
183 |
|
uint periods_max; |
184 |
|
if (snd_pcm_hw_params_get_periods_max(hwparams, &periods_max, &dir) < 0) { |
185 |
|
snd_pcm_close(pcm_handle); |
186 |
|
return optional<int>::nothing; |
187 |
|
} |
188 |
|
snd_pcm_close(pcm_handle); |
189 |
|
return (int) periods_max; |
190 |
} |
} |
191 |
|
|
192 |
std::vector<int> AudioOutputDeviceAlsa::ParameterFragments::PossibilitiesAsInt(std::map<String,String> Parameters) { |
std::vector<int> AudioOutputDeviceAlsa::ParameterFragments::PossibilitiesAsInt(std::map<String,String> Parameters) { |
198 |
} |
} |
199 |
|
|
200 |
String AudioOutputDeviceAlsa::ParameterFragments::Name() { |
String AudioOutputDeviceAlsa::ParameterFragments::Name() { |
201 |
return "fragments"; |
return "FRAGMENTS"; |
202 |
} |
} |
203 |
|
|
204 |
|
|
237 |
} |
} |
238 |
|
|
239 |
optional<int> AudioOutputDeviceAlsa::ParameterFragmentSize::RangeMinAsInt(std::map<String,String> Parameters) { |
optional<int> AudioOutputDeviceAlsa::ParameterFragmentSize::RangeMinAsInt(std::map<String,String> Parameters) { |
240 |
return optional<int>::nothing; |
if (!Parameters.count("CARD")) return optional<int>::nothing; |
241 |
|
|
242 |
|
// obtain information from given sound card |
243 |
|
String pcm_name = "hw:" + Parameters["CARD"]; |
244 |
|
snd_pcm_t* pcm_handle = NULL; |
245 |
|
if (snd_pcm_open(&pcm_handle, pcm_name.c_str(), SND_PCM_STREAM_PLAYBACK, 0) < 0) return optional<int>::nothing; |
246 |
|
snd_pcm_hw_params_t* hwparams; |
247 |
|
snd_pcm_hw_params_alloca(&hwparams); |
248 |
|
if (snd_pcm_hw_params_any(pcm_handle, hwparams) < 0) { |
249 |
|
snd_pcm_close(pcm_handle); |
250 |
|
return optional<int>::nothing; |
251 |
|
} |
252 |
|
int dir = 0; |
253 |
|
unsigned long period_size_min; |
254 |
|
if (snd_pcm_hw_params_get_period_size_min(hwparams, &period_size_min, &dir) < 0) { |
255 |
|
snd_pcm_close(pcm_handle); |
256 |
|
return optional<int>::nothing; |
257 |
|
} |
258 |
|
snd_pcm_close(pcm_handle); |
259 |
|
return (int) period_size_min; |
260 |
} |
} |
261 |
|
|
262 |
optional<int> AudioOutputDeviceAlsa::ParameterFragmentSize::RangeMaxAsInt(std::map<String,String> Parameters) { |
optional<int> AudioOutputDeviceAlsa::ParameterFragmentSize::RangeMaxAsInt(std::map<String,String> Parameters) { |
263 |
return optional<int>::nothing; |
if (!Parameters.count("CARD")) return optional<int>::nothing; |
264 |
|
|
265 |
|
// obtain information from given sound card |
266 |
|
String pcm_name = "hw:" + Parameters["CARD"]; |
267 |
|
snd_pcm_t* pcm_handle = NULL; |
268 |
|
if (snd_pcm_open(&pcm_handle, pcm_name.c_str(), SND_PCM_STREAM_PLAYBACK, 0) < 0) return optional<int>::nothing; |
269 |
|
snd_pcm_hw_params_t* hwparams; |
270 |
|
snd_pcm_hw_params_alloca(&hwparams); |
271 |
|
if (snd_pcm_hw_params_any(pcm_handle, hwparams) < 0) { |
272 |
|
snd_pcm_close(pcm_handle); |
273 |
|
return optional<int>::nothing; |
274 |
|
} |
275 |
|
int dir = 0; |
276 |
|
unsigned long period_size_max; |
277 |
|
if (snd_pcm_hw_params_get_period_size_max(hwparams, &period_size_max, &dir) < 0) { |
278 |
|
snd_pcm_close(pcm_handle); |
279 |
|
return optional<int>::nothing; |
280 |
|
} |
281 |
|
snd_pcm_close(pcm_handle); |
282 |
|
return (int) period_size_max; //FIXME: might overflow int limit |
283 |
} |
} |
284 |
|
|
285 |
std::vector<int> AudioOutputDeviceAlsa::ParameterFragmentSize::PossibilitiesAsInt(std::map<String,String> Parameters) { |
std::vector<int> AudioOutputDeviceAlsa::ParameterFragmentSize::PossibilitiesAsInt(std::map<String,String> Parameters) { |
291 |
} |
} |
292 |
|
|
293 |
String AudioOutputDeviceAlsa::ParameterFragmentSize::Name() { |
String AudioOutputDeviceAlsa::ParameterFragmentSize::Name() { |
294 |
return "fragmentsize"; |
return "FRAGMENTSIZE"; |
295 |
} |
} |
296 |
|
|
297 |
|
|
308 |
AudioOutputDeviceAlsa::AudioOutputDeviceAlsa(std::map<String,DeviceCreationParameter*> Parameters) : AudioOutputDevice(Parameters), Thread(true, 1, 0) { |
AudioOutputDeviceAlsa::AudioOutputDeviceAlsa(std::map<String,DeviceCreationParameter*> Parameters) : AudioOutputDevice(Parameters), Thread(true, 1, 0) { |
309 |
pcm_handle = NULL; |
pcm_handle = NULL; |
310 |
stream = SND_PCM_STREAM_PLAYBACK; |
stream = SND_PCM_STREAM_PLAYBACK; |
311 |
this->uiAlsaChannels = ((DeviceCreationParameterInt*)Parameters["channels"])->ValueAsInt(); |
this->uiAlsaChannels = ((DeviceCreationParameterInt*)Parameters["CHANNELS"])->ValueAsInt(); |
312 |
this->uiSamplerate = ((DeviceCreationParameterInt*)Parameters["samplerate"])->ValueAsInt(); |
this->uiSamplerate = ((DeviceCreationParameterInt*)Parameters["SAMPLERATE"])->ValueAsInt(); |
313 |
this->FragmentSize = ((DeviceCreationParameterInt*)Parameters["fragmentsize"])->ValueAsInt(); |
this->FragmentSize = ((DeviceCreationParameterInt*)Parameters["FRAGMENTSIZE"])->ValueAsInt(); |
314 |
uint Fragments = ((DeviceCreationParameterInt*)Parameters["fragments"])->ValueAsInt(); |
uint Fragments = ((DeviceCreationParameterInt*)Parameters["FRAGMENTS"])->ValueAsInt(); |
315 |
String Card = Parameters["card"]->Value(); |
String Card = ((DeviceCreationParameterString*)Parameters["CARD"])->ValueAsString(); |
316 |
|
|
317 |
dmsg(1,("Checking if hw parameters supported...\n")); |
dmsg(1,("Checking if hw parameters supported...\n")); |
318 |
if (HardwareParametersSupported(Card, uiAlsaChannels, uiSamplerate, Fragments, FragmentSize)) { |
if (HardwareParametersSupported(Card, uiAlsaChannels, uiSamplerate, Fragments, FragmentSize)) { |
420 |
pAlsaOutputBuffer = new int16_t[uiAlsaChannels * FragmentSize]; |
pAlsaOutputBuffer = new int16_t[uiAlsaChannels * FragmentSize]; |
421 |
|
|
422 |
// create audio channels for this audio device to which the sampler engines can write to |
// create audio channels for this audio device to which the sampler engines can write to |
423 |
for (int i = 0; i < uiAlsaChannels; i++) this->Channels.push_back(new AudioChannel(FragmentSize)); |
for (int i = 0; i < uiAlsaChannels; i++) this->Channels.push_back(new AudioChannel(i, FragmentSize)); |
424 |
|
|
425 |
if (((DeviceCreationParameterBool*)Parameters["active"])->ValueAsBool()) { |
if (((DeviceCreationParameterBool*)Parameters["ACTIVE"])->ValueAsBool()) { |
426 |
Play(); |
Play(); |
427 |
} |
} |
428 |
} |
} |
435 |
//FIXME: currently commented out due to segfault |
//FIXME: currently commented out due to segfault |
436 |
//snd_pcm_close(pcm_handle); |
//snd_pcm_close(pcm_handle); |
437 |
|
|
|
// destroy all audio channels |
|
|
for (int c = 0; c < Channels.size(); c++) delete Channels[c]; |
|
|
|
|
438 |
if (pAlsaOutputBuffer) { |
if (pAlsaOutputBuffer) { |
439 |
//FIXME: currently commented out due to segfault |
//FIXME: currently commented out due to segfault |
440 |
//delete[] pOutputBuffer; |
//delete[] pOutputBuffer; |
501 |
StopThread(); |
StopThread(); |
502 |
} |
} |
503 |
|
|
504 |
void AudioOutputDeviceAlsa::AcquireChannels(uint Channels) { |
AudioChannel* AudioOutputDeviceAlsa::CreateChannel(uint ChannelNr) { |
505 |
if (Channels > uiAlsaChannels) { |
// just create a mix channel |
506 |
// just create mix channel(s) |
return new AudioChannel(ChannelNr, Channel(ChannelNr % uiAlsaChannels)); |
|
for (int i = uiAlsaChannels; i < Channels; i++) { |
|
|
AudioChannel* pNewChannel = new AudioChannel(this->Channels[i % uiAlsaChannels]); |
|
|
this->Channels.push_back(pNewChannel); |
|
|
} |
|
|
} |
|
507 |
} |
} |
508 |
|
|
509 |
uint AudioOutputDeviceAlsa::MaxSamplesPerCycle() { |
uint AudioOutputDeviceAlsa::MaxSamplesPerCycle() { |
515 |
} |
} |
516 |
|
|
517 |
String AudioOutputDeviceAlsa::Name() { |
String AudioOutputDeviceAlsa::Name() { |
518 |
return "Alsa"; |
return "ALSA"; |
519 |
} |
} |
520 |
|
|
521 |
String AudioOutputDeviceAlsa::Driver() { |
String AudioOutputDeviceAlsa::Driver() { |
527 |
} |
} |
528 |
|
|
529 |
String AudioOutputDeviceAlsa::Version() { |
String AudioOutputDeviceAlsa::Version() { |
530 |
String s = "$Revision: 1.11 $"; |
String s = "$Revision: 1.14 $"; |
531 |
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 |
532 |
} |
} |
533 |
|
|
578 |
} |
} |
579 |
|
|
580 |
} // namespace LinuxSampler |
} // namespace LinuxSampler |
|
|
|