updated on Mon Jan 16 20:00:43 UTC 2012
[aur-mirror.git] / sidplay2-alsa / sidplay2-2.0.9-alsa.patch
blob11da9f8f37206266fc013effebd8919460579cb8
1 diff -Naur sidplay-2.0.9.ORIG/configure.ac sidplay-2.0.9/configure.ac
2 --- sidplay-2.0.9.ORIG/configure.ac 2004-05-06 06:13:58.000000000 +1000
3 +++ sidplay-2.0.9/configure.ac 2011-03-18 14:33:10.000000000 +1100
4 @@ -37,10 +37,17 @@
5 #undef HAVE_WAV_ONLY
6 ])
8 +AC_CHECK_HEADER(alsa/asoundlib.h, [OK_ASOUNDLIB_H=1])
9 +AC_CHECK_LIB(asound, main, [OK_LIBASOUND=1])
11 +# use ALSA is available
12 +audio="$host"
13 +test "$OK_ASOUNDLIB_H" -a "$OK_LIBASOUND" && audio="alsa"
15 dnl Audio Subsystem Test
16 AC_MSG_CHECKING([which audio subsystem is available])
17 audiodrv_libadd=""
18 -case "$host" in
19 +case "$audio" in
20 *cygwin*) AC_DEFINE(HAVE_MMSYSTEM)
21 audiodrv_libadd="./audio/mmsystem/libmmsystem.a"
22 AC_MSG_RESULT(mmsystem)
23 @@ -67,12 +74,12 @@
24 *netbsd*) AC_DEFINE(HAVE_OSS)
25 audiodrv_libadd="./audio/oss/liboss.a"
26 AC_MSG_RESULT(oss)
27 - AC_CHECK_LIB(ossaudio, main, [AUDIO_LDADD=-lossaudio AC_SUBST(AUDIO_LDFLAGS)])
28 + AC_CHECK_LIB(ossaudio, main, [AUDIO_LDFLAGS=-lossaudio AC_SUBST(AUDIO_LDFLAGS)])
30 - *qnx*) AC_DEFINE(HAVE_ALSA)
31 + *qnx*|alsa) AC_DEFINE(HAVE_ALSA)
32 audiodrv_libadd="./audio/alsa/libalsa.a"
33 AC_MSG_RESULT(alsa)
34 - AC_CHECK_LIB(asound, main, [AUDIO_LDADD=-lasound AC_SUBST(AUDIO_LDFLAGS)])
35 + AC_CHECK_LIB(asound, main, [AUDIO_LDFLAGS=-lasound AC_SUBST(AUDIO_LDFLAGS)])
37 *sgi*) AC_DEFINE(HAVE_SGI)
38 AC_MSG_RESULT(sgi)
39 diff -Naur sidplay-2.0.9.ORIG/src/Makefile.am sidplay-2.0.9/src/Makefile.am
40 --- sidplay-2.0.9.ORIG/src/Makefile.am 2003-07-08 05:58:53.000000000 +1000
41 +++ sidplay-2.0.9/src/Makefile.am 2011-03-18 14:14:43.000000000 +1100
42 @@ -10,7 +10,7 @@
43 player.cpp player.h
45 sidplay2_LDADD = ./audio/null/libnull.a ./audio/wav/libwav.a \
46 -$(AUDIO_DRV) $(AUDIO_LDFLAGS) \
47 +$(AUDIO_DRV) $(AUDIO_LDFLAGS) $(AUDIO_LDADD) \
48 $(LIBSIDPLAY2_LDFLAGS) $(LIBSIDUTILS_LDFLAGS) \
49 $(BUILDERS_LDFLAGS)
51 diff -Naur sidplay-2.0.9.ORIG/src/audio/alsa/audiodrv.cpp sidplay-2.0.9/src/audio/alsa/audiodrv.cpp
52 --- sidplay-2.0.9.ORIG/src/audio/alsa/audiodrv.cpp 2002-03-05 06:07:48.000000000 +1100
53 +++ sidplay-2.0.9/src/audio/alsa/audiodrv.cpp 2011-03-18 14:14:43.000000000 +1100
54 @@ -3,6 +3,9 @@
55 // --------------------------------------------------------------------------
56 /***************************************************************************
57 * $Log: audiodrv.cpp,v $
58 + * Revision 1.8 2008/07/19 13:58:04 wnd
59 + * Almost complete rewrite to support new ALSA API.
60 + *
61 * Revision 1.7 2002/03/04 19:07:48 s_a_white
62 * Fix C++ use of nothrow.
64 @@ -29,171 +32,277 @@
65 ***************************************************************************/
67 #include "audiodrv.h"
68 -#ifdef HAVE_ALSA
69 +#ifdef HAVE_ALSA
71 #include <stdio.h>
72 #ifdef HAVE_EXCEPTIONS
73 -# include <new>
74 +#include <new>
75 #endif
77 +#include <alsa/asoundlib.h>
78 +#include <string.h>
80 +#define ALSA_DEFAULT "default"
82 Audio_ALSA::Audio_ALSA()
84 - // Reset everything.
85 - outOfOrder();
86 + // Reset everything.
87 + outOfOrder();
90 +Audio_ALSA::~Audio_ALSA()
92 + close ();
95 -Audio_ALSA::~Audio_ALSA ()
96 +void
97 +Audio_ALSA::outOfOrder()
99 - close ();
100 + // Reset everything.
101 + _swapEndian = false;
102 + _bufShift = 0;
103 + _errorString = "None";
104 + _audioHandle = NULL;
107 -void Audio_ALSA::outOfOrder ()
109 - // Reset everything.
110 - _errorString = "None";
111 - _audioHandle = NULL;
114 -void *Audio_ALSA::open (AudioConfig &cfg, const char *)
116 - AudioConfig tmpCfg;
117 - int mask, wantedFormat, format;
118 - int rtn;
119 - int card = -1, dev = 0;
121 - if (_audioHandle != NULL)
123 - _errorString = "ERROR: Device already in use";
124 - return NULL;
127 - if ((rtn = snd_pcm_open_preferred (&_audioHandle, &card, &dev, SND_PCM_OPEN_PLAYBACK)))
129 - _errorString = "ERROR: Could not open audio device.";
130 - goto open_error;
133 - // Transfer input parameters to this object.
134 - // May later be replaced with driver defaults.
135 - tmpCfg = cfg;
137 - snd_pcm_channel_params_t pp;
138 - snd_pcm_channel_setup_t setup;
140 - snd_pcm_channel_info_t pi;
142 - memset (&pi, 0, sizeof (pi));
143 - pi.channel = SND_PCM_CHANNEL_PLAYBACK;
144 - if ((rtn = snd_pcm_plugin_info (_audioHandle, &pi)))
146 - _errorString = "ALSA: snd_pcm_plugin_info failed.";
147 - goto open_error;
150 - memset(&pp, 0, sizeof (pp));
151 +bool
152 +Audio_ALSA::fmt(AudioConfig &cfg, snd_pcm_hw_params_t *hw)
154 + struct precinfo {
155 + snd_pcm_format_t format;
156 + int encoding;
157 + int precision;
158 + int swap;
159 + };
160 + struct precinfo info[] = {
161 +#if defined(WORDS_BIGENDIAN)
162 + { SND_PCM_FORMAT_S16_BE, AUDIO_SIGNED_PCM, 16, false },
163 + { SND_PCM_FORMAT_U16_BE, AUDIO_UNSIGNED_PCM, 16, false },
164 + { SND_PCM_FORMAT_S16_LE, AUDIO_SIGNED_PCM, 16, true },
165 + { SND_PCM_FORMAT_U16_LE, AUDIO_UNSIGNED_PCM, 16, true },
166 +#else
167 + { SND_PCM_FORMAT_S16_LE, AUDIO_SIGNED_PCM, 16, false },
168 + { SND_PCM_FORMAT_U16_LE, AUDIO_UNSIGNED_PCM, 16, false },
169 + { SND_PCM_FORMAT_S16_BE, AUDIO_SIGNED_PCM, 16, true },
170 + { SND_PCM_FORMAT_U16_BE, AUDIO_UNSIGNED_PCM, 16, true },
171 +#endif
172 + { SND_PCM_FORMAT_S8, AUDIO_SIGNED_PCM, 8, false },
173 + { SND_PCM_FORMAT_U8, AUDIO_UNSIGNED_PCM, 8, false }
174 + };
176 + switch (cfg.precision) {
177 + case 8:
178 + for (int i = 0; i < 2; i++) {
179 + struct precinfo t;
180 + memcpy(&t, &info[i], sizeof(t));
181 + memcpy(&info[i + 4], &info[i], sizeof(t));
182 + memcpy(&info[i], &t, sizeof(t));
184 + break;
185 + case 16:
186 + break;
187 + default:
188 + fprintf(stderr, "Unsupported precision: %d bits\n",
189 + cfg.precision);
190 + return false;
193 + int err;
194 + for (int i = 0; i < 6; i++) {
195 + err = snd_pcm_hw_params_set_format(_audioHandle, hw,
196 + info[i].format);
197 + if (err < 0) {
198 + continue;
201 + cfg.precision = info[i].precision;
202 + cfg.encoding = info[i].encoding;
203 + _swapEndian = info[i].swap;
204 + _bufShift = info[i].precision == 8 ? 0 : 1;
205 + return true;
208 - pp.mode = SND_PCM_MODE_BLOCK;
209 - pp.channel = SND_PCM_CHANNEL_PLAYBACK;
210 - pp.start_mode = SND_PCM_START_FULL;
211 - pp.stop_mode = SND_PCM_STOP_STOP;
213 - pp.buf.block.frag_size = pi.max_fragment_size;
215 - pp.buf.block.frags_max = 1;
216 - pp.buf.block.frags_min = 1;
218 - pp.format.interleave = 1;
219 - pp.format.rate = tmpCfg.frequency;
220 - pp.format.voices = tmpCfg.channels;
222 - // Set sample precision and type of encoding.
223 - if ( tmpCfg.precision == 8 )
225 - tmpCfg.encoding = AUDIO_UNSIGNED_PCM;
226 - pp.format.format = SND_PCM_SFMT_U8;
228 - if ( tmpCfg.precision == 16 )
230 - tmpCfg.encoding = AUDIO_SIGNED_PCM;
231 - pp.format.format = SND_PCM_SFMT_S16_LE;
234 - if ((rtn = snd_pcm_plugin_params (_audioHandle, &pp)) < 0)
236 - _errorString = "ALSA: snd_pcm_plugin_params failed.";
237 - goto open_error;
240 - if ((rtn = snd_pcm_plugin_prepare (_audioHandle, SND_PCM_CHANNEL_PLAYBACK)) < 0)
242 - _errorString = "ALSA: snd_pcm_plugin_prepare failed.";
243 - goto open_error;
246 - memset (&setup, 0, sizeof (setup));
247 - setup.channel = SND_PCM_CHANNEL_PLAYBACK;
248 - if ((rtn = snd_pcm_plugin_setup (_audioHandle, &setup)) < 0)
250 - _errorString = "ALSA: snd_pcm_plugin_setup failed.";
251 - goto open_error;
253 + fprintf(stderr, "Cannot set sample format: %s\n", snd_strerror(err));
254 + return false;
259 +bool
260 +Audio_ALSA::init(AudioConfig &cfg, snd_pcm_hw_params_t *hw)
262 + int err;
264 + err = snd_pcm_hw_params_any(_audioHandle, hw);
265 + if (err < 0) {
266 + fprintf(stderr, "Cannot initialize hardware "
267 + "parameter structure: %s\n",
268 + snd_strerror(err));
269 + return false;
272 + err = snd_pcm_hw_params_set_access(_audioHandle, hw,
273 + SND_PCM_ACCESS_RW_INTERLEAVED);
274 + if (err < 0) {
275 + fprintf(stderr, "Cannot set access type: %s\n",
276 + snd_strerror(err));
277 + return false;
280 + /* try to find supported format/precision */
281 + if (! fmt(cfg, hw)) {
282 + return false;
285 + /* use closest frequency */
286 + unsigned int realFreq = (unsigned int) cfg.frequency;
287 + err = snd_pcm_hw_params_set_rate_near(_audioHandle, hw, &realFreq, 0);
288 + if (err < 0) {
289 + fprintf(stderr, "Cannot set sample rate: %s\n",
290 + snd_strerror(err));
291 + return false;
293 + cfg.frequency = realFreq;
295 + switch (cfg.channels) {
296 + case 2:
297 + _bufShift++;
298 + break;
299 + case 1:
300 + break;
301 + default:
302 + fprintf(stderr, "Unsupported channel count: %d\n",
303 + cfg.channels);
304 + return false;
306 + err = snd_pcm_hw_params_set_channels(_audioHandle, hw,
307 + cfg.channels);
308 + if (err < 0) {
309 + fprintf(stderr, "Cannot set channel count: %s\n",
310 + snd_strerror(err));
311 + return false;
314 + err = snd_pcm_hw_params(_audioHandle, hw);
315 + if (err < 0) {
316 + fprintf(stdout, "Cannot set parameters: %s\n",
317 + snd_strerror(err));
318 + return false;
321 - tmpCfg.bufSize = setup.buf.block.frag_size;
322 + return true;
327 +void *
328 +Audio_ALSA::open(AudioConfig &cfg, const char *name)
330 + AudioConfig tmpCfg = cfg;
331 + snd_pcm_hw_params_t *hw;
332 + int err;
334 + if (_audioHandle != NULL) {
335 + _errorString = "ERROR: Device already in use";
336 + return NULL;
339 + err = snd_pcm_open(&_audioHandle, ALSA_DEFAULT,
340 + SND_PCM_STREAM_PLAYBACK, 0);
341 + if (err < 0) {
342 + _errorString = "ERROR: Could not open audio device.";
343 + fprintf(stderr, "Cannot open audio device: %s\n",
344 + snd_strerror(err));
345 + return false;
348 + err = snd_pcm_hw_params_malloc(&hw);
349 + if (err < 0) {
350 + _errorString = "ERROR: Cannot initialise ALSA";
351 + fprintf(stderr, "Cannot allocate hardware "
352 + "parameter structure: %s\n",
353 + snd_strerror(err));
354 + return false;
357 + bool init_ok = init(tmpCfg, hw);
358 + snd_pcm_hw_params_free(hw);
359 + if (! init_ok) {
360 + _errorString = "ERROR: Cannot initialise ALSA";
361 + return false;
364 + err = snd_pcm_prepare(_audioHandle);
365 + if (err < 0) {
366 + _errorString = "Cannot initialise ALSA";
367 + fprintf(stderr, "cannot prepare audio interface for use: %s\n",
368 + snd_strerror(err));
369 + return false;
372 + tmpCfg.bufSize = 4096;
373 #ifdef HAVE_EXCEPTIONS
374 - _sampleBuffer = new(std::nothrow) int_least8_t[tmpCfg.bufSize];
375 + _sampleBuffer = new(std::nothrow) int_least8_t[tmpCfg.bufSize];
376 #else
377 - _sampleBuffer = new int_least8_t[tmpCfg.bufSize];
378 + _sampleBuffer = new int_least8_t[tmpCfg.bufSize];
379 #endif
381 - if (!_sampleBuffer)
383 - _errorString = "AUDIO: Unable to allocate memory for sample buffers.";
384 - goto open_error;
387 - // Setup internal Config
388 - _settings = tmpCfg;
389 - // Update the users settings
390 - getConfig (cfg);
391 - return _sampleBuffer;
393 -open_error:
394 - if (_audioHandle != NULL)
396 - close ();
399 - perror ("ALSA");
400 -return NULL;
401 + if (!_sampleBuffer) {
402 + _errorString = "Unable to allocate memory for sample buffers";
403 + return NULL;
406 + // Setup internal Config
407 + _settings = tmpCfg;
408 + // Update the users settings
409 + getConfig (cfg);
410 + return _sampleBuffer;
415 // Close an opened audio device, free any allocated buffers and
416 // reset any variables that reflect the current state.
417 -void Audio_ALSA::close ()
418 +void
419 +Audio_ALSA::close()
421 - if (_audioHandle != NULL )
423 - snd_pcm_close(_audioHandle);
424 - delete [] _sampleBuffer;
425 - outOfOrder ();
427 + if (_audioHandle != NULL) {
428 + snd_pcm_close(_audioHandle);
429 + delete [] _sampleBuffer;
430 + outOfOrder ();
434 -void *Audio_ALSA::reset ()
437 +void *
438 +Audio_ALSA::reset ()
440 - return (void *) _sampleBuffer;
441 + return (void *) _sampleBuffer;
444 -void *Audio_ALSA::write ()
446 - if (_audioHandle == NULL)
448 - _errorString = "ERROR: Device not open.";
449 - return NULL;
452 - snd_pcm_plugin_write (_audioHandle, _sampleBuffer, _settings.bufSize);
453 - return (void *) _sampleBuffer;
455 +void *
456 +Audio_ALSA::write()
458 + if (_audioHandle == NULL)
460 + _errorString = "ERROR: Device not open.";
461 + return NULL;
464 + if (_swapEndian) {
465 + for (int n = 0; n < _settings.bufSize; n += 2) {
466 + char t = ((char *) _sampleBuffer)[n];
467 + ((char *) _sampleBuffer)[n] =
468 + ((char *) _sampleBuffer)[n + 1];
469 + ((char *) _sampleBuffer)[n + 1] = t;
472 + snd_pcm_writei(_audioHandle, _sampleBuffer,
473 + _settings.bufSize >> _bufShift);
474 + return (void *) _sampleBuffer;
477 #endif // HAVE_ALSA
478 diff -Naur sidplay-2.0.9.ORIG/src/audio/alsa/audiodrv.h sidplay-2.0.9/src/audio/alsa/audiodrv.h
479 --- sidplay-2.0.9.ORIG/src/audio/alsa/audiodrv.h 2002-01-11 06:04:00.000000000 +1100
480 +++ sidplay-2.0.9/src/audio/alsa/audiodrv.h 2011-03-18 14:14:43.000000000 +1100
481 @@ -3,6 +3,9 @@
482 // --------------------------------------------------------------------------
483 /***************************************************************************
484 * $Log: audiodrv.h,v $
485 + * Revision 1.6 2008/07/19 13:58:04 wnd
486 + * Update to new ALSA API.
488 * Revision 1.5 2002/01/10 19:04:00 s_a_white
489 * Interface changes for audio drivers.
491 @@ -36,7 +39,7 @@
492 #include <fcntl.h>
493 #include <unistd.h>
494 #include <sys/ioctl.h>
495 -#include <sys/asoundlib.h>
496 +#include <alsa/asoundlib.h>
497 #include "../AudioBase.h"
500 @@ -44,6 +47,8 @@
502 private: // ------------------------------------------------------- private
503 snd_pcm_t * _audioHandle;
504 + bool _swapEndian;
505 + int _bufShift;
507 void outOfOrder ();
509 @@ -51,6 +56,8 @@
510 Audio_ALSA();
511 ~Audio_ALSA();
513 + bool fmt (AudioConfig &cfg, snd_pcm_hw_params_t *hw);
514 + bool init (AudioConfig &cfg, snd_pcm_hw_params_t *hw);
515 void *open (AudioConfig &cfg, const char *name);
516 void close ();
517 // Rev 1.2 (saw) - Changed, see AudioBase.h