20 |
* MA 02111-1307 USA * |
* MA 02111-1307 USA * |
21 |
***************************************************************************/ |
***************************************************************************/ |
22 |
|
|
23 |
|
#include "../drivers/InputOutputDevice.h" |
24 |
#include "AudioOutputDeviceAlsa.h" |
#include "AudioOutputDeviceAlsa.h" |
25 |
#include "AudioOutputDeviceFactory.h" |
#include "AudioOutputDeviceFactory.h" |
26 |
|
|
27 |
namespace LinuxSampler { |
namespace LinuxSampler { |
28 |
|
|
29 |
REGISTER_AUDIO_OUTPUT_DRIVER("Alsa",AudioOutputDeviceAlsa); |
REGISTER_AUDIO_OUTPUT_DRIVER(AudioOutputDeviceAlsa); |
30 |
|
|
31 |
|
/* Common parameters for now they'll have to be registered here. */ |
32 |
|
REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceAlsa, ParameterActive); |
33 |
|
REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceAlsa, ParameterSampleRate); |
34 |
|
REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceAlsa, ParameterChannels); |
35 |
|
|
36 |
|
/* Driver specific parameters */ |
37 |
|
REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceAlsa, ParameterCard); |
38 |
|
REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceAlsa, ParameterFragments); |
39 |
|
REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceAlsa, ParameterFragmentSize); |
40 |
|
|
41 |
/** |
/** |
42 |
* Create and initialize Alsa audio output device with given parameters. |
* Create and initialize Alsa audio output device with given parameters. |
44 |
* @param Parameters - optional parameters |
* @param Parameters - optional parameters |
45 |
* @throws AudioOutputException if output device cannot be opened |
* @throws AudioOutputException if output device cannot be opened |
46 |
*/ |
*/ |
47 |
AudioOutputDeviceAlsa::AudioOutputDeviceAlsa(std::map<String,String> Parameters) : AudioOutputDevice(CreateParameters(Parameters)), Thread(true, 1, 0) { |
AudioOutputDeviceAlsa::AudioOutputDeviceAlsa(std::map<String,DeviceCreationParameter*> Parameters) : AudioOutputDevice(Parameters), Thread(true, 1, 0) { |
48 |
pcm_handle = NULL; |
pcm_handle = NULL; |
49 |
stream = SND_PCM_STREAM_PLAYBACK; |
stream = SND_PCM_STREAM_PLAYBACK; |
50 |
this->uiAlsaChannels = ((DeviceCreationParameterInt*)this->Parameters["channels"])->ValueAsInt(); |
this->uiAlsaChannels = ((DeviceCreationParameterInt*)Parameters["channels"])->ValueAsInt(); |
51 |
this->uiSamplerate = ((DeviceCreationParameterInt*)this->Parameters["samplerate"])->ValueAsInt(); |
this->uiSamplerate = ((DeviceCreationParameterInt*)Parameters["samplerate"])->ValueAsInt(); |
52 |
this->FragmentSize = ((DeviceCreationParameterInt*)this->Parameters["fragmentsize"])->ValueAsInt(); |
this->FragmentSize = ((DeviceCreationParameterInt*)Parameters["fragmentsize"])->ValueAsInt(); |
53 |
uint Fragments = ((DeviceCreationParameterInt*)this->Parameters["fragments"])->ValueAsInt(); |
uint Fragments = ((DeviceCreationParameterInt*)Parameters["fragments"])->ValueAsInt(); |
54 |
String Card = this->Parameters["card"]->Value(); |
String Card = Parameters["card"]->Value(); |
55 |
|
|
56 |
dmsg(1,("Checking if hw parameters supported...\n")); |
dmsg(1,("Checking if hw parameters supported...\n")); |
57 |
if (HardwareParametersSupported(Card, uiAlsaChannels, uiSamplerate, Fragments, FragmentSize)) { |
if (HardwareParametersSupported(Card, uiAlsaChannels, uiSamplerate, Fragments, FragmentSize)) { |
160 |
|
|
161 |
// 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 |
162 |
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(FragmentSize)); |
163 |
|
|
164 |
|
if (((DeviceCreationParameterBool*)Parameters["active"])->ValueAsBool()) { |
165 |
|
Play(); |
166 |
|
} |
167 |
} |
} |
168 |
|
|
169 |
AudioOutputDeviceAlsa::~AudioOutputDeviceAlsa() { |
AudioOutputDeviceAlsa::~AudioOutputDeviceAlsa() { |
183 |
} |
} |
184 |
} |
} |
185 |
|
|
|
std::map<String,DeviceCreationParameter*> AudioOutputDeviceAlsa::CreateParameters(std::map<String,String> Parameters) { |
|
|
std::map<String,DeviceCreationParameter*> result; |
|
|
//FIXME: common stuff still has to be created somewhere. |
|
|
// AND filled with values, but we are only passing result |
|
|
// of this method to base, so common stuff will be part |
|
|
// of this result for now. |
|
|
result["channels"] = OptionalParameter<ParameterChannels>::New(this, Parameters["channels"]); |
|
|
result["samplerate"] = OptionalParameter<ParameterSampleRate>::New(this, Parameters["samplerate"]); |
|
|
result["active"] = OptionalParameter<ParameterActive>::New(this, Parameters["active"]); |
|
|
|
|
|
//Alsa specific |
|
|
result["card"] = OptionalParameter<ParameterCard>::New(this, Parameters["card"]); // additional parameter, individually for this driver |
|
|
result["fragments"] = OptionalParameter<ParameterFragments>::New(this, Parameters["fragments"]); // additional parameter, individually for this driver |
|
|
result["fragmentsize"] = OptionalParameter<ParameterFragmentSize>::New(this, Parameters["fragmentsize"]); // additional parameter, individually for this driver |
|
|
return result; |
|
|
} |
|
|
|
|
186 |
/** |
/** |
187 |
* Checks if sound card supports the chosen parameters. |
* Checks if sound card supports the chosen parameters. |
188 |
* |
* |
261 |
return uiSamplerate; |
return uiSamplerate; |
262 |
} |
} |
263 |
|
|
264 |
String AudioOutputDeviceAlsa::Driver() { |
String AudioOutputDeviceAlsa::Name() { |
265 |
return "Alsa"; |
return "Alsa"; |
266 |
} |
} |
267 |
|
|
268 |
|
String AudioOutputDeviceAlsa::Driver() { |
269 |
|
return Name(); |
270 |
|
} |
271 |
|
|
272 |
String AudioOutputDeviceAlsa::Description() { |
String AudioOutputDeviceAlsa::Description() { |
273 |
return "Advanced Linux Sound Architecture"; |
return "Advanced Linux Sound Architecture"; |
274 |
} |
} |
275 |
|
|
276 |
String AudioOutputDeviceAlsa::Version() { |
String AudioOutputDeviceAlsa::Version() { |
277 |
String s = "$Revision: 1.7 $"; |
String s = "$Revision: 1.8 $"; |
278 |
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 |
279 |
} |
} |
280 |
|
|
|
std::map<String,DeviceCreationParameter*> AudioOutputDeviceAlsa::AvailableParameters() { |
|
|
// FIXME: not a good solution to get the commot parameters (ACTIVE,SAMPERATE,CHANNELS which have to be offered by all audio output drivers) |
|
|
std::map<String,DeviceCreationParameter*> available_parameters = AudioOutputDevice::AvailableParameters(); |
|
|
static ParameterCard param_card(NULL); |
|
|
static ParameterFragments param_fragments(NULL); |
|
|
static ParameterFragmentSize param_fragmentsize(NULL); |
|
|
available_parameters["card"] = ¶m_card; // additional parameter, individually for this driver |
|
|
available_parameters["fragments"] = ¶m_fragments; // additional parameter, individually for this driver |
|
|
available_parameters["fragmentsize"] = ¶m_fragmentsize; // additional parameter, individually for this driver |
|
|
return available_parameters; |
|
|
} |
|
|
|
|
281 |
/** |
/** |
282 |
* Entry point for the thread. |
* Entry point for the thread. |
283 |
*/ |
*/ |