Skip to content

Commit

Permalink
More generic naming for FIFO buffer.
Browse files Browse the repository at this point in the history
  • Loading branch information
Themaister committed Jun 14, 2011
1 parent c34a944 commit 0e964c5
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 38 deletions.
20 changes: 10 additions & 10 deletions audio/buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@

#include "buffer.h"

struct rsound_fifo_buffer
struct fifo_buffer
{
char *buffer;
size_t bufsize;
size_t first;
size_t end;
};

rsound_fifo_buffer_t* rsnd_fifo_new(size_t size)
fifo_buffer_t* fifo_new(size_t size)
{
rsound_fifo_buffer_t *buf = calloc(1, sizeof(*buf));
fifo_buffer_t *buf = calloc(1, sizeof(*buf));
if (buf == NULL)
return NULL;

Expand All @@ -40,7 +40,7 @@ rsound_fifo_buffer_t* rsnd_fifo_new(size_t size)
return buf;
}

void rsnd_fifo_free(rsound_fifo_buffer_t* buffer)
void fifo_free(fifo_buffer_t* buffer)
{
assert(buffer);
assert(buffer->buffer);
Expand All @@ -49,7 +49,7 @@ void rsnd_fifo_free(rsound_fifo_buffer_t* buffer)
free(buffer);
}

size_t rsnd_fifo_read_avail(rsound_fifo_buffer_t* buffer)
size_t fifo_read_avail(fifo_buffer_t* buffer)
{
assert(buffer);
assert(buffer->buffer);
Expand All @@ -61,7 +61,7 @@ size_t rsnd_fifo_read_avail(rsound_fifo_buffer_t* buffer)
return end - first;
}

size_t rsnd_fifo_write_avail(rsound_fifo_buffer_t* buffer)
size_t fifo_write_avail(fifo_buffer_t* buffer)
{
assert(buffer);
assert(buffer->buffer);
Expand All @@ -74,12 +74,12 @@ size_t rsnd_fifo_write_avail(rsound_fifo_buffer_t* buffer)
return (buffer->bufsize - 1) - (end - first);
}

void rsnd_fifo_write(rsound_fifo_buffer_t* buffer, const void* in_buf, size_t size)
void fifo_write(fifo_buffer_t* buffer, const void* in_buf, size_t size)
{
assert(buffer);
assert(buffer->buffer);
assert(in_buf);
assert(rsnd_fifo_write_avail(buffer) >= size);
assert(fifo_write_avail(buffer) >= size);

size_t first_write = size;
size_t rest_write = 0;
Expand All @@ -97,12 +97,12 @@ void rsnd_fifo_write(rsound_fifo_buffer_t* buffer, const void* in_buf, size_t si
}


void rsnd_fifo_read(rsound_fifo_buffer_t* buffer, void* in_buf, size_t size)
void fifo_read(fifo_buffer_t* buffer, void* in_buf, size_t size)
{
assert(buffer);
assert(buffer->buffer);
assert(in_buf);
assert(rsnd_fifo_read_avail(buffer) >= size);
assert(fifo_read_avail(buffer) >= size);

size_t first_read = size;
size_t rest_read = 0;
Expand Down
18 changes: 9 additions & 9 deletions audio/buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@
#include <stdio.h>
#include <string.h>

#ifndef RSD_FIFO_BUF_TYPEDEF
#define RSD_FIFO_BUF_TYPEDEF
typedef struct rsound_fifo_buffer rsound_fifo_buffer_t;
#ifndef FIFO_BUF_TYPEDEF
#define FIFO_BUF_TYPEDEF
typedef struct fifo_buffer fifo_buffer_t;
#endif

rsound_fifo_buffer_t* rsnd_fifo_new(size_t size);
void rsnd_fifo_write(rsound_fifo_buffer_t* buffer, const void* in_buf, size_t size);
void rsnd_fifo_read(rsound_fifo_buffer_t* buffer, void* in_buf, size_t size);
void rsnd_fifo_free(rsound_fifo_buffer_t* buffer);
size_t rsnd_fifo_read_avail(rsound_fifo_buffer_t* buffer);
size_t rsnd_fifo_write_avail(rsound_fifo_buffer_t* buffer);
fifo_buffer_t* fifo_new(size_t size);
void fifo_write(fifo_buffer_t* buffer, const void* in_buf, size_t size);
void fifo_read(fifo_buffer_t* buffer, void* in_buf, size_t size);
void fifo_free(fifo_buffer_t* buffer);
size_t fifo_read_avail(fifo_buffer_t* buffer);
size_t fifo_write_avail(fifo_buffer_t* buffer);

#endif
18 changes: 9 additions & 9 deletions audio/rsound.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ typedef struct rsd
bool nonblock;
volatile bool has_error;

rsound_fifo_buffer_t *buffer;
fifo_buffer_t *buffer;

SDL_mutex *cond_lock;
SDL_cond *cond;
Expand All @@ -39,9 +39,9 @@ static ssize_t audio_cb(void *data, size_t bytes, void *userdata)
{
rsd_t *rsd = userdata;

size_t avail = rsnd_fifo_read_avail(rsd->buffer);
size_t avail = fifo_read_avail(rsd->buffer);
size_t write_size = bytes > avail ? avail : bytes;
rsnd_fifo_read(rsd->buffer, data, write_size);
fifo_read(rsd->buffer, data, write_size);
SDL_CondSignal(rsd->cond);

return write_size;
Expand Down Expand Up @@ -71,7 +71,7 @@ static void* __rsd_init(const char* device, unsigned rate, unsigned latency)
rsd->cond_lock = SDL_CreateMutex();
rsd->cond = SDL_CreateCond();

rsd->buffer = rsnd_fifo_new(1024 * 4);
rsd->buffer = fifo_new(1024 * 4);

int channels = 2;
int format = RSD_S16_NE;
Expand Down Expand Up @@ -108,9 +108,9 @@ static ssize_t __rsd_write(void* data, const void* buf, size_t size)
if (rsd->nonblock)
{
rsd_callback_lock(rsd->rd);
size_t avail = rsnd_fifo_write_avail(rsd->buffer);
size_t avail = fifo_write_avail(rsd->buffer);
size_t write_amt = avail > size ? size : avail;
rsnd_fifo_write(rsd->buffer, buf, write_amt);
fifo_write(rsd->buffer, buf, write_amt);
rsd_callback_unlock(rsd->rd);
return write_amt;
}
Expand All @@ -120,7 +120,7 @@ static ssize_t __rsd_write(void* data, const void* buf, size_t size)
while (written < size && !rsd->has_error)
{
rsd_callback_lock(rsd->rd);
size_t avail = rsnd_fifo_write_avail(rsd->buffer);
size_t avail = fifo_write_avail(rsd->buffer);

if (avail == 0)
{
Expand All @@ -135,7 +135,7 @@ static ssize_t __rsd_write(void* data, const void* buf, size_t size)
else
{
size_t write_amt = size - written > avail ? avail : size - written;
rsnd_fifo_write(rsd->buffer, (const char*)buf + written, write_amt);
fifo_write(rsd->buffer, (const char*)buf + written, write_amt);
rsd_callback_unlock(rsd->rd);
written += write_amt;
}
Expand Down Expand Up @@ -174,7 +174,7 @@ static void __rsd_free(void *data)
rsd_stop(rsd->rd);
rsd_free(rsd->rd);

rsnd_fifo_free(rsd->buffer);
fifo_free(rsd->buffer);
SDL_DestroyMutex(rsd->cond_lock);
SDL_DestroyCond(rsd->cond);

Expand Down
20 changes: 10 additions & 10 deletions audio/sdl.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,16 @@ typedef struct sdl_audio

SDL_mutex *lock;
SDL_cond *cond;
rsound_fifo_buffer_t *buffer;
fifo_buffer_t *buffer;
} sdl_audio_t;

static void sdl_audio_cb(void *data, Uint8 *stream, int len)
{
sdl_audio_t *sdl = data;

size_t avail = rsnd_fifo_read_avail(sdl->buffer);
size_t avail = fifo_read_avail(sdl->buffer);
size_t write_size = len > avail ? avail : len;
rsnd_fifo_read(sdl->buffer, stream, write_size);
fifo_read(sdl->buffer, stream, write_size);
SDL_CondSignal(sdl->cond);

// If underrun, fill rest with silence.
Expand Down Expand Up @@ -98,10 +98,10 @@ static void* sdl_audio_init(const char* device, unsigned rate, unsigned latency)
// Create a buffer twice as big as needed and prefill the buffer.
size_t bufsize = out.samples * 4 * sizeof(int16_t);
void *tmp = calloc(1, bufsize);
sdl->buffer = rsnd_fifo_new(bufsize);
sdl->buffer = fifo_new(bufsize);
if (tmp)
{
rsnd_fifo_write(sdl->buffer, tmp, bufsize);
fifo_write(sdl->buffer, tmp, bufsize);
free(tmp);
}

Expand All @@ -117,9 +117,9 @@ static ssize_t sdl_audio_write(void* data, const void* buf, size_t size)
if (sdl->nonblock)
{
SDL_LockAudio();
size_t avail = rsnd_fifo_write_avail(sdl->buffer);
size_t avail = fifo_write_avail(sdl->buffer);
size_t write_amt = avail > size ? size : avail;
rsnd_fifo_write(sdl->buffer, buf, write_amt);
fifo_write(sdl->buffer, buf, write_amt);
SDL_UnlockAudio();
ret = write_amt;
}
Expand All @@ -129,7 +129,7 @@ static ssize_t sdl_audio_write(void* data, const void* buf, size_t size)
while (written < size)
{
SDL_LockAudio();
size_t avail = rsnd_fifo_write_avail(sdl->buffer);
size_t avail = fifo_write_avail(sdl->buffer);

if (avail == 0)
{
Expand All @@ -141,7 +141,7 @@ static ssize_t sdl_audio_write(void* data, const void* buf, size_t size)
else
{
size_t write_amt = size - written > avail ? avail : size - written;
rsnd_fifo_write(sdl->buffer, (const char*)buf + written, write_amt);
fifo_write(sdl->buffer, (const char*)buf + written, write_amt);
SDL_UnlockAudio();
written += write_amt;
}
Expand Down Expand Up @@ -180,7 +180,7 @@ static void sdl_audio_free(void *data)
sdl_audio_t *sdl = data;
if (sdl)
{
rsnd_fifo_free(sdl->buffer);
fifo_free(sdl->buffer);
SDL_DestroyMutex(sdl->lock);
SDL_DestroyCond(sdl->cond);
}
Expand Down

0 comments on commit 0e964c5

Please sign in to comment.