audio: rename fake_stream to work_buffer.
authorRyan C. Gordon <icculus@icculus.org>
Fri, 06 Jan 2017 01:07:34 -0500
changeset 1076561312c8c59fe
parent 10764 f9bf759e9dd1
child 10766 6cfccf993c5d
audio: rename fake_stream to work_buffer.

It's more than an alternative for when the OS can't provide a DMA buffer, now.
src/audio/SDL_audio.c
src/audio/SDL_sysaudio.h
src/audio/emscripten/SDL_emscriptenaudio.c
src/audio/haiku/SDL_haikuaudio.cc
src/audio/nacl/SDL_naclaudio.c
     1.1 --- a/src/audio/SDL_audio.c	Fri Jan 06 01:02:58 2017 -0500
     1.2 +++ b/src/audio/SDL_audio.c	Fri Jan 06 01:07:34 2017 -0500
     1.3 @@ -568,16 +568,16 @@
     1.4              stream = current_audio.impl.GetDeviceBuf(device);
     1.5          } else {
     1.6              /* if the device isn't enabled, we still write to the
     1.7 -               fake_stream, so the app's callback will fire with
     1.8 +               work_buffer, so the app's callback will fire with
     1.9                 a regular frequency, in case they depend on that
    1.10                 for timing or progress. They can use hotplug
    1.11                 now to know if the device failed.
    1.12 -               Streaming playback uses fake_stream as a work buffer, too. */
    1.13 +               Streaming playback uses work_buffer, too. */
    1.14              stream = NULL;
    1.15          }
    1.16  
    1.17          if (stream == NULL) {
    1.18 -            stream = device->fake_stream;
    1.19 +            stream = device->work_buffer;
    1.20          }
    1.21  
    1.22          if ( SDL_AtomicGet(&device->enabled) ) {
    1.23 @@ -614,7 +614,7 @@
    1.24                      current_audio.impl.WaitDevice(device);
    1.25                  }
    1.26              }
    1.27 -        } else if (stream == device->fake_stream) {
    1.28 +        } else if (stream == device->work_buffer) {
    1.29              /* nothing to do; pause like we queued a buffer to play. */
    1.30              SDL_Delay(delay);
    1.31          } else {  /* writing directly to the device. */
    1.32 @@ -670,8 +670,8 @@
    1.33          /* Fill the current buffer with sound */
    1.34          still_need = stream_len;
    1.35  
    1.36 -        /* just use the "fake" stream to hold data read from the device. */
    1.37 -        stream = device->fake_stream;
    1.38 +        /* Use the work_buffer to hold data read from the device. */
    1.39 +        stream = device->work_buffer;
    1.40          SDL_assert(stream != NULL);
    1.41  
    1.42          ptr = stream;
    1.43 @@ -702,16 +702,16 @@
    1.44              SDL_AudioStreamPut(device->stream, stream, stream_len);
    1.45  
    1.46              while (SDL_AudioStreamAvailable(device->stream) >= ((int) device->callbackspec.size)) {
    1.47 -                const int got = SDL_AudioStreamGet(device->stream, device->fake_stream, device->callbackspec.size);
    1.48 +                const int got = SDL_AudioStreamGet(device->stream, device->work_buffer, device->callbackspec.size);
    1.49                  SDL_assert((got < 0) || (got == device->callbackspec.size));
    1.50                  if (got != device->callbackspec.size) {
    1.51 -                    SDL_memset(device->fake_stream, device->spec.silence, device->callbackspec.size);
    1.52 +                    SDL_memset(device->work_buffer, device->spec.silence, device->callbackspec.size);
    1.53                  }
    1.54  
    1.55                  /* !!! FIXME: this should be LockDevice. */
    1.56                  SDL_LockMutex(device->mixer_lock);
    1.57                  if (!SDL_AtomicGet(&device->paused)) {
    1.58 -                    callback(udata, device->fake_stream, device->callbackspec.size);
    1.59 +                    callback(udata, device->work_buffer, device->callbackspec.size);
    1.60                  }
    1.61                  SDL_UnlockMutex(device->mixer_lock);
    1.62              }
    1.63 @@ -958,7 +958,7 @@
    1.64          SDL_DestroyMutex(device->mixer_lock);
    1.65      }
    1.66  
    1.67 -    SDL_free(device->fake_stream);
    1.68 +    SDL_free(device->work_buffer);
    1.69      SDL_FreeAudioStream(device->stream);
    1.70  
    1.71      if (device->hidden != NULL) {
    1.72 @@ -1243,16 +1243,15 @@
    1.73          device->spec.userdata = device;
    1.74      }
    1.75  
    1.76 -    /* !!! FIXME: rename this from fake_stream */
    1.77      /* Allocate a scratch audio buffer */
    1.78 -    device->fake_stream_len = build_stream ? device->callbackspec.size : 0;
    1.79 -    if (device->spec.size > device->fake_stream_len) {
    1.80 -        device->fake_stream_len = device->spec.size;
    1.81 +    device->work_buffer_len = build_stream ? device->callbackspec.size : 0;
    1.82 +    if (device->spec.size > device->work_buffer_len) {
    1.83 +        device->work_buffer_len = device->spec.size;
    1.84      }
    1.85 -    SDL_assert(device->fake_stream_len > 0);
    1.86 +    SDL_assert(device->work_buffer_len > 0);
    1.87  
    1.88 -    device->fake_stream = (Uint8 *) SDL_malloc(device->fake_stream_len);
    1.89 -    if (device->fake_stream == NULL) {
    1.90 +    device->work_buffer = (Uint8 *) SDL_malloc(device->work_buffer_len);
    1.91 +    if (device->work_buffer == NULL) {
    1.92          close_audio_device(device);
    1.93          SDL_OutOfMemory();
    1.94          return 0;
     2.1 --- a/src/audio/SDL_sysaudio.h	Fri Jan 06 01:02:58 2017 -0500
     2.2 +++ b/src/audio/SDL_sysaudio.h	Fri Jan 06 01:07:34 2017 -0500
     2.3 @@ -146,11 +146,11 @@
     2.4      SDL_atomic_t paused;
     2.5      SDL_bool iscapture;
     2.6  
     2.7 -    /* Fake audio buffer for when the audio hardware is busy */
     2.8 -    Uint8 *fake_stream;
     2.9 +    /* Scratch buffer used in the bridge between SDL and the user callback. */
    2.10 +    Uint8 *work_buffer;
    2.11  
    2.12 -    /* Size, in bytes, of fake_stream. */
    2.13 -    Uint32 fake_stream_len;
    2.14 +    /* Size, in bytes, of work_buffer. */
    2.15 +    Uint32 work_buffer_len;
    2.16  
    2.17      /* A mutex for locking the mixing buffers */
    2.18      SDL_mutex *mixer_lock;
     3.1 --- a/src/audio/emscripten/SDL_emscriptenaudio.c	Fri Jan 06 01:02:58 2017 -0500
     3.2 +++ b/src/audio/emscripten/SDL_emscriptenaudio.c	Fri Jan 06 01:07:34 2017 -0500
     3.3 @@ -65,26 +65,26 @@
     3.4  
     3.5      if (this->stream == NULL) {  /* no conversion necessary. */
     3.6          SDL_assert(this->spec.size == stream_len);
     3.7 -        callback(this->spec.userdata, this->fake_stream, stream_len);
     3.8 +        callback(this->spec.userdata, this->work_buffer, stream_len);
     3.9      } else {  /* streaming/converting */
    3.10          int got;
    3.11          while (SDL_AudioStreamAvailable(this->stream) < ((int) this->spec.size)) {
    3.12 -            callback(this->spec.userdata, this->fake_stream, stream_len);
    3.13 -            if (SDL_AudioStreamPut(this->stream, this->fake_stream, stream_len) == -1) {
    3.14 +            callback(this->spec.userdata, this->work_buffer, stream_len);
    3.15 +            if (SDL_AudioStreamPut(this->stream, this->work_buffer, stream_len) == -1) {
    3.16                  SDL_AudioStreamClear(this->stream);
    3.17                  SDL_AtomicSet(&this->enabled, 0);
    3.18                  break;
    3.19              }
    3.20          }
    3.21  
    3.22 -        got = SDL_AudioStreamGet(this->stream, this->fake_stream, this->spec.size);
    3.23 +        got = SDL_AudioStreamGet(this->stream, this->work_buffer, this->spec.size);
    3.24          SDL_assert((got < 0) || (got == this->spec.size));
    3.25          if (got != this->spec.size) {
    3.26 -            SDL_memset(this->fake_stream, this->spec.silence, this->spec.size);
    3.27 +            SDL_memset(this->work_buffer, this->spec.silence, this->spec.size);
    3.28          }
    3.29      }
    3.30  
    3.31 -    FeedAudioDevice(this, this->fake_stream, this->spec.size);
    3.32 +    FeedAudioDevice(this, this->work_buffer, this->spec.size);
    3.33  }
    3.34  
    3.35  static void
    3.36 @@ -117,25 +117,25 @@
    3.37                  }
    3.38              }
    3.39          }
    3.40 -    }, this->fake_stream, (this->spec.size / sizeof (float)) / this->spec.channels);
    3.41 +    }, this->work_buffer, (this->spec.size / sizeof (float)) / this->spec.channels);
    3.42  
    3.43      /* okay, we've got an interleaved float32 array in C now. */
    3.44  
    3.45      if (this->stream == NULL) {  /* no conversion necessary. */
    3.46          SDL_assert(this->spec.size == stream_len);
    3.47 -        callback(this->spec.userdata, this->fake_stream, stream_len);
    3.48 +        callback(this->spec.userdata, this->work_buffer, stream_len);
    3.49      } else {  /* streaming/converting */
    3.50 -        if (SDL_AudioStreamPut(this->stream, this->fake_stream, this->spec.size) == -1) {
    3.51 +        if (SDL_AudioStreamPut(this->stream, this->work_buffer, this->spec.size) == -1) {
    3.52              SDL_AtomicSet(&this->enabled, 0);
    3.53          }
    3.54  
    3.55          while (SDL_AudioStreamAvailable(this->stream) >= stream_len) {
    3.56 -            const int got = SDL_AudioStreamGet(this->stream, this->fake_stream, stream_len);
    3.57 +            const int got = SDL_AudioStreamGet(this->stream, this->work_buffer, stream_len);
    3.58              SDL_assert((got < 0) || (got == stream_len));
    3.59              if (got != stream_len) {
    3.60 -                SDL_memset(this->fake_stream, this->callbackspec.silence, stream_len);
    3.61 +                SDL_memset(this->work_buffer, this->callbackspec.silence, stream_len);
    3.62              }
    3.63 -            callback(this->spec.userdata, this->fake_stream, stream_len);  /* Send it to the app. */
    3.64 +            callback(this->spec.userdata, this->work_buffer, stream_len);  /* Send it to the app. */
    3.65          }
    3.66      }
    3.67  }
     4.1 --- a/src/audio/haiku/SDL_haikuaudio.cc	Fri Jan 06 01:02:58 2017 -0500
     4.2 +++ b/src/audio/haiku/SDL_haikuaudio.cc	Fri Jan 06 01:07:34 2017 -0500
     4.3 @@ -69,8 +69,8 @@
     4.4          const int stream_len = audio->callbackspec.size;
     4.5          const int ilen = (int) len;
     4.6          while (SDL_AudioStreamAvailable(audio->stream) < ilen) {
     4.7 -            callback(audio->spec.userdata, audio->fake_stream, stream_len);
     4.8 -            if (SDL_AudioStreamPut(audio->stream, audio->fake_stream, stream_len) == -1) {
     4.9 +            callback(audio->spec.userdata, audio->work_buffer, stream_len);
    4.10 +            if (SDL_AudioStreamPut(audio->stream, audio->work_buffer, stream_len) == -1) {
    4.11                  SDL_AudioStreamClear(audio->stream);
    4.12                  SDL_AtomicSet(&audio->enabled, 0);
    4.13                  break;
     5.1 --- a/src/audio/nacl/SDL_naclaudio.c	Fri Jan 06 01:02:58 2017 -0500
     5.2 +++ b/src/audio/nacl/SDL_naclaudio.c	Fri Jan 06 01:07:34 2017 -0500
     5.3 @@ -70,8 +70,8 @@
     5.4      } else {  /* streaming/converting */
     5.5          const int stream_len = _this->callbackspec.size;
     5.6          while (SDL_AudioStreamAvailable(_this->stream) < len) {
     5.7 -            callback(_this->spec.userdata, _this->fake_stream, stream_len);
     5.8 -            if (SDL_AudioStreamPut(_this->stream, _this->fake_stream, stream_len) == -1) {
     5.9 +            callback(_this->spec.userdata, _this->work_buffer, stream_len);
    5.10 +            if (SDL_AudioStreamPut(_this->stream, _this->work_buffer, stream_len) == -1) {
    5.11                  SDL_AudioStreamClear(_this->stream);
    5.12                  SDL_AtomicSet(&_this->enabled, 0);
    5.13                  break;