From c8d83cc733e52e57a00e24a7e4b841a14d21b166 Mon Sep 17 00:00:00 2001 From: John Alanbrook Date: Tue, 19 Jul 2022 20:13:15 +0000 Subject: [PATCH] Remove johnsondict --- source/engine/circbuf.c | 9 +++++++++ source/engine/circbuf.h | 1 + source/engine/datastream.c | 2 +- source/engine/datastream.h | 5 +++-- source/engine/dsp.c | 7 +------ source/engine/mix.c | 5 +++++ source/engine/sound.c | 38 ++++++++++++++++++++------------------ source/engine/sound.h | 27 ++++++++++++++------------- 8 files changed, 54 insertions(+), 40 deletions(-) diff --git a/source/engine/circbuf.c b/source/engine/circbuf.c index df5f9c0..7f63bbc 100644 --- a/source/engine/circbuf.c +++ b/source/engine/circbuf.c @@ -3,6 +3,15 @@ #include "util.h" #include "assert.h" +struct circbuf *circbuf_make(size_t size, unsigned int len) +{ + struct circbuf *new = malloc(sizeof(*new)); + new->len = powof2(len); + new->data = calloc(sizeof(short), new->len); + new->read = new->write = 0; + return new; +} + struct circbuf circbuf_init(size_t size, unsigned int len) { struct circbuf new; diff --git a/source/engine/circbuf.h b/source/engine/circbuf.h index 52f9600..84af514 100644 --- a/source/engine/circbuf.h +++ b/source/engine/circbuf.h @@ -11,6 +11,7 @@ struct circbuf { unsigned int len; }; +struct circbuf *circbuf_make(size_t size, unsigned int len); struct circbuf circbuf_init(size_t size, unsigned int len); void cbuf_push(struct circbuf *buf, short data); short cbuf_shift(struct circbuf *buf); diff --git a/source/engine/datastream.c b/source/engine/datastream.c index cea9a5f..65fd813 100755 --- a/source/engine/datastream.c +++ b/source/engine/datastream.c @@ -38,7 +38,7 @@ static void render_audio(plm_t * mpeg, plm_samples_t * samples, void *user) for (int i = 0; i < samples->count * CHANNELS; i++) { t = (short)(samples->interleaved[i] * SHRT_MAX); - cbuf_push(&ds->astream.buf, t*5); + cbuf_push(ds->astream->buf, t*5); } } diff --git a/source/engine/datastream.h b/source/engine/datastream.h index 1edd282..30d864c 100755 --- a/source/engine/datastream.h +++ b/source/engine/datastream.h @@ -3,7 +3,8 @@ #include #include -#include "sound.h" + +struct soundstream; struct datastream { plm_t *plm; @@ -14,7 +15,7 @@ struct datastream { uint32_t texture_y; uint32_t texture_cb; uint32_t texture_cr; - struct soundstream astream; + struct soundstream *astream; }; struct Texture; diff --git a/source/engine/dsp.c b/source/engine/dsp.c index 45010aa..0dbe973 100644 --- a/source/engine/dsp.c +++ b/source/engine/dsp.c @@ -159,15 +159,10 @@ struct dsp_filter dsp_filter(void *data, void (*filter)(void *data, short *out, { struct dsp_filter new; new.data = data; - data.filter = filter; + new.filter = filter; return new; } -void dsp_filter(short *in, short *out, int samples, struct dsp_delay *d) -{ - -} - void dsp_rectify(short *in, short *out, int n) { for (int i = 0; i < n; i++) diff --git a/source/engine/mix.c b/source/engine/mix.c index 2c873cd..feab359 100644 --- a/source/engine/mix.c +++ b/source/engine/mix.c @@ -18,6 +18,11 @@ struct bus *first_free_bus(struct dsp_filter in) { return NULL; } +void bus_free(struct bus *bus) +{ + bus->on = 0; +} + void bus_fill_buffers(short *master, int n) { for (int i = 0; i < 256; i++) { if (bus[i].on != 1) continue; diff --git a/source/engine/sound.c b/source/engine/sound.c index f90cab4..d9a2d0d 100755 --- a/source/engine/sound.c +++ b/source/engine/sound.c @@ -8,6 +8,7 @@ #include "time.h" #include "music.h" + #include "SDL2/SDL.h" #include "mix.h" @@ -41,9 +42,9 @@ void new_samplerate(short *in, short *out, int n, int ch, int sr_in, int sr_out) struct wav change_samplerate(struct wav w, int rate) { - int samples = sizeof(short) * w.ch * w.frames; - short *new = malloc(samples); - new_samplerate(w.data, new, + //int samples = sizeof(short) * w.ch * w.frames; + //short *new = malloc(samples); + //new_samplerate(w.data, new, @@ -52,9 +53,8 @@ struct wav change_samplerate(struct wav w, int rate) int oldframes = w.frames; w.frames *= (float)rate/w.samplerate; - + int samples = sizeof(short) * w.ch * w.frames; w.samplerate = rate; - int samples = sizeof(short)*w.ch*w.frames; short *new = malloc(samples); SDL_AudioStreamGet(stream, new, samples); @@ -168,10 +168,17 @@ struct wav make_sound(const char *wav) return mwav; } +struct soundstream *soundstream_make() +{ + struct soundstream *new = malloc(sizeof(*new)); + new->buf = circbuf_make(sizeof(short), BUF_FRAMES*CHANNELS*2); + return new; +} + struct sound *play_sound(struct wav *wav) { struct sound *new = calloc(1, sizeof(*new)); - new.data = wav; + new->data = wav; new->bus = first_free_bus(dsp_filter(new, sound_fillbuf)); new->playing = 1; @@ -182,12 +189,12 @@ struct sound *play_sound(struct wav *wav) int sound_playing(const struct sound *s) { - return s.playing; + return s->playing; } int sound_paused(const struct sound *s) { - return (!s.playing && s.frame < s.data->frames); + return (!s->playing && s->frame < s->data->frames); } void sound_pause(struct sound *s) { @@ -208,14 +215,14 @@ void sound_stop(struct sound *s) bus_free(s->bus); } -int sound_finished(struct sound *s) +int sound_finished(const struct sound *s) { return !s->playing && s->frame == s->data->frames; } -int sound_stopped(struct sound *s) +int sound_stopped(const struct sound *s) { - return !s->playing && s->frame = 0; + return !s->playing && s->frame == 0; } struct music make_music(const char *mp3) @@ -284,16 +291,11 @@ void mp3_fillbuf(struct sound *s, short *buf, int n) } -struct soundstream soundstream_make() -{ - struct soundstream new; - new.buf = circbuf_init(sizeof(short), BUF_FRAMES*CHANNELS*2); - return new; -} + void soundstream_fillbuf(struct soundstream *s, short *buf, int n) { - int max = s->buf.write - s->buf.read; + int max = s->buf->write - s->buf->read; int lim = (max < n*CHANNELS) ? max : n*CHANNELS; for (int i = 0; i < lim; i++) { buf[i] = cbuf_shift(&s->buf); diff --git a/source/engine/sound.h b/source/engine/sound.h index 4e9ce2b..5e519bc 100755 --- a/source/engine/sound.h +++ b/source/engine/sound.h @@ -1,7 +1,8 @@ #ifndef SOUND_H #define SOUND_H -#include "circbuf.h" +struct circbuf; +struct SDL_AudioStream; struct Mix_Chunk { int i; @@ -18,10 +19,15 @@ enum MUS { }; struct soundstream { - struct circbuf buf; + struct circbuf *buf; }; -struct soundstream soundstream_make(); +struct soundconvstream { + // SDL_AudioStream *srconv; + void *data; +}; + +struct soundstream *soundstream_make(); struct sound { int loop; @@ -42,14 +48,9 @@ struct wav { void *data; }; -struct soundstream { - SDL_AudioStream *srconv; - void *data; -}; struct music { - }; extern const char *audioDriver; @@ -62,12 +63,12 @@ void sound_fillbuf(struct sound *s, short *buf, int n); struct wav make_sound(const char *wav); void wav_norm_gain(struct wav *w, double lv); -struct sound play_sound(struct wav *wav); +struct sound *play_sound(struct wav *wav); -int sound_playing(struct sound *s); -int sound_paused(struct sound *s); -int sound_stopped(struct sound *s); -int sound_finished(struct sound *s); +int sound_playing(const struct sound *s); +int sound_paused(const struct sound *s); +int sound_stopped(const struct sound *s); +int sound_finished(const struct sound *s); void sound_pause(struct sound *s); void sound_resume(struct sound *s); void sound_stop(struct sound *s);