From 7bc72d4acf6c4abbe0e00b0211f5b79dafbb0b4c Mon Sep 17 00:00:00 2001 From: Ahmet Inan Date: Fri, 1 Jun 2012 23:41:04 +0200 Subject: [PATCH] dont hide structs behind typedefs --- alsa.c | 38 +++++++++++++++++++------------------- alsa.h | 4 ++-- ddc.c | 8 ++++---- ddc.h | 10 +++++----- debug.c | 12 ++++++------ decode.c | 16 ++++++++-------- delay.c | 8 ++++---- delay.h | 10 +++++----- encode.c | 4 ++-- img.c | 6 +++--- img.h | 10 +++++----- pcm.c | 16 ++++++++-------- pcm.h | 20 ++++++++++---------- ppm.c | 18 +++++++++--------- ppm.h | 4 ++-- sdl.c | 26 +++++++++++++------------- sdl.h | 2 +- wav.c | 52 ++++++++++++++++++++++++++-------------------------- wav.h | 4 ++-- 19 files changed, 134 insertions(+), 134 deletions(-) diff --git a/alsa.c b/alsa.c index b621abe..d0e6b19 100644 --- a/alsa.c +++ b/alsa.c @@ -11,44 +11,44 @@ You should have received a copy of the CC0 Public Domain Dedication along with t #include #include "alsa.h" -typedef struct { - pcm_t base; +struct alsa { + struct pcm base; snd_pcm_t *pcm; int index; int frames; int r; int c; -} alsa_t; +}; -void close_alsa(pcm_t *pcm) +void close_alsa(struct pcm *pcm) { - alsa_t *alsa = (alsa_t *)(pcm->data); + struct alsa *alsa = (struct alsa *)(pcm->data); snd_pcm_drain(alsa->pcm); snd_pcm_close(alsa->pcm); free(alsa); } -void info_alsa(pcm_t *pcm) +void info_alsa(struct pcm *pcm) { - alsa_t *alsa = (alsa_t *)(pcm->data); + struct alsa *alsa = (struct alsa *)(pcm->data); if (alsa->frames) fprintf(stderr, "%d channel(s), %d rate, %.2f seconds\n", alsa->c, alsa->r, (float)alsa->frames / (float)alsa->r); else fprintf(stderr, "%d channel(s), %d rate\n", alsa->c, alsa->r); } -int rate_alsa(pcm_t *pcm) +int rate_alsa(struct pcm *pcm) { - alsa_t *alsa = (alsa_t *)(pcm->data); + struct alsa *alsa = (struct alsa *)(pcm->data); return alsa->r; } -int channels_alsa(pcm_t *pcm) +int channels_alsa(struct pcm *pcm) { - alsa_t *alsa = (alsa_t *)(pcm->data); + struct alsa *alsa = (struct alsa *)(pcm->data); return alsa->c; } -int read_alsa(pcm_t *pcm, short *buff, int frames) +int read_alsa(struct pcm *pcm, short *buff, int frames) { - alsa_t *alsa = (alsa_t *)(pcm->data); + struct alsa *alsa = (struct alsa *)(pcm->data); int got = 0; while (0 < frames) { while ((got = snd_pcm_readi(alsa->pcm, buff, frames)) < 0) @@ -60,9 +60,9 @@ int read_alsa(pcm_t *pcm, short *buff, int frames) return 1; } -int write_alsa(pcm_t *pcm, short *buff, int frames) +int write_alsa(struct pcm *pcm, short *buff, int frames) { - alsa_t *alsa = (alsa_t *)(pcm->data); + struct alsa *alsa = (struct alsa *)(pcm->data); if (alsa->frames && (alsa->index + frames) > alsa->frames) return 0; alsa->index += frames; @@ -77,9 +77,9 @@ int write_alsa(pcm_t *pcm, short *buff, int frames) return 1; } -int open_alsa_read(pcm_t **p, char *name) +int open_alsa_read(struct pcm **p, char *name) { - alsa_t *alsa = (alsa_t *)malloc(sizeof(alsa_t)); + struct alsa *alsa = (struct alsa *)malloc(sizeof(struct alsa)); alsa->base.close = close_alsa; alsa->base.info = info_alsa; alsa->base.rate = rate_alsa; @@ -153,9 +153,9 @@ int open_alsa_read(pcm_t **p, char *name) return 1; } -int open_alsa_write(pcm_t **p, char *name, int rate, int channels, float seconds) +int open_alsa_write(struct pcm **p, char *name, int rate, int channels, float seconds) { - alsa_t *alsa = (alsa_t *)malloc(sizeof(alsa_t)); + struct alsa *alsa = (struct alsa *)malloc(sizeof(struct alsa)); alsa->base.close = close_alsa; alsa->base.info = info_alsa; alsa->base.rate = rate_alsa; diff --git a/alsa.h b/alsa.h index 57991a8..bd78640 100644 --- a/alsa.h +++ b/alsa.h @@ -9,7 +9,7 @@ You should have received a copy of the CC0 Public Domain Dedication along with t #ifndef ALSA_H #define ALSA_H #include "pcm.h" -int open_alsa_read(pcm_t **, char *); -int open_alsa_write(pcm_t **, char *, int, int, float); +int open_alsa_read(struct pcm **, char *); +int open_alsa_write(struct pcm **, char *, int, int, float); #endif diff --git a/ddc.c b/ddc.c index 59448c0..b895065 100644 --- a/ddc.c +++ b/ddc.c @@ -12,7 +12,7 @@ You should have received a copy of the CC0 Public Domain Dedication along with t #include "window.h" #include "ddc.h" -void do_ddc(ddc_t *ddc, float *input, float complex *output) +void do_ddc(struct ddc *ddc, float *input, float complex *output) { // this works only for L <= M for (int k = 0, last = ddc->last, in = 0; k < ddc->L; k++) { @@ -38,11 +38,11 @@ void do_ddc(ddc_t *ddc, float *input, float complex *output) // ddc->osc /= cabsf(ddc->osc); // not really needed } } -ddc_t *alloc_ddc(float freq, float bw, float step, int taps, int L, int M, float (*window)(float, float, float), float a) +struct ddc *alloc_ddc(float freq, float bw, float step, int taps, int L, int M, float (*window)(float, float, float), float a) { float lstep = step / (float)L; float ostep = step * (float)M / (float)L; - ddc_t *ddc = malloc(sizeof(ddc_t)); + struct ddc *ddc = malloc(sizeof(struct ddc)); ddc->taps = taps; ddc->samples = (taps + L - 1) / L; ddc->b = malloc(sizeof(float complex) * ddc->taps); @@ -73,7 +73,7 @@ ddc_t *alloc_ddc(float freq, float bw, float step, int taps, int L, int M, float ddc->b[i] /= sum; return ddc; } -void free_ddc(ddc_t *ddc) +void free_ddc(struct ddc *ddc) { free(ddc->b); free(ddc->s); diff --git a/ddc.h b/ddc.h index 589680c..e539f60 100644 --- a/ddc.h +++ b/ddc.h @@ -10,7 +10,7 @@ You should have received a copy of the CC0 Public Domain Dedication along with t #define DDC_H #include "window.h" -typedef struct { +struct ddc { float complex *b; float *s; float complex osc; @@ -22,11 +22,11 @@ typedef struct { int samples; int L; int M; -} ddc_t; +}; -void do_ddc(ddc_t *, float *, float complex *); -ddc_t *alloc_ddc(float, float, float, int, int, int, float (*)(float, float, float), float); -void free_ddc(ddc_t *); +void do_ddc(struct ddc *, float *, float complex *); +struct ddc *alloc_ddc(float, float, float, int, int, int, float (*)(float, float, float), float); +void free_ddc(struct ddc *); #endif diff --git a/debug.c b/debug.c index abea7b0..2308d0a 100644 --- a/debug.c +++ b/debug.c @@ -22,7 +22,7 @@ You should have received a copy of the CC0 Public Domain Dedication along with t int main(int argc, char **argv) { - pcm_t *pcm; + struct pcm *pcm; char *pcm_name = "default"; char *img_name = 0; if (argc != 1) @@ -112,11 +112,11 @@ int main(int argc, char **argv) float complex *cnt_q = malloc(sizeof(float complex) * factor_L); float complex *dat_q = malloc(sizeof(float complex) * factor_L); // same factor to keep life simple and have accurate horizontal sync - ddc_t *cnt_ddc = alloc_ddc(1200.0, 200.0, step, cnt_taps, factor_L, factor_M, kaiser, 2.0); - ddc_t *dat_ddc = alloc_ddc(1900.0, 800.0, step, dat_taps, factor_L, factor_M, kaiser, 2.0); + struct ddc *cnt_ddc = alloc_ddc(1200.0, 200.0, step, cnt_taps, factor_L, factor_M, kaiser, 2.0); + struct ddc *dat_ddc = alloc_ddc(1900.0, 800.0, step, dat_taps, factor_L, factor_M, kaiser, 2.0); // delay input by phase shift of other filter to synchronize outputs - delay_t *cnt_delay = alloc_delay((dat_taps - 1) / (2 * factor_L)); - delay_t *dat_delay = alloc_delay((cnt_taps - 1) / (2 * factor_L)); + struct delay *cnt_delay = alloc_delay((dat_taps - 1) / (2 * factor_L)); + struct delay *dat_delay = alloc_delay((cnt_taps - 1) / (2 * factor_L)); short *buff = (short *)malloc(sizeof(short) * channels * factor_M); @@ -130,7 +130,7 @@ int main(int argc, char **argv) const int width = (0.150 + 3.0 * sync_porch_len) * drate + 20; const int height = 256; - img_t *img = 0; + struct img *img = 0; int hor_ticks = 0; int y_pixel_x = 0; diff --git a/decode.c b/decode.c index 01dc10b..48785d3 100644 --- a/decode.c +++ b/decode.c @@ -156,7 +156,7 @@ int cal_header(float cnt_freq, float dat_freq, float drate) return 0; } -int decode(int *reset, img_t **img, char *img_name, float cnt_freq, float dat_freq, float drate) +int decode(int *reset, struct img **img, char *img_name, float cnt_freq, float dat_freq, float drate) { const int width = 320; const int height = 240; @@ -281,7 +281,7 @@ int decode(int *reset, img_t **img, char *img_name, float cnt_freq, float dat_fr uv_pixel[uv_pixel_x++ + odd * uv_width] = fclampf(255.0 * (dat_freq - 1500.0) / 800.0, 0.0, 255.0); return 0; } -int demodulate(pcm_t *pcm, float *cnt_freq, float *dat_freq, float *drate) +int demodulate(struct pcm *pcm, float *cnt_freq, float *dat_freq, float *drate) { static float rate; static int channels; @@ -295,10 +295,10 @@ int demodulate(pcm_t *pcm, float *cnt_freq, float *dat_freq, float *drate) static float *dat_amp; static float complex *cnt_q; static float complex *dat_q; - static ddc_t *cnt_ddc; - static ddc_t *dat_ddc; - static delay_t *cnt_delay; - static delay_t *dat_delay; + static struct ddc *cnt_ddc; + static struct ddc *dat_ddc; + static struct delay *cnt_delay; + static struct delay *dat_delay; static short *buff; static int init = 0; @@ -382,7 +382,7 @@ int demodulate(pcm_t *pcm, float *cnt_freq, float *dat_freq, float *drate) int main(int argc, char **argv) { - pcm_t *pcm; + struct pcm *pcm; char *pcm_name = "default"; char *img_name = 0; if (argc != 1) @@ -410,7 +410,7 @@ int main(int argc, char **argv) int vis_reset = 0; int dat_reset = 0; - img_t *img = 0; + struct img *img = 0; float cnt_freq = 0.0; float dat_freq = 0.0; float drate = 0.0; diff --git a/delay.c b/delay.c index 54d6dd0..e5e7cc6 100644 --- a/delay.c +++ b/delay.c @@ -9,17 +9,17 @@ You should have received a copy of the CC0 Public Domain Dedication along with t #include "delay.h" #include -float do_delay(delay_t *d, float input) +float do_delay(struct delay *d, float input) { d->s[d->last] = input; d->last = (d->last + 1) < d->len ? d->last + 1 : 0; return d->s[d->last]; } -delay_t *alloc_delay(int samples) +struct delay *alloc_delay(int samples) { int len = samples + 1; - delay_t *d = malloc(sizeof(delay_t)); + struct delay *d = malloc(sizeof(struct delay)); d->s = malloc(sizeof(float) * len); d->last = 0; d->len = len; @@ -27,7 +27,7 @@ delay_t *alloc_delay(int samples) d->s[i] = 0.0; return d; } -void free_delay(delay_t *delay) +void free_delay(struct delay *delay) { free(delay->s); free(delay); diff --git a/delay.h b/delay.h index 44b8dc9..64ea1dd 100644 --- a/delay.h +++ b/delay.h @@ -8,14 +8,14 @@ You should have received a copy of the CC0 Public Domain Dedication along with t #ifndef DELAY_H #define DELAY_H -typedef struct { +struct delay { float *s; int last; int len; -} delay_t; +}; -float do_delay(delay_t *, float); -delay_t *alloc_delay(int); -void free_delay(delay_t *); +float do_delay(struct delay *, float); +struct delay *alloc_delay(int); +void free_delay(struct delay *); #endif diff --git a/encode.c b/encode.c index a5e2692..5991da1 100644 --- a/encode.c +++ b/encode.c @@ -17,8 +17,8 @@ You should have received a copy of the CC0 Public Domain Dedication along with t #include "pcm.h" #include "img.h" -img_t *img; -pcm_t *pcm; +struct img *img; +struct pcm *pcm; complex float nco; float hz2rad; int channels; diff --git a/img.c b/img.c index 1aa65f0..b0de78a 100644 --- a/img.c +++ b/img.c @@ -11,19 +11,19 @@ You should have received a copy of the CC0 Public Domain Dedication along with t #include "ppm.h" #include "sdl.h" -void close_img(img_t *img) +void close_img(struct img *img) { img->close(img); } -int open_img_read(img_t **p, char *name) +int open_img_read(struct img **p, char *name) { if (strstr(name, ".ppm") == (name + (strlen(name) - strlen(".ppm")))) return open_ppm_read(p, name); return 0; } -int open_img_write(img_t **p, char *name, int width, int height) +int open_img_write(struct img **p, char *name, int width, int height) { if (strstr(name, ".ppm") == (name + (strlen(name) - strlen(".ppm")))) return open_ppm_write(p, name, width, height); diff --git a/img.h b/img.h index ee29486..93fe67c 100644 --- a/img.h +++ b/img.h @@ -11,17 +11,17 @@ You should have received a copy of the CC0 Public Domain Dedication along with t #include -typedef struct img { +struct img { void (*close)(struct img *); uint8_t *pixel; void *data; int width; int height; -} img_t; +}; -void close_img(img_t *); -int open_img_read(img_t **, char *); -int open_img_write(img_t **, char *, int, int); +void close_img(struct img *); +int open_img_read(struct img **, char *); +int open_img_write(struct img **, char *, int, int); #endif diff --git a/pcm.c b/pcm.c index 3a12cdc..a315835 100644 --- a/pcm.c +++ b/pcm.c @@ -13,37 +13,37 @@ You should have received a copy of the CC0 Public Domain Dedication along with t #include "alsa.h" #include "wav.h" -void close_pcm(pcm_t *pcm) +void close_pcm(struct pcm *pcm) { pcm->close(pcm); } -void info_pcm(pcm_t *pcm) +void info_pcm(struct pcm *pcm) { pcm->info(pcm); } -int rate_pcm(pcm_t *pcm) +int rate_pcm(struct pcm *pcm) { return pcm->rate(pcm); } -int channels_pcm(pcm_t *pcm) +int channels_pcm(struct pcm *pcm) { return pcm->channels(pcm); } -int read_pcm(pcm_t *pcm, short *buff, int frames) +int read_pcm(struct pcm *pcm, short *buff, int frames) { return pcm->rw(pcm, buff, frames); } -int write_pcm(pcm_t *pcm, short *buff, int frames) +int write_pcm(struct pcm *pcm, short *buff, int frames) { return pcm->rw(pcm, buff, frames); } -int open_pcm_read(pcm_t **p, char *name) +int open_pcm_read(struct pcm **p, char *name) { if (strstr(name, "plughw:") == name || strstr(name, "hw:") == name || strstr(name, "default") == name) return open_alsa_read(p, name); @@ -52,7 +52,7 @@ int open_pcm_read(pcm_t **p, char *name) return 0; } -int open_pcm_write(pcm_t **p, char *name, int rate, int channels, float seconds) +int open_pcm_write(struct pcm **p, char *name, int rate, int channels, float seconds) { if (strstr(name, "plughw:") == name || strstr(name, "hw:") == name || strstr(name, "default") == name) return open_alsa_write(p, name, rate, channels, seconds); diff --git a/pcm.h b/pcm.h index afc2bb3..bac5736 100644 --- a/pcm.h +++ b/pcm.h @@ -9,23 +9,23 @@ You should have received a copy of the CC0 Public Domain Dedication along with t #ifndef PCM_H #define PCM_H -typedef struct pcm { +struct pcm { void (*close)(struct pcm *); void (*info)(struct pcm *); int (*rate)(struct pcm *); int (*channels)(struct pcm *); int (*rw)(struct pcm *, short *, int); void *data; -} pcm_t; +}; -void close_pcm(pcm_t *); -void info_pcm(pcm_t *); -int rate_pcm(pcm_t *); -int channels_pcm(pcm_t *); -int read_pcm(pcm_t *, short *, int); -int write_pcm(pcm_t *, short *, int); -int open_pcm_read(pcm_t **, char *); -int open_pcm_write(pcm_t **, char *, int, int, float); +void close_pcm(struct pcm *); +void info_pcm(struct pcm *); +int rate_pcm(struct pcm *); +int channels_pcm(struct pcm *); +int read_pcm(struct pcm *, short *, int); +int write_pcm(struct pcm *, short *, int); +int open_pcm_read(struct pcm **, char *); +int open_pcm_write(struct pcm **, char *, int, int, float); #endif diff --git a/ppm.c b/ppm.c index 21ac5b0..f51d592 100644 --- a/ppm.c +++ b/ppm.c @@ -12,21 +12,21 @@ You should have received a copy of the CC0 Public Domain Dedication along with t #include "mmap_file.h" #include "img.h" -typedef struct { - img_t base; +struct ppm { + struct img base; void *p; size_t size; -} ppm_t; +}; -void close_ppm(img_t *img) +void close_ppm(struct img *img) { - ppm_t *ppm = (ppm_t *)(img->data); + struct ppm *ppm = (struct ppm *)(img->data); munmap_file(ppm->p, ppm->size); free(ppm); } -int open_ppm_read(img_t **p, char *name) { - ppm_t *ppm = (ppm_t *)malloc(sizeof(ppm_t)); +int open_ppm_read(struct img **p, char *name) { + struct ppm *ppm = (struct ppm *)malloc(sizeof(struct ppm)); ppm->base.close = close_ppm; ppm->base.data = (void *)ppm; @@ -89,9 +89,9 @@ int open_ppm_read(img_t **p, char *name) { return 1; } -int open_ppm_write(img_t **p, char *name, int width, int height) +int open_ppm_write(struct img **p, char *name, int width, int height) { - ppm_t *ppm = (ppm_t *)malloc(sizeof(ppm_t)); + struct ppm *ppm = (struct ppm *)malloc(sizeof(struct ppm)); ppm->base.close = close_ppm; ppm->base.data = (void *)ppm; diff --git a/ppm.h b/ppm.h index 921b7da..5d661da 100644 --- a/ppm.h +++ b/ppm.h @@ -9,6 +9,6 @@ You should have received a copy of the CC0 Public Domain Dedication along with t #ifndef PPM_H #define PPM_H #include "img.h" -int open_ppm_read(img_t **, char *); -int open_ppm_write(img_t **, char *, int, int); +int open_ppm_read(struct img **, char *); +int open_ppm_write(struct img **, char *, int, int); #endif diff --git a/sdl.c b/sdl.c index e4f3bab..66981cf 100644 --- a/sdl.c +++ b/sdl.c @@ -12,7 +12,7 @@ You should have received a copy of the CC0 Public Domain Dedication along with t #include #include "img.h" -typedef struct { +struct data { uint8_t *pixel; int quit; int stop; @@ -20,12 +20,12 @@ typedef struct { int okay; SDL_Surface *screen; SDL_Thread *thread; -} data_t; +}; -typedef struct { - img_t base; - data_t *data; -} sdl_t; +struct sdl { + struct img base; + struct data *data; +}; void handle_events() { @@ -56,7 +56,7 @@ void handle_events() int update_sdl(void *ptr) { - data_t *data = (data_t *)ptr; + struct data *data = (struct data *)ptr; while (!data->quit) { if (data->stop) { data->busy = 0; @@ -81,9 +81,9 @@ int update_sdl(void *ptr) return 0; } -void close_sdl(img_t *img) +void close_sdl(struct img *img) { - sdl_t *sdl = (sdl_t *)(img->data); + struct sdl *sdl = (struct sdl *)(img->data); sdl->data->okay = 0; sdl->data->stop = 1; while (sdl->data->busy) @@ -93,15 +93,15 @@ void close_sdl(img_t *img) free(sdl); } -int open_sdl_write(img_t **p, char *name, int width, int height) +int open_sdl_write(struct img **p, char *name, int width, int height) { - sdl_t *sdl = (sdl_t *)malloc(sizeof(sdl_t)); + struct sdl *sdl = (struct sdl *)malloc(sizeof(struct sdl)); sdl->base.close = close_sdl; sdl->base.data = (void *)sdl; - static data_t *data = 0; + static struct data *data = 0; if (!data) { - data = (data_t *)malloc(sizeof(data_t)); + data = (struct data *)malloc(sizeof(struct data)); data->quit = 0; data->stop = 1; data->okay = 0; diff --git a/sdl.h b/sdl.h index a99fbfa..cfbb01d 100644 --- a/sdl.h +++ b/sdl.h @@ -9,5 +9,5 @@ You should have received a copy of the CC0 Public Domain Dedication along with t #ifndef SDL_H #define SDL_H #include "img.h" -int open_sdl_write(img_t **, char *, int, int); +int open_sdl_write(struct img **, char *, int, int); #endif diff --git a/wav.c b/wav.c index fea95ca..a793dc5 100644 --- a/wav.c +++ b/wav.c @@ -13,7 +13,7 @@ You should have received a copy of the CC0 Public Domain Dedication along with t #include "wav.h" #include "mmap_file.h" -typedef struct { +struct wav_head { uint32_t ChunkID; uint32_t ChunkSize; uint32_t Format; @@ -27,10 +27,10 @@ typedef struct { uint16_t BitsPerSample; uint32_t Subchunk2ID; uint32_t Subchunk2Size; -} wav_head_t; +}; -typedef struct { - pcm_t base; +struct wav { + struct pcm base; void *p; short *b; size_t size; @@ -38,42 +38,42 @@ typedef struct { int frames; int r; int c; -} wav_t; +}; -void close_wav(pcm_t *pcm) +void close_wav(struct pcm *pcm) { - wav_t *wav = (wav_t *)(pcm->data); + struct wav *wav = (struct wav *)(pcm->data); munmap_file(wav->p, wav->size); free(wav); } -void info_wav(pcm_t *pcm) +void info_wav(struct pcm *pcm) { - wav_t *wav = (wav_t *)(pcm->data); + struct wav *wav = (struct wav *)(pcm->data); fprintf(stderr, "%d channel(s), %d rate, %.2f seconds\n", wav->c, wav->r, (float)wav->frames / (float)wav->r); } -int rate_wav(pcm_t *pcm) +int rate_wav(struct pcm *pcm) { - wav_t *wav = (wav_t *)(pcm->data); + struct wav *wav = (struct wav *)(pcm->data); return wav->r; } -int channels_wav(pcm_t *pcm) +int channels_wav(struct pcm *pcm) { - wav_t *wav = (wav_t *)(pcm->data); + struct wav *wav = (struct wav *)(pcm->data); return wav->c; } -int read_wav(pcm_t *pcm, short *buff, int frames) +int read_wav(struct pcm *pcm, short *buff, int frames) { - wav_t *wav = (wav_t *)(pcm->data); + struct wav *wav = (struct wav *)(pcm->data); if ((wav->index + frames) > wav->frames) return 0; memcpy(buff, wav->b + wav->index * wav->c, sizeof(short) * frames * wav->c); wav->index += frames; return 1; } -int write_wav(pcm_t *pcm, short *buff, int frames) +int write_wav(struct pcm *pcm, short *buff, int frames) { - wav_t *wav = (wav_t *)(pcm->data); + struct wav *wav = (struct wav *)(pcm->data); if ((wav->index + frames) > wav->frames) return 0; memcpy(wav->b + wav->index * wav->c, buff, sizeof(short) * frames * wav->c); @@ -81,9 +81,9 @@ int write_wav(pcm_t *pcm, short *buff, int frames) return 1; } -int open_wav_read(pcm_t **p, char *name) +int open_wav_read(struct pcm **p, char *name) { - wav_t *wav = (wav_t *)malloc(sizeof(wav_t)); + struct wav *wav = (struct wav *)malloc(sizeof(struct wav)); wav->base.close = close_wav; wav->base.info = info_wav; wav->base.rate = rate_wav; @@ -95,8 +95,8 @@ int open_wav_read(pcm_t **p, char *name) free(wav); return 0; } - wav_head_t *head = (wav_head_t *)wav->p; - wav->b = (short *)(wav->p + sizeof(wav_head_t)); + struct wav_head *head = (struct wav_head *)wav->p; + wav->b = (short *)(wav->p + sizeof(struct wav_head)); if (head->ChunkID != 0x46464952 || head->Format != 0x45564157 || head->Subchunk1ID != 0x20746d66 || head->Subchunk1Size != 16 || @@ -120,9 +120,9 @@ int open_wav_read(pcm_t **p, char *name) return 1; } -int open_wav_write(pcm_t **p, char *name, int rate, int channels, float seconds) +int open_wav_write(struct pcm **p, char *name, int rate, int channels, float seconds) { - wav_t *wav = (wav_t *)malloc(sizeof(wav_t)); + struct wav *wav = (struct wav *)malloc(sizeof(struct wav)); wav->base.close = close_wav; wav->base.info = info_wav; wav->base.rate = rate_wav; @@ -130,14 +130,14 @@ int open_wav_write(pcm_t **p, char *name, int rate, int channels, float seconds) wav->base.rw = write_wav; wav->base.data = (void *)wav; int frames = seconds * rate; - wav->size = frames * channels * sizeof(short) + sizeof(wav_head_t); + wav->size = frames * channels * sizeof(short) + sizeof(struct wav_head); if (!mmap_file_rw(&wav->p, name, wav->size)) { fprintf(stderr, "couldnt open wav file %s!\n", name); free(wav); return 0; } - wav_head_t *head = (wav_head_t *)wav->p; - wav->b = (short *)(wav->p + sizeof(wav_head_t)); + struct wav_head *head = (struct wav_head *)wav->p; + wav->b = (short *)(wav->p + sizeof(struct wav_head)); head->ChunkID = 0x46464952; head->ChunkSize = 36 + frames * sizeof(short) * channels; diff --git a/wav.h b/wav.h index 85aab09..8b7991e 100644 --- a/wav.h +++ b/wav.h @@ -9,6 +9,6 @@ You should have received a copy of the CC0 Public Domain Dedication along with t #ifndef WAV_H #define WAV_H #include "pcm.h" -int open_wav_read(pcm_t **, char *); -int open_wav_write(pcm_t **, char *, int, int, float); +int open_wav_read(struct pcm **, char *); +int open_wav_write(struct pcm **, char *, int, int, float); #endif