Changeset 5056:b31e60545552 in roaraudio for roard/driver_portaudio.c


Ignore:
Timestamp:
06/02/11 23:13:11 (13 years ago)
Author:
phi
Branch:
default
Phase:
public
Message:

support auto reconf bits=32->16 in case not supported (See: #48)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • roard/driver_portaudio.c

    r5012 r5056  
    3535 long flags = PABLIO_WRITE; 
    3636#elif defined(ROAR_HAVE_PA19_VERSION_19) 
     37 PaStreamParameters params; 
     38#endif 
    3739 PaError err; 
    38  PaStreamParameters params; 
    39 #endif 
     40 int autoconfig = 0; 
    4041 
    4142 if ( fh != -1 ) 
    4243  return -1; 
     44 
     45 if ( sstream != NULL ) { 
     46  autoconfig = streams_get_flag(ROAR_STREAM(sstream)->id, ROAR_FLAG_AUTOCONF); 
     47 } 
    4348 
    4449 switch (info->bits) { 
     
    5661      break; 
    5762     default: 
    58        return -1; 
     63       if ( autoconfig ) { 
     64        info->codec = ROAR_CODEC_DEFAULT; 
     65        fmt = paInt8; 
     66       } else { 
     67        return -1; 
     68       } 
    5969      break; 
    6070    } 
    6171   break; 
    6272  case 16: 
    63     if ( info->codec != ROAR_CODEC_DEFAULT ) 
    64      return -1; 
     73    if ( info->codec != ROAR_CODEC_DEFAULT ) { 
     74     if ( autoconfig ) { 
     75      info->codec = ROAR_CODEC_DEFAULT; 
     76     } else { 
     77      return -1; 
     78     } 
     79    } 
    6580    fmt = paInt16; 
    6681   break; 
    6782#ifdef paPackedInt24 
    6883  case 24: 
    69     if ( info->codec != ROAR_CODEC_DEFAULT ) 
     84    if ( info->codec != ROAR_CODEC_DEFAULT ) { 
     85     if ( autoconfig ) { 
     86      info->codec = ROAR_CODEC_DEFAULT; 
     87     } else { 
     88      return -1; 
     89     } 
     90    } 
     91    fmt = paPackedInt24; 
     92   break; 
     93#endif 
     94  case 32: 
     95    if ( info->codec != ROAR_CODEC_DEFAULT ) { 
     96     if ( autoconfig ) { 
     97      info->codec = ROAR_CODEC_DEFAULT; 
     98     } else { 
     99      return -1; 
     100     } 
     101    } 
     102    fmt = paInt32; 
     103   break; 
     104  default: 
     105    if ( autoconfig ) { 
     106     info->codec = ROAR_CODEC_DEFAULT; 
     107     info->bits  = 16; 
     108     fmt = paInt16; 
     109    } else { 
    70110     return -1; 
    71     fmt = paPackedInt24; 
    72    break; 
    73 #endif 
    74   case 32: 
    75     if ( info->codec != ROAR_CODEC_DEFAULT ) 
    76      return -1; 
    77     fmt = paInt32; 
    78    break; 
    79   default: 
    80     return -1; 
     111    } 
     112   break; 
    81113 } 
    82114 
     
    100132  case 2: flags |= PABLIO_STEREO; break; 
    101133  default: 
    102     roar_mm_free(self); 
    103     Pa_Terminate(); 
    104     return -1; 
    105  } 
    106  
    107  if ( OpenAudioStream(&(self->ostream), info->rate, fmt, flags) != paNoError ) { 
     134    if ( autoconfig ) { 
     135     info->channels = 2; 
     136     flags |= PABLIO_STEREO; 
     137    } else { 
     138     roar_mm_free(self); 
     139     Pa_Terminate(); 
     140     return -1; 
     141    } 
     142 } 
     143 
     144 err = OpenAudioStream(&(self->ostream), info->rate, fmt, flags); 
     145 
     146 if ( err != paNoError && autoconfig ) { 
     147  if ( (flags & PABLIO_MONO) == PABLIO_MONO ) { 
     148   flags -= PABLIO_MONO; 
     149   flags |= PABLIO_STEREO; 
     150   info->channels = 2; 
     151  } 
     152  fmt         = paInt16; 
     153  info->codec = ROAR_CODEC_DEFAULT; 
     154  info->bits  = 16; 
     155 
     156  err = OpenAudioStream(&(self->ostream), info->rate, fmt, flags); 
     157 } 
     158 
     159 if ( err != paNoError ) { 
    108160  roar_mm_free(self); 
    109161  Pa_Terminate(); 
     
    133185                    ); 
    134186 
     187 if ( err != paNoError && autoconfig ) { 
     188  params.sampleFormat = paInt16; 
     189  params.channelCount = 2; 
     190  info->codec         = ROAR_CODEC_DEFAULT; 
     191  info->bits          = 16; 
     192  info->channels      = 2; 
     193 
     194  err = Pa_OpenStream(&(self->stream), 
     195                      NULL, 
     196                      &params, 
     197                      info->rate, 
     198                      128 /*FIXME:frames*/, 
     199                      paClipOff, 
     200                      NULL, 
     201                      NULL 
     202                     ); 
     203 } 
     204 
    135205 if ( err != paNoError ) { 
    136206  ROAR_ERR("driver_portaudio_open(*): Could not open PortAudio device: \"%s\".", Pa_GetErrorText(err)); 
Note: See TracChangeset for help on using the changeset viewer.