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
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
13 +test "$OK_ASOUNDLIB_H" -a "$OK_LIBASOUND" && audio="alsa"
15 dnl Audio Subsystem Test
16 AC_MSG_CHECKING([which audio subsystem is available])
20 *cygwin*) AC_DEFINE(HAVE_MMSYSTEM)
21 audiodrv_libadd="./audio/mmsystem/libmmsystem.a"
22 AC_MSG_RESULT(mmsystem)
24 *netbsd*) AC_DEFINE(HAVE_OSS)
25 audiodrv_libadd="./audio/oss/liboss.a"
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"
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)
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
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) \
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
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.
61 * Revision 1.7 2002/03/04 19:07:48 s_a_white
62 * Fix C++ use of nothrow.
65 ***************************************************************************/
72 #ifdef HAVE_EXCEPTIONS
77 +#include <alsa/asoundlib.h>
80 +#define ALSA_DEFAULT "default"
82 Audio_ALSA::Audio_ALSA()
84 - // Reset everything.
86 + // Reset everything.
90 +Audio_ALSA::~Audio_ALSA()
95 -Audio_ALSA::~Audio_ALSA ()
97 +Audio_ALSA::outOfOrder()
100 + // Reset everything.
101 + _swapEndian = false;
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;
119 - int card = -1, dev = 0;
121 - if (_audioHandle != NULL)
123 - _errorString = "ERROR: Device already in use";
127 - if ((rtn = snd_pcm_open_preferred (&_audioHandle, &card, &dev, SND_PCM_OPEN_PLAYBACK)))
129 - _errorString = "ERROR: Could not open audio device.";
133 - // Transfer input parameters to this object.
134 - // May later be replaced with driver defaults.
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.";
150 - memset(&pp, 0, sizeof (pp));
152 +Audio_ALSA::fmt(AudioConfig &cfg, snd_pcm_hw_params_t *hw)
155 + snd_pcm_format_t format;
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 },
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 },
172 + { SND_PCM_FORMAT_S8, AUDIO_SIGNED_PCM, 8, false },
173 + { SND_PCM_FORMAT_U8, AUDIO_UNSIGNED_PCM, 8, false }
176 + switch (cfg.precision) {
178 + for (int i = 0; i < 2; i++) {
180 + memcpy(&t, &info[i], sizeof(t));
181 + memcpy(&info[i + 4], &info[i], sizeof(t));
182 + memcpy(&info[i], &t, sizeof(t));
188 + fprintf(stderr, "Unsupported precision: %d bits\n",
194 + for (int i = 0; i < 6; i++) {
195 + err = snd_pcm_hw_params_set_format(_audioHandle, hw,
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;
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.";
240 - if ((rtn = snd_pcm_plugin_prepare (_audioHandle, SND_PCM_CHANNEL_PLAYBACK)) < 0)
242 - _errorString = "ALSA: snd_pcm_plugin_prepare failed.";
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.";
253 + fprintf(stderr, "Cannot set sample format: %s\n", snd_strerror(err));
260 +Audio_ALSA::init(AudioConfig &cfg, snd_pcm_hw_params_t *hw)
264 + err = snd_pcm_hw_params_any(_audioHandle, hw);
266 + fprintf(stderr, "Cannot initialize hardware "
267 + "parameter structure: %s\n",
268 + snd_strerror(err));
272 + err = snd_pcm_hw_params_set_access(_audioHandle, hw,
273 + SND_PCM_ACCESS_RW_INTERLEAVED);
275 + fprintf(stderr, "Cannot set access type: %s\n",
276 + snd_strerror(err));
280 + /* try to find supported format/precision */
281 + if (! fmt(cfg, hw)) {
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);
289 + fprintf(stderr, "Cannot set sample rate: %s\n",
290 + snd_strerror(err));
293 + cfg.frequency = realFreq;
295 + switch (cfg.channels) {
302 + fprintf(stderr, "Unsupported channel count: %d\n",
306 + err = snd_pcm_hw_params_set_channels(_audioHandle, hw,
309 + fprintf(stderr, "Cannot set channel count: %s\n",
310 + snd_strerror(err));
314 + err = snd_pcm_hw_params(_audioHandle, hw);
316 + fprintf(stdout, "Cannot set parameters: %s\n",
317 + snd_strerror(err));
321 - tmpCfg.bufSize = setup.buf.block.frag_size;
328 +Audio_ALSA::open(AudioConfig &cfg, const char *name)
330 + AudioConfig tmpCfg = cfg;
331 + snd_pcm_hw_params_t *hw;
334 + if (_audioHandle != NULL) {
335 + _errorString = "ERROR: Device already in use";
339 + err = snd_pcm_open(&_audioHandle, ALSA_DEFAULT,
340 + SND_PCM_STREAM_PLAYBACK, 0);
342 + _errorString = "ERROR: Could not open audio device.";
343 + fprintf(stderr, "Cannot open audio device: %s\n",
344 + snd_strerror(err));
348 + err = snd_pcm_hw_params_malloc(&hw);
350 + _errorString = "ERROR: Cannot initialise ALSA";
351 + fprintf(stderr, "Cannot allocate hardware "
352 + "parameter structure: %s\n",
353 + snd_strerror(err));
357 + bool init_ok = init(tmpCfg, hw);
358 + snd_pcm_hw_params_free(hw);
360 + _errorString = "ERROR: Cannot initialise ALSA";
364 + err = snd_pcm_prepare(_audioHandle);
366 + _errorString = "Cannot initialise ALSA";
367 + fprintf(stderr, "cannot prepare audio interface for use: %s\n",
368 + snd_strerror(err));
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];
377 - _sampleBuffer = new int_least8_t[tmpCfg.bufSize];
378 + _sampleBuffer = new int_least8_t[tmpCfg.bufSize];
381 - if (!_sampleBuffer)
383 - _errorString = "AUDIO: Unable to allocate memory for sample buffers.";
387 - // Setup internal Config
388 - _settings = tmpCfg;
389 - // Update the users settings
391 - return _sampleBuffer;
394 - if (_audioHandle != NULL)
401 + if (!_sampleBuffer) {
402 + _errorString = "Unable to allocate memory for sample buffers";
406 + // Setup internal Config
407 + _settings = tmpCfg;
408 + // Update the users settings
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 ()
421 - if (_audioHandle != NULL )
423 - snd_pcm_close(_audioHandle);
424 - delete [] _sampleBuffer;
427 + if (_audioHandle != NULL) {
428 + snd_pcm_close(_audioHandle);
429 + delete [] _sampleBuffer;
434 -void *Audio_ALSA::reset ()
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.";
452 - snd_pcm_plugin_write (_audioHandle, _sampleBuffer, _settings.bufSize);
453 - return (void *) _sampleBuffer;
458 + if (_audioHandle == NULL)
460 + _errorString = "ERROR: Device not open.";
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;
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
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.
494 #include <sys/ioctl.h>
495 -#include <sys/asoundlib.h>
496 +#include <alsa/asoundlib.h>
497 #include "../AudioBase.h"
502 private: // ------------------------------------------------------- private
503 snd_pcm_t * _audioHandle;
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);
517 // Rev 1.2 (saw) - Changed, see AudioBase.h