Remove johnsondict

This commit is contained in:
John Alanbrook 2022-07-19 20:13:15 +00:00
parent 6995477411
commit c8d83cc733
8 changed files with 54 additions and 40 deletions

View file

@ -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;

View file

@ -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);

View file

@ -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);
}
}

View file

@ -3,7 +3,8 @@
#include <stdint.h>
#include <pl_mpeg.h>
#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;

View file

@ -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++)

View file

@ -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;

View file

@ -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;
w.samplerate = rate;
int samples = sizeof(short) * w.ch * w.frames;
w.samplerate = rate;
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);

View file

@ -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);