src/audio/macosx/SDL_coreaudio.c
changeset 3636 e474a820daeb
parent 3617 023aa9699baa
child 3637 8a46b3eab813
equal deleted inserted replaced
3635:5ea5e4e6103f 3636:e474a820daeb
   256     AudioBuffer *abuf;
   256     AudioBuffer *abuf;
   257     UInt32 remaining, len;
   257     UInt32 remaining, len;
   258     void *ptr;
   258     void *ptr;
   259     UInt32 i;
   259     UInt32 i;
   260 
   260 
   261     /* Is there ever more than one buffer, and what do you do with it? */
       
   262     if (ioDataList->mNumberBuffers != 1) {
       
   263         return noErr;
       
   264     }
       
   265 
       
   266     /* Only do anything if audio is enabled and not paused */
   261     /* Only do anything if audio is enabled and not paused */
   267     if (!this->enabled || this->paused) {
   262     if (!this->enabled || this->paused) {
   268         for (i = 0; i < ioData->mNumberBuffers; i++) {
   263         for (i = 0; i < ioData->mNumberBuffers; i++) {
   269             abuf = &ioData->mBuffers[i];
   264             abuf = &ioData->mBuffers[i];
   270             SDL_memset(abuf->mData, this->spec.silence, abuf->mDataByteSize);
   265             SDL_memset(abuf->mData, this->spec.silence, abuf->mDataByteSize);
   283     for (i = 0; i < ioData->mNumberBuffers; i++) {
   278     for (i = 0; i < ioData->mNumberBuffers; i++) {
   284         abuf = &ioData->mBuffers[i];
   279         abuf = &ioData->mBuffers[i];
   285         remaining = abuf->mDataByteSize;
   280         remaining = abuf->mDataByteSize;
   286         ptr = abuf->mData;
   281         ptr = abuf->mData;
   287         while (remaining > 0) {
   282         while (remaining > 0) {
   288             if (bufferOffset >= bufferSize) {
   283             if (this->hidden->bufferOffset >= this->hidden->bufferSize) {
   289                 /* Generate the data */
   284                 /* Generate the data */
   290                 SDL_memset(buffer, this->spec.silence, bufferSize);
   285                 SDL_memset(this->hidden->buffer, this->spec.silence,
       
   286                            this->hidden->bufferSize);
   291                 SDL_mutexP(this->mixer_lock);
   287                 SDL_mutexP(this->mixer_lock);
   292                 (*this->spec.callback)(this->spec.userdata,
   288                 (*this->spec.callback)(this->spec.userdata,
   293                             buffer, bufferSize);
   289                             this->hidden->buffer, this->hidden->bufferSize);
   294                 SDL_mutexV(this->mixer_lock);
   290                 SDL_mutexV(this->mixer_lock);
   295                 bufferOffset = 0;
   291                 this->hidden->bufferOffset = 0;
   296             }
   292             }
   297 
   293 
   298             len = bufferSize - bufferOffset;
   294             len = this->hidden->bufferSize - this->hidden->bufferOffset;
   299             if (len > remaining)
   295             if (len > remaining)
   300                 len = remaining;
   296                 len = remaining;
   301             SDL_memcpy(ptr, (char *)buffer + bufferOffset, len);
   297             SDL_memcpy(ptr, (char *)this->hidden->buffer +
       
   298                        this->hidden->bufferOffset, len);
   302             ptr = (char *)ptr + len;
   299             ptr = (char *)ptr + len;
   303             remaining -= len;
   300             remaining -= len;
   304             bufferOffset += len;
   301             this->hidden->bufferOffset += len;
   305         }
   302         }
   306     }
   303     }
   307 
   304 
   308     return 0;
   305     return 0;
   309 }
   306 }