Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/io/source_apple_audio.c

    r9209c79 r493b832  
    6161  aubio_source_apple_audio_t * s = AUBIO_NEW(aubio_source_apple_audio_t);
    6262
     63  if (path == NULL) {
     64    AUBIO_ERROR("source_apple_audio: Aborted opening null path\n");
     65    goto beach;
     66  }
     67
     68  if ( (sint_t)block_size <= 0 ) {
     69    AUBIO_ERROR("source_apple_audio: Can not open %s with null or negative block_size %d\n",
     70        path, block_size);
     71    goto beach;
     72  }
     73
     74  if ( (sint_t)samplerate < 0 ) {
     75    AUBIO_ERROR("source_apple_audio: Can not open %s with negative samplerate %d\n",
     76        path, samplerate);
     77    goto beach;
     78  }
     79
    6380  s->block_size = block_size;
    6481  s->samplerate = samplerate;
     82  s->path = path;
    6583
    6684  if ( aubio_source_apple_audio_open ( s, path ) ) {
     
    140158        "error in ExtAudioFileSetProperty (%s)\n", s->path,
    141159        getPrintableOSStatusError(errorstr, err));
    142 #if 1
     160#if 0
    143161  // print client and format descriptions
    144162  AUBIO_DBG("Opened %s\n", s->path);
     
    281299
    282300uint_t aubio_source_apple_audio_seek (aubio_source_apple_audio_t * s, uint_t pos) {
     301  OSStatus err = noErr;
     302  if ((sint_t)pos < 0) {
     303    AUBIO_ERROR("source_apple_audio: error while seeking in %s "
     304        "(can not seek at negative position %d)\n",
     305        s->path, pos);
     306    err = -1;
     307    goto beach;
     308  }
     309  // check if we are not seeking out of the file
     310  SInt64 fileLengthFrames = 0;
     311  UInt32 propSize = sizeof(fileLengthFrames);
     312  ExtAudioFileGetProperty(s->audioFile,
     313      kExtAudioFileProperty_FileLengthFrames, &propSize, &fileLengthFrames);
     314  // compute position in the source file, before resampling
     315  smpl_t ratio = s->source_samplerate * 1. / s->samplerate;
     316  SInt64 resampled_pos = (SInt64)ROUND( pos * ratio );
     317  if (resampled_pos > fileLengthFrames) {
     318    AUBIO_ERR("source_apple_audio: trying to seek in %s at pos %d, "
     319        "but file has only %d frames\n",
     320        s->path, pos, (uint_t)(fileLengthFrames / ratio));
     321    err = -1;
     322    goto beach;
     323  }
    283324  // after a short read, the bufferList size needs to resetted to prepare for a full read
    284325  AudioBufferList *bufferList = &s->bufferList;
    285326  bufferList->mBuffers[0].mDataByteSize = s->block_size * s->channels * sizeof (short);
    286   // compute position in the source file, before resampling
    287   smpl_t ratio = s->source_samplerate * 1. / s->samplerate;
    288   SInt64 resampled_pos = (SInt64)ROUND( pos * ratio );
    289   OSStatus err = ExtAudioFileSeek(s->audioFile, resampled_pos);
     327  // do the actual seek
     328  err = ExtAudioFileSeek(s->audioFile, resampled_pos);
    290329  if (err) {
    291330    char_t errorstr[20];
     
    294333        getPrintableOSStatusError(errorstr, err));
    295334  }
     335#if 0
     336  // check position after seek
     337  {
     338    SInt64 outFrameOffset = 0;
     339    err = ExtAudioFileTell(s->audioFile, &outFrameOffset);
     340    if (err) {
     341      char_t errorstr[20];
     342      AUBIO_ERROR("source_apple_audio: error while seeking %s at %d "
     343          "in ExtAudioFileTell (%s)\n", s->path, pos,
     344          getPrintableOSStatusError(errorstr, err));
     345    }
     346    AUBIO_DBG("source_apple_audio: asked seek at %d, tell got %d\n",
     347        pos, (uint_t)(outFrameOffset / ratio + .5));
     348  }
     349#endif
     350beach:
    296351  return err;
    297352}
Note: See TracChangeset for help on using the changeset viewer.