Ignore:
Timestamp:
Mar 26, 2003, 4:34:03 AM (17 years ago)
Author:
ranger
Message:

regen + esound puredarwin support (well... disable sound driver)

Location:
trunk/dports/audio/esound
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/dports/audio/esound/Portfile

    r2189 r2367  
    1 # $Id: Portfile,v 1.5 2003/03/09 04:14:20 ranger Exp $
     1# $Id: Portfile,v 1.6 2003/03/26 04:34:03 ranger Exp $
    22
    33PortSystem 1.0
     
    1313extract.sufx    .tar.bz2
    1414use_bzip2       yes
    15 patchfiles      patch-esound-darwin
     15patchfiles      patch-esound-darwin patch-esound-coreaudio
    1616depends_lib     lib:audiofile.0:audiofile
    1717checksums       md5 58bea6f744613da37a5970e1c18a04f8
     18
     19variant puredarwin {
     20                configure.args-append   --disable-local-sound
     21}
    1822
    1923long_description EsounD, the Enlightened Sound Daemon, is a server \
  • trunk/dports/audio/esound/files/patch-esound-darwin

    r2189 r2367  
    1 diff -Naur audio.c audio.c
    2 --- audio.c     Tue Aug 27 01:41:22 2002
    3 +++ audio.c     Fri Mar  7 18:33:43 2003
    4 @@ -41,6 +41,8 @@
    5  #  include "audio_mklinux.c"
    6  #elif defined(DRIVER_DART)
    7  #  include "audio_dart.c"
    8 +#elif defined(DRIVER_COREAUDIO)
    9 +#  include "audio_coreaudio.c"
    10  #else
    11  #  include "audio_none.c"
    12  #endif
    13 diff -Naur audio_coreaudio.c audio_coreaudio.c
    14 --- audio_coreaudio.c   Thu Jan  1 09:00:00 1970
    15 +++ audio_coreaudio.c   Fri Mar  7 18:07:52 2003
    16 @@ -0,0 +1,461 @@
    17 +
    18 +/*
    19 + * for CoreAudio
    20 + *
    21 + * If the playback/recording sound device is not stereo and its sample
    22 + * size is not float (32 bit), this will not work.
    23 + *
    24 + * Please let me know if there is such a case.
    25 + *
    26 + * Shawn Hsiao <phsiao@mac.com>
    27 + * Some enhancement by Masanori Sekino <msek@users.sourceforge.net>
    28 + */
    29 +
    30 +#include <CoreAudio/CoreAudio.h>
    31 +#include <limits.h>
    32 +#include <pthread.h>
    33 +
    34 +#define BUF_SIZE ESD_BUF_SIZE
    35 +
    36 +static AudioDeviceID gOutputDeviceID, gInputDeviceID;
    37 +
    38 +static float OutputDataBuf[BUF_SIZE];
    39 +static float InputDataBuf[BUF_SIZE];
    40 +static int OutputWroteSamples = 0;
    41 +static int InputReadSamples = 0;
    42 +
    43 +static pthread_mutex_t mutexOutput, mutexInput;
    44 +static pthread_cond_t condOutput, condInput;
    45 +
    46 +static int audioPlaybackStarted = 0, audioRecordStarted = 0;
    47 +static int coreaudio_has_output_device = 0;
    48 +static int coreaudio_has_input_device = 0;
    49 +static int num_ca_input_channel = 0;
    50 +static int coreaudio_init = 0;
    51 +
    52 +OSStatus PlaybackIOProc(AudioDeviceID inDevice,
    53 +                       const AudioTimeStamp *inNow,
    54 +                       const AudioBufferList *inInputData,
    55 +                       const AudioTimeStamp *inInputTime,
    56 +                       AudioBufferList *outOutputData,
    57 +                       const AudioTimeStamp *inOutputTime,
    58 +                       void *inClientData)
    59 +{
    60 +  float *bufPtr = outOutputData->mBuffers[0].mData;
    61 +  int i;
    62 +
    63 +  pthread_mutex_lock(&mutexOutput);
    64 +
    65 +  for (i = 0; i < OutputWroteSamples; i++)
    66 +    bufPtr[i] = OutputDataBuf[i];
    67 +  for ( ; i < BUF_SIZE; i++)
    68 +    bufPtr[i] = 0;
    69 +  OutputWroteSamples = 0;
    70 +
    71 +  pthread_mutex_unlock(&mutexOutput);
    72 +  pthread_cond_signal(&condOutput);
    73 +
    74 +  return (kAudioHardwareNoError);
    75 +}
    76 +
    77 +OSStatus RecordIOProc(AudioDeviceID inDevice,
    78 +                     const AudioTimeStamp *inNow,
    79 +                     const AudioBufferList *inInputData,
    80 +                     const AudioTimeStamp *inInputTime,
    81 +                     AudioBufferList *outOutputData,
    82 +                     const AudioTimeStamp *inOutputTime,
    83 +                     void *inClientData)
    84 +{
    85 +  float *bufPtr = inInputData->mBuffers[0].mData;
    86 +  int i;
    87 +
    88 +  pthread_mutex_lock(&mutexInput);
    89 +
    90 +  if (num_ca_input_channel == 2) {
    91 +    for (i = 0; i < BUF_SIZE; i++)
    92 +      InputDataBuf[i] = bufPtr[i];
    93 +  }
    94 +  else {
    95 +    for (i = 0; i < BUF_SIZE/2; i++)
    96 +      InputDataBuf[2*i] = bufPtr[i];
    97 +  }
    98 +  InputReadSamples = 0;
    99 +
    100 +  pthread_mutex_unlock(&mutexInput);
    101 +  pthread_cond_signal(&condInput);
    102 +
    103 +  return (kAudioHardwareNoError);
    104 +}
    105 +
    106 +#define ARCH_esd_audio_devices
    107 +const char *esd_audio_devices()
    108 +{
    109 +    return "coreaudio API only";
    110 +}
    111 +
    112 +/*
    113 + * This is called to reset the device status.
    114 + * Returns -2 to indicate the device failed to initialize;
    115 + * returns  -1 means any of rate/size/{mono,stereo} mismatched.
    116 + */
    117 +#define ARCH_esd_audio_open
    118 +int esd_audio_open()
    119 +{
    120 +#define LEN_DEVICE_NAME 128
    121 +  OSStatus status;
    122 +  UInt32 propertySize, bufferByteCount;
    123 +  char deviceName[LEN_DEVICE_NAME];
    124 +  struct AudioStreamBasicDescription streamDesc;
    125 +  int rval;
    126 +
    127 +  /*
    128 +   * We only need to do this once, the rest are taken cared by
    129 +   * disable/enable calback.
    130 +   */
    131 +  if (coreaudio_init) {
    132 +    return (0);
    133 +  }
    134 +
    135 +  /********************** playback section ***************************/
    136 +  /* get default output device */
    137 +  propertySize = sizeof(gOutputDeviceID);
    138 +  status = AudioHardwareGetProperty(kAudioHardwarePropertyDefaultOutputDevice,
    139 +                                   &propertySize,
    140 +                                   &gOutputDeviceID);
    141 +  if (status) {
    142 +    fprintf(stderr, "get default output device failed, status = %d\n",
    143 +           (int)status);
    144 +    return (-2);
    145 +  }
    146 +
    147 +  if (gOutputDeviceID != kAudioDeviceUnknown) {
    148 +    /* got default output device */
    149 +    coreaudio_has_output_device = 1;
    150 +
    151 +    /* get output device name */
    152 +    propertySize = sizeof(char)*LEN_DEVICE_NAME;
    153 +    status = AudioDeviceGetProperty(gOutputDeviceID,
    154 +                                   1,
    155 +                                   0,
    156 +                                   kAudioDevicePropertyDeviceName,
    157 +                                   &propertySize,
    158 +                                   deviceName);
    159 +    if (status) {
    160 +      fprintf(stderr, "get device name failed, status = %d\n",
    161 +             (int)status);
    162 +      return (-2);
    163 +    }
    164 +
    165 +    /* get output format */
    166 +    propertySize = sizeof(struct AudioStreamBasicDescription);
    167 +    status = AudioDeviceGetProperty(gOutputDeviceID,
    168 +                                   1,
    169 +                                   0,
    170 +                                   kAudioDevicePropertyStreamFormat,
    171 +                                   &propertySize,
    172 +                                   &streamDesc);
    173 +    if (status) {
    174 +      fprintf(stderr, "get device property failed, status = %d\n",
    175 +             (int)status);
    176 +      return (-2);
    177 +    }
    178 +
    179 +    if ((streamDesc.mSampleRate != 44100.0) ||
    180 +        (streamDesc.mFormatID != kAudioFormatLinearPCM) ||
    181 +       !(streamDesc.mFormatFlags & kLinearPCMFormatFlagIsFloat) ||
    182 +        (streamDesc.mChannelsPerFrame != 2))
    183 +    {
    184 +      fprintf (stderr, "unsupported device.\n");
    185 +      return (-2);
    186 +    }
    187 +
    188 +    /* set buffer size */
    189 +    bufferByteCount = BUF_SIZE * sizeof(float);
    190 +    propertySize = sizeof(bufferByteCount);
    191 +    status = AudioDeviceSetProperty(gOutputDeviceID,
    192 +                                    0,
    193 +                                    0,
    194 +                                    0,
    195 +                                    kAudioDevicePropertyBufferSize,
    196 +                                    propertySize,
    197 +                                    &bufferByteCount);
    198 +    if (status) {
    199 +      fprintf(stderr, "set device property failed, status = %d\n",
    200 +              (int)status);
    201 +    }
    202 +
    203 +    fprintf(stderr, "using device %s for output:\n", deviceName);
    204 +    fprintf(stderr, "\twith sample rate %f, %ld channels and %ld-bit sample\n",
    205 +           streamDesc.mSampleRate,
    206 +           streamDesc.mChannelsPerFrame,
    207 +           streamDesc.mBitsPerChannel);
    208 +
    209 +    rval = pthread_mutex_init(&mutexOutput, NULL);
    210 +    if (rval) {
    211 +      fprintf(stderr, "mutex init failed\n");
    212 +      return (-1);
    213 +    }
    214 +    rval = pthread_cond_init(&condOutput, NULL);
    215 +    if (rval) {
    216 +      fprintf(stderr, "condition init failed\n");
    217 +      return (-1);
    218 +    }
    219 +
    220 +    /* Registers PlaybackIOProc with the device without activating it. */
    221 +    status = AudioDeviceAddIOProc(gOutputDeviceID, PlaybackIOProc, (void *)1);
    222 +  }
    223 +
    224 +  /********************** record section ***************************/
    225 +  /* get default input device */
    226 +  propertySize = sizeof(gInputDeviceID);
    227 +  status = AudioHardwareGetProperty(kAudioHardwarePropertyDefaultInputDevice,
    228 +                                   &propertySize,
    229 +                                   &gInputDeviceID);
    230 +  if (status) {
    231 +    fprintf(stderr, "get default input device failed, status = %d\n",
    232 +           (int)status);
    233 +    return (-2);
    234 +  }
    235 +
    236 +  if (gInputDeviceID != kAudioDeviceUnknown) {
    237 +    /* got default input device */
    238 +    coreaudio_has_input_device = 1;
    239 +
    240 +    /* get input device name */
    241 +    propertySize = sizeof(char)*64;
    242 +    status = AudioDeviceGetProperty(gInputDeviceID,
    243 +                                   1,
    244 +                                   1,
    245 +                                   kAudioDevicePropertyDeviceName,
    246 +                                   &propertySize,
    247 +                                   deviceName);
    248 +    if (status) {
    249 +      fprintf(stderr, "get device name failed, status = %d\n",
    250 +             (int)status);
    251 +      return (-2);
    252 +    }
    253 +
    254 +    /* get input format */
    255 +    propertySize = sizeof(struct AudioStreamBasicDescription);
    256 +    status = AudioDeviceGetProperty(gInputDeviceID,
    257 +                                   1,
    258 +                                   1,
    259 +                                   kAudioDevicePropertyStreamFormat,
    260 +                                   &propertySize,
    261 +                                   &streamDesc);
    262 +    if (status) {
    263 +      fprintf(stderr, "get device property failed, status = %d\n",
    264 +             (int)status);
    265 +      return (-2);
    266 +    }
    267 +
    268 +    if ((streamDesc.mSampleRate != 44100.0) ||
    269 +        (streamDesc.mFormatID != kAudioFormatLinearPCM) ||
    270 +       !(streamDesc.mFormatFlags & kLinearPCMFormatFlagIsFloat) ||
    271 +        (streamDesc.mChannelsPerFrame != 2 &&
    272 +        streamDesc.mChannelsPerFrame != 1))
    273 +    {
    274 +      fprintf (stderr, "unsupported device.\n");
    275 +      return (-2);
    276 +    }
    277 +
    278 +    num_ca_input_channel = streamDesc.mChannelsPerFrame;
    279 +
    280 +    /* set buffer size */
    281 +    bufferByteCount = BUF_SIZE / (2/num_ca_input_channel) * sizeof(float);
    282 +    propertySize = sizeof(bufferByteCount);
    283 +    status = AudioDeviceSetProperty(gInputDeviceID,
    284 +                                    0,
    285 +                                    0,
    286 +                                    1,
    287 +                                    kAudioDevicePropertyBufferSize,
    288 +                                    propertySize,
    289 +                                    &bufferByteCount);
    290 +    if (status) {
    291 +      fprintf(stderr, "set device property failed, status = %d\n",
    292 +              (int)status);
    293 +    }
    294 +
    295 +    fprintf(stderr, "using device %s for input:\n", deviceName);
    296 +    fprintf(stderr, "\twith sample rate %f, %ld channels and %ld-bit sample\n",
    297 +           streamDesc.mSampleRate,
    298 +           streamDesc.mChannelsPerFrame,
    299 +           streamDesc.mBitsPerChannel);
    300 +
    301 +    rval = pthread_mutex_init(&mutexInput, NULL);
    302 +    if (rval) {
    303 +      fprintf(stderr, "mutex init failed\n");
    304 +      return (-1);
    305 +    }
    306 +    rval = pthread_cond_init(&condInput, NULL);
    307 +    if (rval) {
    308 +      fprintf(stderr, "condition init failed\n");
    309 +      return (-1);
    310 +    }
    311 +
    312 +    /* Registers PlaybackIOProc with the device without activating it. */
    313 +    status = AudioDeviceAddIOProc(gInputDeviceID, RecordIOProc, (void *)1);
    314 +  }
    315 +
    316 +  if (!coreaudio_has_output_device) {
    317 +    fprintf(stderr, "unknown output device.\n");
    318 +    return (-2);
    319 +  }
    320 +  /* Allow lack of recording device */
    321 +  /*
    322 +  if (!coreaudio_has_input_device) {
    323 +    fprintf(stderr, "unknown input device.\n");
    324 +    return (-2);
    325 +  }
    326 +  */
    327 +
    328 +  /* Indicates the initialization is done */
    329 +  coreaudio_init = 1;
    330 +
    331 +  esd_audio_fd = 0; /* this is meaningless anyway */
    332 +
    333 +  return 0;
    334 +}
    335 +
    336 +/*
    337 + * This is called to reset the device status.
    338 + * (before calls esd_audio_open again)
    339 + */
    340 +#define ARCH_esd_audio_close
    341 +void esd_audio_close()
    342 +{
    343 +  OSStatus status;
    344 +
    345 +  /* deactivate both of them */
    346 +  if (coreaudio_has_output_device && audioPlaybackStarted) {
    347 +    status = AudioDeviceStop(gOutputDeviceID, PlaybackIOProc);
    348 +    audioPlaybackStarted = 0;
    349 +  }
    350 +
    351 +  if (coreaudio_has_input_device && audioRecordStarted) {
    352 +    status = AudioDeviceStop(gInputDeviceID, RecordIOProc);
    353 +    audioRecordStarted = 0;
    354 +  }
    355 +
    356 +  return;
    357 +}
    358 +
    359 +
    360 +#define ARCH_esd_audio_pause
    361 +void esd_audio_pause()
    362 +{
    363 +  OSStatus status;
    364 +
    365 +  if (coreaudio_has_output_device && audioPlaybackStarted) {
    366 +    status = AudioDeviceStop(gOutputDeviceID, PlaybackIOProc);
    367 +    audioPlaybackStarted = 0;
    368 +  }
    369 +
    370 +  if (coreaudio_has_input_device && audioRecordStarted) {
    371 +    status = AudioDeviceStop(gInputDeviceID, RecordIOProc);
    372 +    audioRecordStarted = 0;
    373 +  }
    374 +
    375 +  return;
    376 +}
    377 +
    378 +
    379 +#define ARCH_esd_audio_write
    380 +/*******************************************************************/
    381 +/* dump a buffer to the sound device */
    382 +int esd_audio_write( void *buffer, int buf_size )
    383 +{
    384 +  OSStatus status;
    385 +  float scale = 1.0 / SHRT_MAX;
    386 +  int remain_to_write = buf_size;
    387 +
    388 +  if (!coreaudio_has_output_device)
    389 +    return -1;
    390 +
    391 +  if (!audioPlaybackStarted) {
    392 +    status = AudioDeviceStart(gOutputDeviceID, PlaybackIOProc);
    393 +    audioPlaybackStarted = 1;
    394 +  }
    395 +
    396 +  while (remain_to_write)
    397 +  {
    398 +    pthread_mutex_lock(&mutexOutput);
    399 +
    400 +    while(OutputWroteSamples == BUF_SIZE)
    401 +      pthread_cond_wait(&condOutput, &mutexOutput);
    402 +
    403 +    {
    404 +      short *src_data = (short *)buffer + (buf_size - remain_to_write) / sizeof(short);
    405 +      float *dst_data = OutputDataBuf + OutputWroteSamples;
    406 +      int src_samples = remain_to_write / sizeof(short);
    407 +      int dst_samples = BUF_SIZE - OutputWroteSamples;
    408 +      int n = (dst_samples < src_samples) ? dst_samples : src_samples;
    409 +      int i;
    410 +
    411 +      for (i = 0; i < n; i++)
    412 +        dst_data[i] = scale * src_data[i];
    413 +
    414 +      OutputWroteSamples += n;
    415 +      remain_to_write -= n * sizeof(short);
    416 +    }
    417 +
    418 +    pthread_mutex_unlock(&mutexOutput);
    419 +  }
    420 +
    421 +  return (buf_size);
    422 +}
    423 +
    424 +#define ARCH_esd_audio_read
    425 +/*******************************************************************/
    426 +/* read a chunk from the sound device */
    427 +int esd_audio_read( void *buffer, int buf_size )
    428 +{
    429 +  OSStatus status;
    430 +  float scale = SHRT_MAX;
    431 +  int remain_to_read = buf_size;
    432 +
    433 +  if (!coreaudio_has_input_device)
    434 +    return -1;
    435 +
    436 +  if (!audioRecordStarted) {
    437 +    status = AudioDeviceStart(gInputDeviceID, RecordIOProc);
    438 +    audioRecordStarted = 1;
    439 +  }
    440 +
    441 +  while (remain_to_read)
    442 +  {
    443 +    pthread_mutex_lock(&mutexInput);
    444 +
    445 +    while(InputReadSamples == BUF_SIZE)
    446 +      pthread_cond_wait(&condInput, &mutexInput);
    447 +
    448 +    {
    449 +      float *src_data = InputDataBuf + InputReadSamples;
    450 +      short *dst_data = (short *)buffer + (buf_size - remain_to_read) / sizeof(short);
    451 +      int src_samples = BUF_SIZE - InputReadSamples;
    452 +      int dst_samples = remain_to_read / sizeof(short);
    453 +      int n = (dst_samples < src_samples) ? dst_samples : src_samples;
    454 +      int i;
    455 +
    456 +      for (i = 0; i < n; i++)
    457 +        dst_data[i] = (short)(scale * src_data[i]);
    458 +
    459 +      InputReadSamples += n;
    460 +      remain_to_read -= n * sizeof(short);
    461 +    }
    462 +
    463 +    pthread_mutex_unlock(&mutexInput);
    464 +  }
    465 +
    466 +  return (buf_size);
    467 +}
    468 +
    469 +
    470 +#define ARCH_esd_audio_flush
    471 +/*******************************************************************/
    472 +/* flush the audio buffer */
    473 +void esd_audio_flush()
    474 +{
    475 +  /* nothing needed */
    476 +  return;
    477 +}
    478 diff -Naur config.h.in config.h.in
    479 --- config.h.in Tue Aug 27 01:45:48 2002
    480 +++ config.h.in Fri Mar  7 18:30:51 2003
    481 @@ -43,6 +43,7 @@
    482  #undef DRIVER_NEWALSA
    483  #undef DRIVER_ALSA_09
    484  #undef DRIVER_DART
    485 +#undef DRIVER_COREAUDIO
    486  #undef DRIVER_NONE
    487  #undef HAVE_INET_ATON
    488  #undef HAVE_NANOSLEEP
    489 diff -Naur configure configure
    490 --- configure   Tue Aug 27 02:18:46 2002
    491 +++ configure   Fri Mar  7 18:01:54 2003
    492 @@ -6915,6 +6915,14 @@
    493  EOF
    494  
    495        ;;
    496 +   darwin*)
    497 +      found_sound=yes
    498 +      cat >> confdefs.h <<\EOF
    499 +#define DRIVER_COREAUDIO 1
    500 +EOF
    501 +
    502 +      SOUND_LIBS="-Wl,-framework -Wl,CoreAudio"
    503 +      ;;
    504     esac
    505  
    506     if test "${ac_cv_header_dmedia_audio_h}" = "yes"; then
    507 diff -Naur esd.c esd.c
    508 --- esd.c       Tue Aug 27 01:41:24 2002
    509 +++ esd.c       Fri Mar  7 17:56:55 2003
    510 @@ -21,6 +21,13 @@
    511  #define gethostbyname2(host, family) gethostbyname((host))
    512  #endif /* HAVE_GETHOSTBYNAME2 */
    513  
    514 +#if defined (__APPLE__)
    515 +#include <mach/mach.h>
    516 +#include <mach/thread_policy.h>
    517 +#include <sys/param.h>
    518 +#include <sys/sysctl.h>
    519 +#endif
    520 +
    521  /*******************************************************************/
    522  /* esd.c - prototypes */
    523  void set_audio_buffer( void *buf, esd_format_t format, int magl, int magr,
    524 @@ -517,6 +524,29 @@
    525  
    526      int default_format = ESD_BITS16 | ESD_STEREO;
    527      /* end test scaffolding parameters */
    528 +
    529 +#if defined (__APPLE__)
    530 +    /* get realtime priority */
    531 +    {
    532 +       struct thread_time_constraint_policy ttcpolicy;
    533 +       int bus_speed, mib [2] = { CTL_HW, HW_BUS_FREQ };
    534 +       size_t len;   
    535 +
    536 +       len = sizeof (bus_speed);
    537 +       sysctl (mib, 2, &bus_speed, &len, NULL, 0);
    538 +
    539 +       /* Is it enough? */
    540 +       ttcpolicy.period = bus_speed / 120;
    541 +       ttcpolicy.computation = bus_speed / 2400;
    542 +       ttcpolicy.constraint = bus_speed / 1200;
    543 +       ttcpolicy.preemptible = 1;
    544 +
    545 +       thread_policy_set (mach_thread_self (),
    546 +                          THREAD_TIME_CONSTRAINT_POLICY,
    547 +                          (int*)&ttcpolicy,
    548 +                          THREAD_TIME_CONSTRAINT_POLICY_COUNT);
    549 +    }
    550 +#endif
    551  
    552      programname = *argv;
    553  
    5541diff -Naur esd.conf esd.conf
    5552--- esd.conf    Tue Jun  4 23:30:47 2002
Note: See TracChangeset for help on using the changeset viewer.