37 |
REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceAlsa, ParameterFragments); |
REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceAlsa, ParameterFragments); |
38 |
REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceAlsa, ParameterFragmentSize); |
REGISTER_AUDIO_OUTPUT_DRIVER_PARAMETER(AudioOutputDeviceAlsa, ParameterFragmentSize); |
39 |
|
|
40 |
|
|
41 |
|
|
42 |
|
// *************** ParameterCard *************** |
43 |
|
// * |
44 |
|
|
45 |
|
AudioOutputDeviceAlsa::ParameterCard::ParameterCard() : DeviceCreationParameterString() { |
46 |
|
InitWithDefault(); // use default card |
47 |
|
} |
48 |
|
|
49 |
|
AudioOutputDeviceAlsa::ParameterCard::ParameterCard(String s) throw (LinuxSamplerException) : DeviceCreationParameterString(s) { |
50 |
|
SetValue(s); // try to use given card |
51 |
|
} |
52 |
|
|
53 |
|
String AudioOutputDeviceAlsa::ParameterCard::Description() { |
54 |
|
return "Sound card to be used"; |
55 |
|
} |
56 |
|
|
57 |
|
bool AudioOutputDeviceAlsa::ParameterCard::Fix() { |
58 |
|
return true; |
59 |
|
} |
60 |
|
|
61 |
|
bool AudioOutputDeviceAlsa::ParameterCard::Mandatory() { |
62 |
|
return false; |
63 |
|
} |
64 |
|
|
65 |
|
std::map<String,DeviceCreationParameter*> AudioOutputDeviceAlsa::ParameterCard::DependsAsParameters() { |
66 |
|
return std::map<String,DeviceCreationParameter*>(); // no dependencies |
67 |
|
} |
68 |
|
|
69 |
|
optional<String> AudioOutputDeviceAlsa::ParameterCard::DefaultAsString(std::map<String,String> Parameters) { |
70 |
|
std::vector<String> cards = PossibilitiesAsString(Parameters); |
71 |
|
if (cards.empty()) throw LinuxSamplerException("AudioOutputDeviceAlsa: Can't find any card"); |
72 |
|
return cards[0]; // first card by default |
73 |
|
} |
74 |
|
|
75 |
|
std::vector<String> AudioOutputDeviceAlsa::ParameterCard::PossibilitiesAsString(std::map<String,String> Parameters) { |
76 |
|
int err; |
77 |
|
std::vector<String> CardNames; |
78 |
|
|
79 |
|
// iterate through all cards |
80 |
|
int card_index = -1; |
81 |
|
while (snd_card_next(&card_index) >= 0 && card_index >= 0) { |
82 |
|
String hw_name = "hw:" + ToString(card_index); |
83 |
|
snd_ctl_t* hCardCtrl; |
84 |
|
if ((err = snd_ctl_open(&hCardCtrl, hw_name.c_str(), 0)) < 0) { |
85 |
|
std::cerr << "AudioOutputDeviceAlsa: Cannot open sound control for card " << card_index << " - " << snd_strerror(err) << std::endl; |
86 |
|
continue; |
87 |
|
} |
88 |
|
|
89 |
|
// iterate through all devices of that card |
90 |
|
int device_index = -1; |
91 |
|
while (!snd_ctl_pcm_next_device(hCardCtrl, &device_index) && device_index >= 0) { |
92 |
|
String name = ToString(card_index) + "," + ToString(device_index); |
93 |
|
//dmsg(1,("[possibility:%s]", name.c_str())); |
94 |
|
CardNames.push_back(name); |
95 |
|
} |
96 |
|
|
97 |
|
snd_ctl_close(hCardCtrl); |
98 |
|
} |
99 |
|
|
100 |
|
return CardNames; |
101 |
|
} |
102 |
|
|
103 |
|
void AudioOutputDeviceAlsa::ParameterCard::OnSetValue(String s) throw (LinuxSamplerException) { |
104 |
|
// not posssible, as parameter is fix |
105 |
|
} |
106 |
|
|
107 |
|
String AudioOutputDeviceAlsa::ParameterCard::Name() { |
108 |
|
return "card"; |
109 |
|
} |
110 |
|
|
111 |
|
|
112 |
|
|
113 |
|
// *************** ParameterFragments *************** |
114 |
|
// * |
115 |
|
|
116 |
|
AudioOutputDeviceAlsa::ParameterFragments::ParameterFragments() : DeviceCreationParameterInt() { |
117 |
|
InitWithDefault(); |
118 |
|
} |
119 |
|
|
120 |
|
AudioOutputDeviceAlsa::ParameterFragments::ParameterFragments(String s) throw (LinuxSamplerException) : DeviceCreationParameterInt(s) { |
121 |
|
} |
122 |
|
|
123 |
|
String AudioOutputDeviceAlsa::ParameterFragments::Description() { |
124 |
|
return "Number of buffer fragments"; |
125 |
|
} |
126 |
|
|
127 |
|
bool AudioOutputDeviceAlsa::ParameterFragments::Fix() { |
128 |
|
return true; |
129 |
|
} |
130 |
|
|
131 |
|
bool AudioOutputDeviceAlsa::ParameterFragments::Mandatory() { |
132 |
|
return false; |
133 |
|
} |
134 |
|
|
135 |
|
std::map<String,DeviceCreationParameter*> AudioOutputDeviceAlsa::ParameterFragments::DependsAsParameters() { |
136 |
|
static ParameterCard card; |
137 |
|
std::map<String,DeviceCreationParameter*> dependencies; |
138 |
|
dependencies[card.Name()] = &card; |
139 |
|
return dependencies; |
140 |
|
} |
141 |
|
|
142 |
|
optional<int> AudioOutputDeviceAlsa::ParameterFragments::DefaultAsInt(std::map<String,String> Parameters) { |
143 |
|
return 2; // until done |
144 |
|
} |
145 |
|
|
146 |
|
optional<int> AudioOutputDeviceAlsa::ParameterFragments::RangeMinAsInt(std::map<String,String> Parameters) { |
147 |
|
return optional<int>::nothing; |
148 |
|
} |
149 |
|
|
150 |
|
optional<int> AudioOutputDeviceAlsa::ParameterFragments::RangeMaxAsInt(std::map<String,String> Parameters) { |
151 |
|
return optional<int>::nothing; |
152 |
|
} |
153 |
|
|
154 |
|
std::vector<int> AudioOutputDeviceAlsa::ParameterFragments::PossibilitiesAsInt(std::map<String,String> Parameters) { |
155 |
|
return std::vector<int>(); |
156 |
|
} |
157 |
|
|
158 |
|
void AudioOutputDeviceAlsa::ParameterFragments::OnSetValue(int i) throw (LinuxSamplerException) { |
159 |
|
// not posssible, as parameter is fix |
160 |
|
} |
161 |
|
|
162 |
|
String AudioOutputDeviceAlsa::ParameterFragments::Name() { |
163 |
|
return "fragments"; |
164 |
|
} |
165 |
|
|
166 |
|
|
167 |
|
|
168 |
|
// *************** ParameterFragmentSize *************** |
169 |
|
// * |
170 |
|
|
171 |
|
AudioOutputDeviceAlsa::ParameterFragmentSize::ParameterFragmentSize() : DeviceCreationParameterInt() { |
172 |
|
InitWithDefault(); |
173 |
|
} |
174 |
|
|
175 |
|
AudioOutputDeviceAlsa::ParameterFragmentSize::ParameterFragmentSize(String s) throw (LinuxSamplerException) : DeviceCreationParameterInt(s) { |
176 |
|
} |
177 |
|
|
178 |
|
String AudioOutputDeviceAlsa::ParameterFragmentSize::Description() { |
179 |
|
return "Size of each buffer fragment"; |
180 |
|
} |
181 |
|
|
182 |
|
bool AudioOutputDeviceAlsa::ParameterFragmentSize::Fix() { |
183 |
|
return true; |
184 |
|
} |
185 |
|
|
186 |
|
bool AudioOutputDeviceAlsa::ParameterFragmentSize::Mandatory() { |
187 |
|
return false; |
188 |
|
} |
189 |
|
|
190 |
|
std::map<String,DeviceCreationParameter*> AudioOutputDeviceAlsa::ParameterFragmentSize::DependsAsParameters() { |
191 |
|
static ParameterCard card; |
192 |
|
std::map<String,DeviceCreationParameter*> dependencies; |
193 |
|
dependencies[card.Name()] = &card; |
194 |
|
return dependencies; |
195 |
|
} |
196 |
|
|
197 |
|
optional<int> AudioOutputDeviceAlsa::ParameterFragmentSize::DefaultAsInt(std::map<String,String> Parameters) { |
198 |
|
return 128; // until done |
199 |
|
} |
200 |
|
|
201 |
|
optional<int> AudioOutputDeviceAlsa::ParameterFragmentSize::RangeMinAsInt(std::map<String,String> Parameters) { |
202 |
|
return optional<int>::nothing; |
203 |
|
} |
204 |
|
|
205 |
|
optional<int> AudioOutputDeviceAlsa::ParameterFragmentSize::RangeMaxAsInt(std::map<String,String> Parameters) { |
206 |
|
return optional<int>::nothing; |
207 |
|
} |
208 |
|
|
209 |
|
std::vector<int> AudioOutputDeviceAlsa::ParameterFragmentSize::PossibilitiesAsInt(std::map<String,String> Parameters) { |
210 |
|
return std::vector<int>(); |
211 |
|
} |
212 |
|
|
213 |
|
void AudioOutputDeviceAlsa::ParameterFragmentSize::OnSetValue(int i) throw (LinuxSamplerException) { |
214 |
|
// not posssible, as parameter is fix |
215 |
|
} |
216 |
|
|
217 |
|
String AudioOutputDeviceAlsa::ParameterFragmentSize::Name() { |
218 |
|
return "fragmentsize"; |
219 |
|
} |
220 |
|
|
221 |
|
|
222 |
|
|
223 |
|
// *************** AudioOutputDeviceAlsa *************** |
224 |
|
// * |
225 |
|
|
226 |
/** |
/** |
227 |
* Create and initialize Alsa audio output device with given parameters. |
* Create and initialize Alsa audio output device with given parameters. |
228 |
* |
* |
459 |
} |
} |
460 |
|
|
461 |
String AudioOutputDeviceAlsa::Version() { |
String AudioOutputDeviceAlsa::Version() { |
462 |
String s = "$Revision: 1.10 $"; |
String s = "$Revision: 1.11 $"; |
463 |
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 |
464 |
} |
} |
465 |
|
|