changed frames to seconds

master
Ahmet Inan 2011-09-09 11:03:34 +02:00
rodzic 1da9331bb1
commit 2ceabe4081
5 zmienionych plików z 8 dodań i 9 usunięć

Wyświetl plik

@ -57,14 +57,12 @@ int main(int argc, char **argv)
uint8_t *pixel = (uint8_t *)ppm_p + strlen(ppm_head); uint8_t *pixel = (uint8_t *)ppm_p + strlen(ppm_head);
float rate = atoi(argv[3]); if (!open_pcm_write(&pcm, argv[2], atoi(argv[3]), 1, 37.5)) {
int frames = 37.5 * rate;
if (!open_pcm_write(&pcm, argv[2], atoi(argv[3]), 1, frames)) {
fprintf(stderr, "couldnt open output %s\n", argv[2]); fprintf(stderr, "couldnt open output %s\n", argv[2]);
return 1; return 1;
} }
rate = rate_pcm(pcm); float rate = rate_pcm(pcm);
channels = channels_pcm(pcm); channels = channels_pcm(pcm);
buff = (short *)malloc(sizeof(short)*channels); buff = (short *)malloc(sizeof(short)*channels);

4
pcm.c
Wyświetl plik

@ -53,12 +53,12 @@ int open_pcm_read(pcm_t **p, char *name)
return 0; 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) if (strstr(name, "plughw:") == name || strstr(name, "hw:") == name || strstr(name, "default") == name)
return open_alsa_write(p, name, rate, channels); return open_alsa_write(p, name, rate, channels);
if (strstr(name, ".wav") == (name + (strlen(name) - strlen(".wav")))) 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; return 0;
} }

2
pcm.h
Wyświetl plik

@ -24,7 +24,7 @@ int channels_pcm(pcm_t *);
int read_pcm(pcm_t *, short *, int); int read_pcm(pcm_t *, short *, int);
int write_pcm(pcm_t *, short *, int); int write_pcm(pcm_t *, short *, int);
int open_pcm_read(pcm_t **, char *); 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 #endif

3
wav.c
Wyświetl plik

@ -123,7 +123,7 @@ int open_wav_read(pcm_t **p, char *name)
return 1; 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_t *wav = (wav_t *)malloc(sizeof(wav_t));
wav->close = close_wav; 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->rate = rate_wav;
wav->channels = channels_wav; wav->channels = channels_wav;
wav->rw = write_wav; wav->rw = write_wav;
int frames = seconds * rate;
wav->size = frames * channels * sizeof(short) + sizeof(wav_head_t); wav->size = frames * channels * sizeof(short) + sizeof(wav_head_t);
if (!mmap_file_rw(&wav->p, name, wav->size)) { if (!mmap_file_rw(&wav->p, name, wav->size)) {
fprintf(stderr, "couldnt open wav file %s!\n", name); fprintf(stderr, "couldnt open wav file %s!\n", name);

2
wav.h
Wyświetl plik

@ -10,5 +10,5 @@ You should have received a copy of the CC0 Public Domain Dedication along with t
#define WAV_H #define WAV_H
#include "pcm.h" #include "pcm.h"
int open_wav_read(pcm_t **, char *); 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 #endif