Changeset 2370:20fe0615bbe9 in roaraudio


Ignore:
Timestamp:
08/15/09 03:58:43 (15 years ago)
Author:
phi
Branch:
default
Phase:
public
Message:

added MIDI support to sndio output driver

Location:
roard
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • roard/driver.c

    r2367 r2370  
    5555#endif 
    5656#ifdef ROAR_HAVE_LIBSNDIO 
    57  {"sndio", "OpenBSD sndio", "/dev/audio, /tmp/aucat-<uid>/default", DRV_FLAG_NONE, ROAR_SUBSYS_WAVEFORM, 
     57 {"sndio", "OpenBSD sndio", "/dev/audio, /tmp/aucat-<uid>/default", DRV_FLAG_NONE, ROAR_SUBSYS_WAVEFORM|ROAR_SUBSYS_MIDI, 
    5858  NULL, NULL, driver_sndio_open}, 
    5959#endif 
  • roard/driver_sndio.c

    r2369 r2370  
    4242} 
    4343 
    44 #define er() if ( self->handle ) sio_close(self->handle); if ( self->device ) free(self->device); free(self); return -1 
     44#define er() if ( self->shandle ) sio_close(self->shandle); \ 
     45             if ( self->mhandle ) mio_close(self->mhandle); \ 
     46             if ( self->device  ) free(self->device);       \ 
     47             free(self);                                    \ 
     48             return -1 
     49 
    4550int driver_sndio_open(struct roar_vio_calls * inst, char * device, struct roar_audio_info * info, int fh, struct roar_stream_server * sstream) { 
    4651 struct driver_sndio * self = NULL; 
     
    5560 
    5661 self->ssid = -1; 
     62 
     63 if ( sstream == NULL ) { 
     64  self->stream = NULL; 
     65  self->dir    = ROAR_DIR_OUTPUT; 
     66 } else { 
     67  self->stream = sstream; 
     68  self->dir    = ROAR_STREAM(sstream)->dir; 
     69 
     70  switch (self->dir) { 
     71   case ROAR_DIR_OUTPUT: 
     72   case ROAR_DIR_MONITOR: 
     73     self->dir = ROAR_DIR_OUTPUT; 
     74    break; 
     75   case ROAR_DIR_MIDI_OUT: 
     76     info->channels = 16; 
     77     info->codec    = ROAR_CODEC_MIDI; 
     78     info->bits     = 8; 
     79    break; 
     80   default: 
     81     er(); 
     82  } 
     83 } 
    5784 
    5885 if ( device != NULL ) 
     
    6693 if ( driver_sndio_open_device(self) == -1 ) { 
    6794  ROAR_ERR("driver_sndio_open(*): Can not open audio device"); 
    68   if ( self->handle ) 
    69    sio_close(self->handle); 
    70  
    71   if ( self->device ) 
    72    free(self->device); 
    73  
    74   free(self); 
    75  
    76   return -1; 
    77 //  er(); 
     95  er(); 
    7896 } 
    7997 
    8098 ROAR_DBG("driver_sndio_open(*): sndio devices opened :)"); 
    81  
    82  if ( sstream != NULL ) 
    83   driver_sndio_ctl(inst, ROAR_VIO_CTL_SET_SSTREAM, sstream); 
    8499 
    85100 return 0; 
     
    90105 struct driver_sndio * self = vio->inst; 
    91106 
    92  if ( self->handle != NULL ) 
    93   sio_close(self->handle); 
     107 if ( self->shandle != NULL ) 
     108  sio_close(self->shandle); 
     109 
     110 if ( self->mhandle != NULL ) 
     111  mio_close(self->mhandle); 
    94112 
    95113 if ( self->device != NULL ) 
     
    103121int     driver_sndio_open_device  (struct driver_sndio * self) { 
    104122 
    105  if ( (self->handle = sio_open(self->device, SIO_PLAY, 0)) == NULL ) { 
    106   ROAR_ERR("driver_sndio_open_device(*): Can not open sndio audio device"); 
    107   return -1; 
    108  } 
    109  
    110  self->need_config = 1; 
    111  
     123 ROAR_DBG("driver_sndio_open_device(*) = ?"); 
     124 switch (self->dir) { 
     125  case ROAR_DIR_OUTPUT: 
     126    if ( (self->shandle = sio_open(self->device, SIO_PLAY, 0)) == NULL ) { 
     127     ROAR_ERR("driver_sndio_open_device(*): Can not open sndio audio device"); 
     128     return -1; 
     129    } 
     130   self->need_config = 1; 
     131   break; 
     132  case ROAR_DIR_MIDI_OUT: 
     133    if ( (self->mhandle = mio_open(self->device, MIO_OUT, 0)) == NULL ) { 
     134     ROAR_ERR("driver_sndio_open_device(*): Can not open sndio MIDI device"); 
     135     return -1; 
     136    } 
     137   break; 
     138  default: 
     139    return -1; 
     140 } 
     141 
     142 ROAR_DBG("driver_sndio_open_device(*) = ?"); 
    112143 return 0; 
    113144} 
     
    144175 } 
    145176 
    146  if ( sio_setpar(self->handle, &par) == 0 ) { 
     177 if ( sio_setpar(self->shandle, &par) == 0 ) { 
    147178  ROAR_ERR("driver_sndio_config_device(*): Can not set stream parameters"); 
    148179  return -1; 
    149180 } 
    150181 
    151  if ( sio_start(self->handle) == 0 ) { 
     182 if ( sio_start(self->shandle) == 0 ) { 
    152183  ROAR_ERR("driver_sndio_config_device(*): Can not start stream"); 
    153184  return -1; 
     
    165196ssize_t driver_sndio_write        (struct roar_vio_calls * vio, void *buf, size_t count) { 
    166197 struct driver_sndio * self = vio->inst; 
     198 
     199 ROAR_DBG("driver_sndio_write(*) = ?"); 
    167200 
    168201 if ( self->need_config ) { 
     
    172205 } 
    173206 
    174  return sio_write(self->handle, buf, count); 
     207 ROAR_DBG("driver_sndio_write(*) = ?"); 
     208 
     209 switch (self->dir) { 
     210  case ROAR_DIR_OUTPUT: 
     211    return sio_write(self->shandle, buf, count); 
     212   break; 
     213  case ROAR_DIR_MIDI_OUT: 
     214    return mio_write(self->mhandle, buf, count); 
     215   break; 
     216 } 
     217 
     218 ROAR_WARN("driver_sndio_write(*): Driver changed direction to something not supported, this should not happen"); 
     219 
     220 return -1; 
    175221} 
    176222 
     
    191237   break; 
    192238  case data(ROAR_VIO_CTL_SET_SSTREAM) 
     239    // FIXME: we should do some better error handling here: 
     240    if ( ROAR_STREAM(data)->dir != self->dir ) return -1; 
    193241    self->stream = data; 
    194242   break; 
     
    213261      return -1; 
    214262    } 
    215     return sio_setvol(self->handle, d) == 0 ? -1 : 0; 
     263    return sio_setvol(self->shandle, d) == 0 ? -1 : 0; 
    216264   break; 
    217265  default: 
  • roard/include/driver_sndio.h

    r2367 r2370  
    2727 
    2828struct driver_sndio { 
     29 int    dir; 
    2930 char * device; 
    30  struct sio_hdl * handle; 
     31 struct sio_hdl * shandle; 
     32 struct mio_hdl * mhandle; 
    3133 struct roar_audio_info info; 
    3234 int need_reopen; 
Note: See TracChangeset for help on using the changeset viewer.