Changeset 320

Show
Ignore:
Timestamp:
01/25/06 12:42:48 (3 years ago)
Author:
conrad
Message:

remove all the ALSA code

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • libremix/trunk/config.h.in

    r172 r320  
    33/* Define to build experimental code */ 
    44#undef ANX_CONFIG_EXPERIMENTAL 
    5  
    6 /* Set to 1 if using ALSA for sound output. */ 
    7 #undef HAVE_ALSA 
    8  
    9 /* Define to 1 if you have the <alsa/asoundlib.h> header file. */ 
    10 #undef HAVE_ALSA_ASOUNDLIB_H 
    115 
    126/* Define to 1 if you have the <dlfcn.h> header file. */ 
  • libremix/trunk/configure.ac

    r172 r320  
    8989AM_CONDITIONAL(BUILD_MONITOR, test -n "$BUILD_MONITOR") 
    9090 
    91 dnl Test for ALSA. 
    92  
    93 HAVE_ALSA=0 
    94 AC_CHECK_HEADERS(alsa/asoundlib.h) 
    95   if test "x${ac_cv_header_alsa_asoundlib_h}" = xyes ; then 
    96     HAVE_ALSA=1 
    97     ALSA_LIBS="-lasound" 
    98     AC_SUBST(ALSA_LIBS) 
    99   fi 
    100  
    101 AC_DEFINE_UNQUOTED([HAVE_ALSA],${HAVE_ALSA}, [Set to 1 if using ALSA for sound output.]) 
    102  
    10391dnl 
    10492dnl Set PACKAGE_PLUGIN_DIR in Makefiles and config.h. 
  • libremix/trunk/remix.pc.in

    r161 r320  
    88Requires: ctxdata sndfile 
    99Version: @VERSION@ 
    10 Libs: -L${libdir} -lremix -ldl @ALSA_LIBS@ 
     10Libs: -L${libdir} -lremix -ldl 
    1111Cflags: -I${includedir} 
  • libremix/trunk/src/examples/Makefile.am

    r168 r320  
    1616 
    1717noisedemo_SOURCES = noisedemo.c 
    18 noisedemo_LDADD = $(REMIX_LIBS) @ALSA_LIBS@ 
     18noisedemo_LDADD = $(REMIX_LIBS) 
    1919 
    2020squaredemo_SOURCES = squaredemo.c 
    21 squaredemo_LDADD = $(REMIX_LIBS) @ALSA_LIBS@ 
     21squaredemo_LDADD = $(REMIX_LIBS) 
    2222 
    2323sndfiledemo_SOURCES = sndfiledemo.c 
    24 sndfiledemo_LDADD = $(REMIX_LIBS) @SNDFILE_LIBS@ @ALSA_LIBS@ 
     24sndfiledemo_LDADD = $(REMIX_LIBS) @SNDFILE_LIBS@ 
  • libremix/trunk/src/libremix/remix_monitor.c

    r176 r320  
    4141#include <config.h> 
    4242 
    43 #if (HAVE_ALSA == 1) 
    44 #define ALSA_PCM_OLD_HW_PARAMS_API 
    45 #include <alsa/asoundlib.h> 
    46 #else 
    47 typedef void snd_pcm_t; 
    48 #endif 
    49  
    5043#define __REMIX__ 
    5144#include "remix.h" 
     
    7164 
    7265static 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 RemixCount 
    79 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 * 
    8666remix_monitor_reset_device (RemixEnv * env, RemixBase * base) 
    8767{ 
     
    11090  } 
    11191 
    112   if (monitor->alsa_dev != NULL) { 
    113     alsa_reset_device (env, base, monitor->alsa_dev, nr_channels, monitor->frequency); 
    114         return base; 
    115   } 
    116  
    11792  if (ioctl (monitor->dev_dsp_fd, SNDCTL_DSP_GETFMTS, &monitor->mask) == -1) { 
    11893    remix_set_error (env, REMIX_ERROR_SYSTEM); 
     
    172147   
    173148  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; 
    187155  } 
    188156 
     
    217185  RemixMonitor * monitor = (RemixMonitor *)base; 
    218186   
    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) { 
    222188    close (monitor->dev_dsp_fd); 
    223189  } 
     
    255221  RemixCount n = 0; 
    256222  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   } 
    262223 
    263224  if (!(monitor->format & AFMT_S16_LE)) { 
     
    298259  const RemixPCM max_value = (RemixPCM)SHRT_MAX / 2; 
    299260 
    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  
    307261  for (i = 0; i < count; i++) { 
    308262    value = *data++ * max_value; 
     
    324278  RemixPCM * d; 
    325279  
    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  
    343280  if (monitor->dev_dsp_fd == -1) { 
    344281    remix_dprintf ("[remix_monitor_chunk] no file\n"); 
     
    446383  return monitor; 
    447384} 
    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 RemixCount 
    470 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 void 
    480 alsa_close_device (RemixMonitor * monitor) 
    481 { 
    482   monitor = monitor; 
    483 } 
    484  
    485 #else 
    486  
    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 RemixCount 
    574 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 void 
    621 alsa_close_device (RemixMonitor * monitor) 
    622 { 
    623   snd_pcm_close (monitor->alsa_dev); 
    624   monitor->alsa_dev = NULL; 
    625 } 
    626 #endif 
  • libremix/trunk/src/libremix/remix_private.h

    r176 r320  
    170170#define REMIX_MONITOR_BUFFERLEN 2048 
    171171 
    172 /* Opaque type from <alsa/pcm.h> */ 
    173 #ifndef __ALSA_PCM_H 
    174 typedef struct _snd_pcm snd_pcm_t; 
    175 #endif 
    176  
    177172struct _RemixMonitor { 
    178173  RemixBase base; 
     
    187182  int numfrags; 
    188183  int fragsize; 
    189   snd_pcm_t *alsa_dev; 
    190184}; 
    191185