Changeset 3150:f35a31dddc8d in roaraudio


Ignore:
Timestamp:
01/15/10 15:56:22 (10 years ago)
Author:
phi
Branch:
default
Message:

wrote most of the mixer stuff

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libroaross/libroaross.c

    r3149 r3150  
    9696} _os; 
    9797 
     98static struct { 
     99 struct { 
     100  int volume; 
     101  int pcm; 
     102  int line; 
     103  int line1; 
     104  int line2; 
     105  int line3; 
     106  int digital1; 
     107  int digital2; 
     108  int digital3; 
     109 } sid; 
     110} _mix_settings = { 
     111                   .sid = { 
     112                           .volume   = -1, 
     113                           .pcm      = -1, 
     114                           .line     =  0, 
     115                           .line1    =  1, 
     116                           .line2    =  2, 
     117                           .line3    =  3, 
     118                           .digital1 =  1, 
     119                           .digital2 =  2, 
     120                           .digital3 =  3 
     121                          } 
     122                  }; 
     123 
    98124static struct pointer { 
    99125 int fh; 
     
    253279  int type; 
    254280 } * ptr = NULL, p[] = { 
    255   {"/dev/dsp", HT_STREAM}, 
     281  {"/dev/dsp",   HT_STREAM}, 
     282  {"/dev/mixer", HT_MIXER}, 
    256283  {NULL, HT_NONE}, 
    257284 }; 
     
    320347 handle->stream_opened++; 
    321348 
     349 _mix_settings.sid.pcm = roar_stream_get_id(&(handle->stream)); 
     350 
    322351 return 0; 
    323352} 
     
    416445 
    417446 return format; 
     447} 
     448 
     449// ------------------------------------- 
     450// mixer ioctls: 
     451// ------------------------------------- 
     452 
     453static int _ioctl_mixer (struct handle * handle, long unsigned int req, int * ip) { 
     454 int channels; 
     455 struct roar_mixer_settings mixer; 
     456 char * name = NULL; 
     457 int o_w    = 0; 
     458 int o_sid  = -1; 
     459 
     460 switch (req) { 
     461#if 0 
     462  case SNDCTL_MIX_DESCRIPTION: name = "SNDCTL_MIX_DESCRIPTION"; break; 
     463  case SNDCTL_MIX_ENUMINFO:    name = "SNDCTL_MIX_ENUMINFO";    break; 
     464  case SNDCTL_MIX_EXTINFO:     name = "SNDCTL_MIX_EXTINFO";     break; 
     465  case SNDCTL_MIX_NREXT:       name = "SNDCTL_MIX_NREXT";       break; 
     466  case SNDCTL_MIX_NRMIX:       name = "SNDCTL_MIX_NRMIX";       break; 
     467  case SNDCTL_MIX_READ:        name = "SNDCTL_MIX_READ";        break; 
     468  case SNDCTL_MIX_WRITE:       name = "SNDCTL_MIX_WRITE";       break; 
     469#endif 
     470  case SOUND_MIXER_READ_DEVMASK: name = "SOUND_MIXER_READ_DEVMASK"; break; 
     471  case SOUND_MIXER_READ_PCM:     name = "SOUND_MIXER_READ_PCM";     break; 
     472  case SOUND_MIXER_WRITE_PCM:    name = "SOUND_MIXER_WRITE_PCM";    break; 
     473 } 
     474 if ( name != NULL ) { 
     475  ROAR_DBG("_ioctl_mixer(handle=%p, req=%lu, ip=%p): unspported mixer command %s", handle, req, ip, name); 
     476  ROAR_DBG("_ioctl_mixer(handle=%p, req=%lu, ip=%p) = -1 // errno = ENOSYS", handle, req, ip); 
     477  errno = ENOSYS; 
     478  return -1; 
     479 } 
     480 
     481 switch (req) { 
     482  case SOUND_MIXER_READ_VOLUME:    o_w = 0; o_sid = _mix_settings.sid.volume;   break; 
     483  case SOUND_MIXER_READ_PCM:       o_w = 0; o_sid = _mix_settings.sid.pcm;      break; 
     484  case SOUND_MIXER_READ_LINE:      o_w = 0; o_sid = _mix_settings.sid.line;     break; 
     485  case SOUND_MIXER_READ_LINE1:     o_w = 0; o_sid = _mix_settings.sid.line1;    break; 
     486  case SOUND_MIXER_READ_LINE2:     o_w = 0; o_sid = _mix_settings.sid.line2;    break; 
     487  case SOUND_MIXER_READ_LINE3:     o_w = 0; o_sid = _mix_settings.sid.line3;    break; 
     488#if 0 
     489  case SOUND_MIXER_READ_DIGITAL1:  o_w = 0; o_sid = _mix_settings.sid.digital1; break; 
     490  case SOUND_MIXER_READ_DIGITAL2:  o_w = 0; o_sid = _mix_settings.sid.digital2; break; 
     491  case SOUND_MIXER_READ_DIGITAL3:  o_w = 0; o_sid = _mix_settings.sid.digital3; break; 
     492#endif 
     493  case SOUND_MIXER_WRITE_VOLUME:   o_w = 1; o_sid = _mix_settings.sid.volume;   break; 
     494  case SOUND_MIXER_WRITE_PCM:      o_w = 1; o_sid = _mix_settings.sid.pcm;      break; 
     495  case SOUND_MIXER_WRITE_LINE:     o_w = 1; o_sid = _mix_settings.sid.line;     break; 
     496  case SOUND_MIXER_WRITE_LINE1:    o_w = 1; o_sid = _mix_settings.sid.line1;    break; 
     497  case SOUND_MIXER_WRITE_LINE2:    o_w = 1; o_sid = _mix_settings.sid.line2;    break; 
     498  case SOUND_MIXER_WRITE_LINE3:    o_w = 1; o_sid = _mix_settings.sid.line3;    break; 
     499#if 0 
     500  case SOUND_MIXER_WRITE_DIGITAL1: o_w = 1; o_sid = _mix_settings.sid.digital1; break; 
     501  case SOUND_MIXER_WRITE_DIGITAL2: o_w = 1; o_sid = _mix_settings.sid.digital2; break; 
     502  case SOUND_MIXER_WRITE_DIGITAL3: o_w = 1; o_sid = _mix_settings.sid.digital3; break; 
     503#endif 
     504 } 
     505 if ( o_sid != -1 ) { 
     506  // set/get volume 
     507  if ( o_w ) { 
     508   mixer.scale    = 65535; 
     509   mixer.mixer[0] = ( *ip       & 0xFF)*65535/50; 
     510   mixer.mixer[1] = ((*ip >> 8) & 0xFF)*65535/50; 
     511   if ( roar_set_vol(&(handle->session->con), o_sid, &mixer, 2) == -1 ) { 
     512    errno = ENOSYS; 
     513    return -1; 
     514   } 
     515   return 0; 
     516  } else { 
     517   if ( roar_get_vol(&(handle->session->con), o_sid, &mixer, &channels) == -1 ) { 
     518    errno = ENOSYS; 
     519    return -1; 
     520   } 
     521   *ip = ((50*mixer.mixer[0])/mixer.scale) | (((50*mixer.mixer[0])/mixer.scale)<<8); 
     522   return 0; 
     523  } 
     524 } 
     525 
     526 switch (req) { 
     527  case SOUND_MIXER_READ_DEVMASK: 
     528    *ip = 0; 
     529 
     530    if ( _mix_settings.sid.volume != -1 ) 
     531     *ip |= SOUND_MASK_VOLUME; 
     532    if ( _mix_settings.sid.pcm != -1 ) 
     533     *ip |= SOUND_MASK_PCM; 
     534    if ( _mix_settings.sid.line != -1 ) 
     535     *ip |= SOUND_MASK_LINE; 
     536    if ( _mix_settings.sid.line1 != -1 ) 
     537     *ip |= SOUND_MASK_LINE1; 
     538    if ( _mix_settings.sid.line2 != -1 ) 
     539     *ip |= SOUND_MASK_LINE2; 
     540    if ( _mix_settings.sid.line3 != -1 ) 
     541     *ip |= SOUND_MASK_LINE3; 
     542    if ( _mix_settings.sid.digital1 != -1 ) 
     543     *ip |= SOUND_MASK_DIGITAL1; 
     544    if ( _mix_settings.sid.digital2 != -1 ) 
     545     *ip |= SOUND_MASK_DIGITAL2; 
     546    if ( _mix_settings.sid.digital3 != -1 ) 
     547     *ip |= SOUND_MASK_DIGITAL3; 
     548 
     549    return 0; 
     550   break; 
     551 } 
     552 
     553 ROAR_DBG("_ioctl_mixer(handle=%p, req=%lu, ip=%p): unknown mixer CTL", handle, req, ip); 
     554 ROAR_DBG("_ioctl_mixer(handle=%p, req=%lu, ip=%p) = -1 // errno = ENOSYS", handle, req, ip); 
     555 errno = ENOSYS; 
     556 return -1; 
    418557} 
    419558 
     
    518657 _init(); 
    519658 
    520  ROAR_DBG("ioctl(__fd=%i, __request=%lu) = ?", __fd, (long unsigned int) __request); 
     659// ROAR_DBG("ioctl(__fd=%i, __request=%lu) = ?", __fd, (long unsigned int) __request); 
    521660 
    522661 va_start (args, __request); 
     
    524663 va_end (args); 
    525664 
    526  ROAR_DBG("ioctl(__fd=%i, __request=%lu): argp=%p", __fd, (long unsigned int) __request, argp); 
     665// ROAR_DBG("ioctl(__fd=%i, __request=%lu): argp=%p", __fd, (long unsigned int) __request, argp); 
    527666 
    528667 if ( (pointer = _get_pointer_by_fh(__fd)) != NULL ) { 
    529668  ip = argp; 
    530   ROAR_DBG("ioctl(__fd=%i, __request=%lu): ip=%p", __fd, (long unsigned int) __request, ip); 
     669//  ROAR_DBG("ioctl(__fd=%i, __request=%lu): ip=%p", __fd, (long unsigned int) __request, ip); 
    531670  switch ((handle = pointer->handle)->type) { 
    532671   case HT_STREAM: 
     
    547686       break; 
    548687      case SNDCTL_DSP_GETFMTS: 
    549         ROAR_DBG("ioctl(__fd=%i, __request=%lu): ip=%p", __fd, (long unsigned int) __request, ip); 
     688//        ROAR_DBG("ioctl(__fd=%i, __request=%lu): ip=%p", __fd, (long unsigned int) __request, ip); 
    550689        *ip = _ioctl_stream_format_list(); 
    551690        return 0; 
     
    558697    break; 
    559698   case HT_MIXER: 
    560      errno = ENOSYS; 
    561      return -1; 
     699     return _ioctl_mixer(handle, __request, ip); 
    562700    break; 
    563701   default: 
     702     ROAR_DBG("ioctl(__fd=%i, __request=%lu): unknown handle type: no ioctl()s supported", __fd, (long unsigned int) __request); 
     703     ROAR_DBG("ioctl(__fd=%i, __request=%lu) = -1 // errno = ENOSYS", __fd, (long unsigned int) __request); 
    564704     errno = EINVAL; 
    565705     return -1; 
Note: See TracChangeset for help on using the changeset viewer.