Changeset 320
- Timestamp:
- 01/25/06 12:42:48 (3 years ago)
- Files:
-
- libremix/trunk/config.h.in (modified) (1 diff)
- libremix/trunk/configure.ac (modified) (1 diff)
- libremix/trunk/remix.pc.in (modified) (1 diff)
- libremix/trunk/src/examples/Makefile.am (modified) (1 diff)
- libremix/trunk/src/libremix/remix_monitor.c (modified) (9 diffs)
- libremix/trunk/src/libremix/remix_private.h (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
libremix/trunk/config.h.in
r172 r320 3 3 /* Define to build experimental code */ 4 4 #undef ANX_CONFIG_EXPERIMENTAL 5 6 /* Set to 1 if using ALSA for sound output. */7 #undef HAVE_ALSA8 9 /* Define to 1 if you have the <alsa/asoundlib.h> header file. */10 #undef HAVE_ALSA_ASOUNDLIB_H11 5 12 6 /* Define to 1 if you have the <dlfcn.h> header file. */ libremix/trunk/configure.ac
r172 r320 89 89 AM_CONDITIONAL(BUILD_MONITOR, test -n "$BUILD_MONITOR") 90 90 91 dnl Test for ALSA.92 93 HAVE_ALSA=094 AC_CHECK_HEADERS(alsa/asoundlib.h)95 if test "x${ac_cv_header_alsa_asoundlib_h}" = xyes ; then96 HAVE_ALSA=197 ALSA_LIBS="-lasound"98 AC_SUBST(ALSA_LIBS)99 fi100 101 AC_DEFINE_UNQUOTED([HAVE_ALSA],${HAVE_ALSA}, [Set to 1 if using ALSA for sound output.])102 103 91 dnl 104 92 dnl Set PACKAGE_PLUGIN_DIR in Makefiles and config.h. libremix/trunk/remix.pc.in
r161 r320 8 8 Requires: ctxdata sndfile 9 9 Version: @VERSION@ 10 Libs: -L${libdir} -lremix -ldl @ALSA_LIBS@10 Libs: -L${libdir} -lremix -ldl 11 11 Cflags: -I${includedir} libremix/trunk/src/examples/Makefile.am
r168 r320 16 16 17 17 noisedemo_SOURCES = noisedemo.c 18 noisedemo_LDADD = $(REMIX_LIBS) @ALSA_LIBS@18 noisedemo_LDADD = $(REMIX_LIBS) 19 19 20 20 squaredemo_SOURCES = squaredemo.c 21 squaredemo_LDADD = $(REMIX_LIBS) @ALSA_LIBS@21 squaredemo_LDADD = $(REMIX_LIBS) 22 22 23 23 sndfiledemo_SOURCES = sndfiledemo.c 24 sndfiledemo_LDADD = $(REMIX_LIBS) @SNDFILE_LIBS@ @ALSA_LIBS@24 sndfiledemo_LDADD = $(REMIX_LIBS) @SNDFILE_LIBS@ libremix/trunk/src/libremix/remix_monitor.c
r176 r320 41 41 #include <config.h> 42 42 43 #if (HAVE_ALSA == 1)44 #define ALSA_PCM_OLD_HW_PARAMS_API45 #include <alsa/asoundlib.h>46 #else47 typedef void snd_pcm_t;48 #endif49 50 43 #define __REMIX__ 51 44 #include "remix.h" … … 71 64 72 65 static RemixBase * 73 alsa_reset_device (RemixEnv * env, RemixBase * base, snd_pcm_t * alsa_dev,74 int channels, int samplerate);75 76 static snd_pcm_t * alsa_open_device (RemixEnv * env, RemixBase * base);77 78 static RemixCount79 alsa_write_float (RemixEnv * env, snd_pcm_t * alsa_dev, RemixPCM *data,80 RemixCount playcount);81 82 static void alsa_close_device (RemixMonitor * monitor);83 84 85 static RemixBase *86 66 remix_monitor_reset_device (RemixEnv * env, RemixBase * base) 87 67 { … … 110 90 } 111 91 112 if (monitor->alsa_dev != NULL) {113 alsa_reset_device (env, base, monitor->alsa_dev, nr_channels, monitor->frequency);114 return base;115 }116 117 92 if (ioctl (monitor->dev_dsp_fd, SNDCTL_DSP_GETFMTS, &monitor->mask) == -1) { 118 93 remix_set_error (env, REMIX_ERROR_SYSTEM); … … 172 147 173 148 monitor->dev_dsp_fd = -1; 174 monitor->alsa_dev = NULL; 175 176 if (HAVE_ALSA == 1) { 177 monitor->alsa_dev = alsa_open_device (env, base); 178 } 179 180 if (monitor->alsa_dev == NULL) { 181 monitor->dev_dsp_fd = open (FILENAME, O_WRONLY, 0); 182 if (monitor->dev_dsp_fd == -1) { 183 printf ("Couldn't open any output device.\n"); 184 remix_set_error (env, REMIX_ERROR_SYSTEM); 185 return RemixNone; 186 } 149 150 monitor->dev_dsp_fd = open (FILENAME, O_WRONLY, 0); 151 if (monitor->dev_dsp_fd == -1) { 152 printf ("Couldn't open any output device.\n"); 153 remix_set_error (env, REMIX_ERROR_SYSTEM); 154 return RemixNone; 187 155 } 188 156 … … 217 185 RemixMonitor * monitor = (RemixMonitor *)base; 218 186 219 if (monitor->alsa_dev != NULL) { 220 alsa_close_device (monitor); 221 } else if (monitor->dev_dsp_fd != -1) { 187 if (monitor->dev_dsp_fd != -1) { 222 188 close (monitor->dev_dsp_fd); 223 189 } … … 255 221 RemixCount n = 0; 256 222 fd_set fds; 257 258 if (monitor->alsa_dev != NULL) {259 printf ("1 ######## Should not be here if using ALSA.\n");260 return count;261 }262 223 263 224 if (!(monitor->format & AFMT_S16_LE)) { … … 298 259 const RemixPCM max_value = (RemixPCM)SHRT_MAX / 2; 299 260 300 if (monitor->alsa_dev != NULL) {301 /* Assuming here that we have two channels. */302 i = alsa_write_float (env, monitor->alsa_dev, data, count / 2) * 2;303 304 return i;305 }306 307 261 for (i = 0; i < count; i++) { 308 262 value = *data++ * max_value; … … 324 278 RemixPCM * d; 325 279 326 if (monitor->alsa_dev != NULL) {327 while (remaining > 0) {328 playcount = MIN (remaining, REMIX_MONITOR_BUFFERLEN);329 d = &chunk->data[offset];330 n = alsa_write_float (env, monitor->alsa_dev, d, playcount);331 332 if (n == -1) {333 return -1;334 }335 336 offset += n;337 written += n;338 remaining -= n;339 }340 return written;341 }342 343 280 if (monitor->dev_dsp_fd == -1) { 344 281 remix_dprintf ("[remix_monitor_chunk] no file\n"); … … 446 383 return monitor; 447 384 } 448 449 #if (HAVE_ALSA == 0)450 451 static snd_pcm_t *452 alsa_open_device (RemixEnv * env, RemixBase * base)453 {454 env = env;455 base = base;456 return NULL;457 }458 459 static RemixBase *460 alsa_reset_device (RemixEnv * env, RemixBase * base, snd_pcm_t * alsa_dev, int channels, int samplerate)461 {462 env = env;463 alsa_dev = alsa_dev;464 channels = channels;465 samplerate = samplerate;466 return base;467 }468 469 static RemixCount470 alsa_write_float (RemixEnv * env, snd_pcm_t * alsa_dev, RemixPCM *data,471 RemixCount playcount)472 {473 env = env;474 alsa_dev = alsa_dev;475 data = data;476 return playcount;477 }478 479 static void480 alsa_close_device (RemixMonitor * monitor)481 {482 monitor = monitor;483 }484 485 #else486 487 static snd_pcm_t *488 alsa_open_device (RemixEnv * env, RemixBase * base)489 {490 snd_pcm_t *alsa_device = NULL;491 char *device_name = "default";492 int error;493 494 if ((error = snd_pcm_open (&alsa_device, device_name, SND_PCM_STREAM_PLAYBACK, 0)) < 0) {495 return NULL;496 }497 498 return alsa_device;499 }500 501 static RemixBase *502 alsa_reset_device (RemixEnv * env, RemixBase * base, snd_pcm_t * alsa_dev,503 int channels, int samplerate)504 {505 snd_pcm_hw_params_t *hw_params;506 int periods;507 int error;508 509 if ((error = snd_pcm_hw_params_malloc (&hw_params)) < 0) {510 remix_set_error (env, REMIX_ERROR_SYSTEM);511 return RemixNone;512 }513 514 if ((error = snd_pcm_hw_params_any (alsa_dev, hw_params)) < 0) {515 remix_set_error (env, REMIX_ERROR_SYSTEM);516 return RemixNone;517 }518 519 if ((error = snd_pcm_hw_params_set_access (alsa_dev, hw_params,520 SND_PCM_ACCESS_RW_INTERLEAVED)) < 0) {521 remix_set_error (env, REMIX_ERROR_SYSTEM);522 return RemixNone;523 }524 525 if ((error = snd_pcm_hw_params_set_format (alsa_dev, hw_params,526 SND_PCM_FORMAT_FLOAT)) < 0) {527 remix_set_error (env, REMIX_ERROR_SYSTEM);528 return RemixNone;529 }530 531 if ((error = snd_pcm_hw_params_set_rate_near (alsa_dev, hw_params,532 samplerate, 0)) < 0) {533 remix_set_error (env, REMIX_ERROR_SYSTEM);534 return RemixNone;535 }536 537 if ((error = snd_pcm_hw_params_set_channels (alsa_dev, hw_params, channels)) < 0) {538 remix_set_error (env, REMIX_ERROR_SYSTEM);539 return RemixNone;540 }541 542 if ((error = snd_pcm_hw_params_set_period_size (alsa_dev, hw_params,543 REMIX_MONITOR_BUFFERLEN/channels, 0)) < 0) {544 remix_set_error (env, REMIX_ERROR_SYSTEM);545 return RemixNone;546 }547 548 periods = MIN (4, snd_pcm_hw_params_get_periods_max (hw_params, 0));549 periods =550 MAX (periods, snd_pcm_hw_params_get_periods_min (hw_params, 0));551 552 if ((error = snd_pcm_hw_params_set_periods (alsa_dev, hw_params,553 periods, 0)) < 0) {554 remix_set_error (env, REMIX_ERROR_SYSTEM);555 return RemixNone;556 }557 558 if ((error = snd_pcm_hw_params (alsa_dev, hw_params)) < 0) {559 remix_set_error (env, REMIX_ERROR_SYSTEM);560 return RemixNone;561 }562 563 snd_pcm_hw_params_free (hw_params);564 565 if ((error = snd_pcm_prepare (alsa_dev)) < 0) {566 remix_set_error (env, REMIX_ERROR_SYSTEM);567 return RemixNone;568 }569 570 return base;571 }572 573 static RemixCount574 alsa_write_float (RemixEnv * env, snd_pcm_t * alsa_dev, RemixPCM *data,575 RemixCount playcount /* frames */)576 {577 snd_pcm_status_t * status;578 int err;579 580 /*printf ("want to write %ld thingies\n", playcount);*/581 582 if (snd_pcm_wait (alsa_dev, 1000) < 0) {583 printf ("snd_pcm_wait error\n");584 remix_set_error (env, REMIX_ERROR_SYSTEM);585 return -1;586 }587 588 err = snd_pcm_writei (alsa_dev, data, playcount);589 590 if (err == -EPIPE) {591 snd_pcm_status_alloca(&status);592 if ((err = snd_pcm_status(alsa_dev, status))<0) {593 fprintf(stderr, "Remix: alsa_write: xrun. can't determine length\n");594 } else {595 if (snd_pcm_status_get_state(status) == SND_PCM_STATE_XRUN) {596 struct timeval now, diff, tstamp;597 gettimeofday(&now, 0);598 snd_pcm_status_get_trigger_tstamp(status, &tstamp);599 timersub(&now, &tstamp, &diff);600 fprintf(stderr, "Remix: alsa_write: xrun of at least %.3f msecs. "601 "resetting stream\n", diff.tv_sec * 1000 + diff.tv_usec / 1000.0);602 } else {603 fprintf(stderr, "Remix: alsa_write: xrun. can't determine length\n");604 }605 }606 snd_pcm_prepare(alsa_dev);607 err = snd_pcm_writei(alsa_dev, data, playcount);608 if (err != playcount) {609 fprintf(stderr, "Remix: alsa_write: %s\n", snd_strerror(err));610 return 0;611 } else if (err < 0) {612 fprintf(stderr, "Remix: alsa_write: %s\n", snd_strerror(err));613 return 0;614 }615 }616 617 return err;618 }619 620 static void621 alsa_close_device (RemixMonitor * monitor)622 {623 snd_pcm_close (monitor->alsa_dev);624 monitor->alsa_dev = NULL;625 }626 #endiflibremix/trunk/src/libremix/remix_private.h
r176 r320 170 170 #define REMIX_MONITOR_BUFFERLEN 2048 171 171 172 /* Opaque type from <alsa/pcm.h> */173 #ifndef __ALSA_PCM_H174 typedef struct _snd_pcm snd_pcm_t;175 #endif176 177 172 struct _RemixMonitor { 178 173 RemixBase base; … … 187 182 int numfrags; 188 183 int fragsize; 189 snd_pcm_t *alsa_dev;190 184 }; 191 185
