From 2ceabe408111b69b4827d33eb3545b97d591859b Mon Sep 17 00:00:00 2001 From: Ahmet Inan Date: Fri, 9 Sep 2011 11:03:34 +0200 Subject: [PATCH] changed frames to seconds --- encode.c | 6 ++---- pcm.c | 4 ++-- pcm.h | 2 +- wav.c | 3 ++- wav.h | 2 +- 5 files changed, 8 insertions(+), 9 deletions(-) diff --git a/encode.c b/encode.c index 3755107..4121559 100644 --- a/encode.c +++ b/encode.c @@ -57,14 +57,12 @@ int main(int argc, char **argv) uint8_t *pixel = (uint8_t *)ppm_p + strlen(ppm_head); - float rate = atoi(argv[3]); - int frames = 37.5 * rate; - if (!open_pcm_write(&pcm, argv[2], atoi(argv[3]), 1, frames)) { + if (!open_pcm_write(&pcm, argv[2], atoi(argv[3]), 1, 37.5)) { fprintf(stderr, "couldnt open output %s\n", argv[2]); return 1; } - rate = rate_pcm(pcm); + float rate = rate_pcm(pcm); channels = channels_pcm(pcm); buff = (short *)malloc(sizeof(short)*channels); diff --git a/pcm.c b/pcm.c index f428c16..32dab4e 100644 --- a/pcm.c +++ b/pcm.c @@ -53,12 +53,12 @@ int open_pcm_read(pcm_t **p, char *name) return 0; } -int open_pcm_write(pcm_t **p, char *name, int rate, int channels, int frames) +int open_pcm_write(pcm_t **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); if (strstr(name, ".wav") == (name + (strlen(name) - strlen(".wav")))) - return open_wav_write(p, name, rate, channels, frames); + return open_wav_write(p, name, rate, channels, seconds); return 0; } diff --git a/pcm.h b/pcm.h index ea4bd4a..ca0a8b4 100644 --- a/pcm.h +++ b/pcm.h @@ -24,7 +24,7 @@ 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, int); +int open_pcm_write(pcm_t **, char *, int, int, float); #endif diff --git a/wav.c b/wav.c index 5e3bb91..b0d4366 100644 --- a/wav.c +++ b/wav.c @@ -123,7 +123,7 @@ int open_wav_read(pcm_t **p, char *name) return 1; } -int open_wav_write(pcm_t **p, char *name, int rate, int channels, int frames) +int open_wav_write(pcm_t **p, char *name, int rate, int channels, float seconds) { wav_t *wav = (wav_t *)malloc(sizeof(wav_t)); wav->close = close_wav; @@ -131,6 +131,7 @@ int open_wav_write(pcm_t **p, char *name, int rate, int channels, int frames) wav->rate = rate_wav; wav->channels = channels_wav; wav->rw = write_wav; + int frames = seconds * rate; wav->size = frames * channels * sizeof(short) + sizeof(wav_head_t); if (!mmap_file_rw(&wav->p, name, wav->size)) { fprintf(stderr, "couldnt open wav file %s!\n", name); diff --git a/wav.h b/wav.h index 703c7ed..85aab09 100644 --- a/wav.h +++ b/wav.h @@ -10,5 +10,5 @@ You should have received a copy of the CC0 Public Domain Dedication along with t #define WAV_H #include "pcm.h" int open_wav_read(pcm_t **, char *); -int open_wav_write(pcm_t **, char *, int, int, int); +int open_wav_write(pcm_t **, char *, int, int, float); #endif