@@ -68,7 +68,7 @@ static void* alsaThread(void* aParam)
6868 uint8_t * stream = (uint8_t *)data->buffer ;
6969 int len = data->samples * data->channels * sizeof (float );
7070
71- data->callback (data-> userdata , stream, len);
71+ data->callback (stream, len);
7272
7373 snd_pcm_sframes_t pcm = snd_pcm_writei (data->alsaDeviceHandle , data->buffer , data->samples );
7474 if (pcm != -EPIPE) {
@@ -107,7 +107,6 @@ static void alsaCleanup()
107107
108108AlsaAudioDriver::AlsaAudioDriver ()
109109{
110- m_deviceId = DEFAULT_DEVICE_ID;
111110}
112111
113112AlsaAudioDriver::~AlsaAudioDriver ()
@@ -131,18 +130,26 @@ std::string AlsaAudioDriver::name() const
131130 return " ALSA" ;
132131}
133132
133+ AudioDeviceID AlsaAudioDriver::defaultDevice () const
134+ {
135+ return DEFAULT_DEVICE_ID;
136+ }
137+
134138bool AlsaAudioDriver::open (const Spec& spec, Spec* activeSpec)
135139{
140+ IF_ASSERT_FAILED (!spec.deviceId .empty ()) {
141+ return false ;
142+ }
143+
136144 s_alsaData = new ALSAData ();
137145 s_alsaData->samples = spec.output .samplesPerChannel ;
138146 s_alsaData->channels = spec.output .audioChannelCount ;
139147 s_alsaData->callback = spec.callback ;
140- s_alsaData->userdata = spec.userdata ;
141148
142149 snd_pcm_t * handle;
143- int rc = snd_pcm_open (&handle, outputDevice () .c_str (), SND_PCM_STREAM_PLAYBACK, 0 );
150+ int rc = snd_pcm_open (&handle, spec. deviceId .c_str (), SND_PCM_STREAM_PLAYBACK, 0 );
144151 if (rc < 0 ) {
145- LOGE () << " Unable to open device: " << outputDevice () << " , err code: " << rc;
152+ LOGE () << " Unable to open device: " << spec. deviceId << " , err code: " << rc;
146153 return false ;
147154 }
148155
@@ -183,7 +190,6 @@ bool AlsaAudioDriver::open(const Spec& spec, Spec* activeSpec)
183190 // _alsaData->sampleBuffer = new short[_alsaData->samples * _alsaData->channels];
184191
185192 s_format = spec;
186- s_format.format = Format::AudioF32;
187193 s_format.output .sampleRate = aSamplerate;
188194 m_activeSpecChanged.send (s_format);
189195
@@ -199,7 +205,7 @@ bool AlsaAudioDriver::open(const Spec& spec, Spec* activeSpec)
199205 return false ;
200206 }
201207
202- LOGI () << " Connected to " << outputDevice ()
208+ LOGI () << " Connected to " << spec. deviceId
203209 << " with bufferSize " << s_format.output .samplesPerChannel
204210 << " , sampleRate " << s_format.output .sampleRate
205211 << " , channels: " << s_format.output .audioChannelCount ;
@@ -227,43 +233,6 @@ async::Channel<IAudioDriver::Spec> AlsaAudioDriver::activeSpecChanged() const
227233 return m_activeSpecChanged;
228234}
229235
230- AudioDeviceID AlsaAudioDriver::outputDevice () const
231- {
232- return m_deviceId;
233- }
234-
235- bool AlsaAudioDriver::selectOutputDevice (const AudioDeviceID& deviceId)
236- {
237- if (m_deviceId == deviceId) {
238- return true ;
239- }
240-
241- bool reopen = isOpened ();
242- close ();
243- m_deviceId = deviceId;
244-
245- bool ok = true ;
246- if (reopen) {
247- ok = open (s_format, &s_format);
248- }
249-
250- if (ok) {
251- m_outputDeviceChanged.notify ();
252- }
253-
254- return ok;
255- }
256-
257- bool AlsaAudioDriver::resetToDefaultOutputDevice ()
258- {
259- return selectOutputDevice (DEFAULT_DEVICE_ID);
260- }
261-
262- async::Notification AlsaAudioDriver::outputDeviceChanged () const
263- {
264- return m_outputDeviceChanged;
265- }
266-
267236AudioDeviceList AlsaAudioDriver::availableOutputDevices () const
268237{
269238 AudioDeviceList devices;
@@ -277,38 +246,11 @@ async::Notification AlsaAudioDriver::availableOutputDevicesChanged() const
277246 return m_availableOutputDevicesChanged;
278247}
279248
280- bool AlsaAudioDriver::setOutputDeviceBufferSize ( unsigned int bufferSize)
249+ std::vector< samples_t > AlsaAudioDriver::availableOutputDeviceBufferSizes () const
281250{
282- if (s_format.output .samplesPerChannel == bufferSize) {
283- return true ;
284- }
285-
286- bool reopen = isOpened ();
287- close ();
288- s_format.output .samplesPerChannel = bufferSize;
289-
290- bool ok = true ;
291- if (reopen) {
292- ok = open (s_format, &s_format);
293- }
251+ std::vector<samples_t > result;
294252
295- if (ok) {
296- m_bufferSizeChanged.notify ();
297- }
298-
299- return ok;
300- }
301-
302- async::Notification AlsaAudioDriver::outputDeviceBufferSizeChanged () const
303- {
304- return m_bufferSizeChanged;
305- }
306-
307- std::vector<unsigned int > AlsaAudioDriver::availableOutputDeviceBufferSizes () const
308- {
309- std::vector<unsigned int > result;
310-
311- unsigned int n = MAXIMUM_BUFFER_SIZE;
253+ samples_t n = MAXIMUM_BUFFER_SIZE;
312254 while (n >= MINIMUM_BUFFER_SIZE) {
313255 result.push_back (n);
314256 n /= 2 ;
@@ -319,34 +261,7 @@ std::vector<unsigned int> AlsaAudioDriver::availableOutputDeviceBufferSizes() co
319261 return result;
320262}
321263
322- bool AlsaAudioDriver::setOutputDeviceSampleRate (unsigned int sampleRate)
323- {
324- if (s_format.output .sampleRate == sampleRate) {
325- return true ;
326- }
327-
328- bool reopen = isOpened ();
329- close ();
330- s_format.output .sampleRate = sampleRate;
331-
332- bool ok = true ;
333- if (reopen) {
334- ok = open (s_format, &s_format);
335- }
336-
337- if (ok) {
338- m_sampleRateChanged.notify ();
339- }
340-
341- return ok;
342- }
343-
344- async::Notification AlsaAudioDriver::outputDeviceSampleRateChanged () const
345- {
346- return m_sampleRateChanged;
347- }
348-
349- std::vector<unsigned int > AlsaAudioDriver::availableOutputDeviceSampleRates () const
264+ std::vector<sample_rate_t > AlsaAudioDriver::availableOutputDeviceSampleRates () const
350265{
351266 // ALSA API is not of any help to get sample rates supported by the driver.
352267 // (snd_pcm_hw_params_get_rate_[min|max] will return 1 to 384000 Hz)
@@ -358,11 +273,3 @@ std::vector<unsigned int> AlsaAudioDriver::availableOutputDeviceSampleRates() co
358273 96000 ,
359274 };
360275}
361-
362- void AlsaAudioDriver::resume ()
363- {
364- }
365-
366- void AlsaAudioDriver::suspend ()
367- {
368- }
0 commit comments