This commit is contained in:
Alexandre Ratchov 2015-01-08 12:50:24 +01:00
parent 7d8a41e152
commit d0e975e33c
3 changed files with 64 additions and 64 deletions

View File

@ -286,21 +286,21 @@ afile_wav_readfmt(struct afile *f, unsigned int csize)
f->par.msb = 1; f->par.msb = 1;
switch (wenc) { switch (wenc) {
case WAV_FMT_PCM: case WAV_FMT_PCM:
f->enc = ENC_PCM; f->fmt = AFILE_FMT_PCM;
f->par.sig = (f->par.bits <= 8) ? 0 : 1; f->par.sig = (f->par.bits <= 8) ? 0 : 1;
break; break;
case WAV_FMT_ALAW: case WAV_FMT_ALAW:
f->enc = ENC_ALAW; f->fmt = AFILE_FMT_ALAW;
f->par.bits = 8; f->par.bits = 8;
f->par.bps = 1; f->par.bps = 1;
break; break;
case WAV_FMT_ULAW: case WAV_FMT_ULAW:
f->enc = ENC_ULAW; f->fmt = AFILE_FMT_ULAW;
f->par.bits = 8; f->par.bits = 8;
f->par.bps = 1; f->par.bps = 1;
break; break;
case WAV_FMT_FLOAT: case WAV_FMT_FLOAT:
f->enc = ENC_FLOAT; f->fmt = AFILE_FMT_FLOAT;
if (f->par.bits != 32) { if (f->par.bits != 32) {
log_puts("only 32-bit float supported\n"); log_puts("only 32-bit float supported\n");
return 0; return 0;
@ -454,23 +454,23 @@ afile_aiff_readcomm(struct afile *f, unsigned int csize,
} }
if (comp) { if (comp) {
if (memcmp(comm.comp_id, aiff_id_none, 4) == 0) { if (memcmp(comm.comp_id, aiff_id_none, 4) == 0) {
f->enc = ENC_PCM; f->fmt = AFILE_FMT_PCM;
f->par.bits = be16_get(&comm.base.bits); f->par.bits = be16_get(&comm.base.bits);
} else if (memcmp(comm.comp_id, aiff_id_fl32, 4) == 0) { } else if (memcmp(comm.comp_id, aiff_id_fl32, 4) == 0) {
f->enc = ENC_FLOAT; f->fmt = AFILE_FMT_FLOAT;
f->par.bits = 32; f->par.bits = 32;
} else if (memcmp(comm.comp_id, aiff_id_ulaw, 4) == 0) { } else if (memcmp(comm.comp_id, aiff_id_ulaw, 4) == 0) {
f->enc = ENC_ULAW; f->fmt = AFILE_FMT_ULAW;
f->par.bits = 8; f->par.bits = 8;
} else if (memcmp(comm.comp_id, aiff_id_alaw, 4) == 0) { } else if (memcmp(comm.comp_id, aiff_id_alaw, 4) == 0) {
f->enc = ENC_ALAW; f->fmt = AFILE_FMT_ALAW;
f->par.bits = 8; f->par.bits = 8;
} else { } else {
log_puts("unsupported encoding of .aiff file\n"); log_puts("unsupported encoding of .aiff file\n");
return 0; return 0;
} }
} else { } else {
f->enc = ENC_PCM; f->fmt = AFILE_FMT_PCM;
f->par.bits = be16_get(&comm.base.bits); f->par.bits = be16_get(&comm.base.bits);
} }
if (f->par.bits < BITS_MIN || f->par.bits > BITS_MAX) { if (f->par.bits < BITS_MIN || f->par.bits > BITS_MAX) {
@ -660,33 +660,33 @@ afile_au_readhdr(struct afile *f)
fmt = be32_get(&hdr.fmt); fmt = be32_get(&hdr.fmt);
switch (fmt) { switch (fmt) {
case AU_FMT_PCM8: case AU_FMT_PCM8:
f->enc = ENC_PCM; f->fmt = AFILE_FMT_PCM;
f->par.bits = 8; f->par.bits = 8;
break; break;
case AU_FMT_PCM16: case AU_FMT_PCM16:
f->enc = ENC_PCM; f->fmt = AFILE_FMT_PCM;
f->par.bits = 16; f->par.bits = 16;
break; break;
case AU_FMT_PCM24: case AU_FMT_PCM24:
f->enc = ENC_PCM; f->fmt = AFILE_FMT_PCM;
f->par.bits = 24; f->par.bits = 24;
break; break;
case AU_FMT_PCM32: case AU_FMT_PCM32:
f->enc = ENC_PCM; f->fmt = AFILE_FMT_PCM;
f->par.bits = 32; f->par.bits = 32;
break; break;
case AU_FMT_ULAW: case AU_FMT_ULAW:
f->enc = ENC_ULAW; f->fmt = AFILE_FMT_ULAW;
f->par.bits = 8; f->par.bits = 8;
f->par.bps = 1; f->par.bps = 1;
break; break;
case AU_FMT_ALAW: case AU_FMT_ALAW:
f->enc = ENC_ALAW; f->fmt = AFILE_FMT_ALAW;
f->par.bits = 8; f->par.bits = 8;
f->par.bps = 1; f->par.bps = 1;
break; break;
case AU_FMT_FLOAT: case AU_FMT_FLOAT:
f->enc = ENC_FLOAT; f->fmt = AFILE_FMT_FLOAT;
f->par.bits = 32; f->par.bits = 32;
f->par.bps = 4; f->par.bps = 4;
break; break;
@ -852,12 +852,12 @@ afile_seek(struct afile *f, off_t pos)
void void
afile_close(struct afile *f) afile_close(struct afile *f)
{ {
if (f->flags & WAV_FWRITE) { if (f->flags & AFILE_FWRITE) {
if (f->hdr == HDR_WAV) if (f->hdr == AFILE_HDR_WAV)
afile_wav_writehdr(f); afile_wav_writehdr(f);
else if (f->hdr == HDR_AIFF) else if (f->hdr == AFILE_HDR_AIFF)
afile_aiff_writehdr(f); afile_aiff_writehdr(f);
else if (f->hdr == HDR_AU) else if (f->hdr == AFILE_HDR_AU)
afile_au_writehdr(f); afile_au_writehdr(f);
} }
close(f->fd); close(f->fd);
@ -879,23 +879,23 @@ afile_open(struct afile *f, char *path, int hdr, int flags,
f->nch = nch; f->nch = nch;
f->flags = flags; f->flags = flags;
f->hdr = hdr; f->hdr = hdr;
if (hdr == HDR_AUTO) { if (hdr == AFILE_HDR_AUTO) {
f->hdr = HDR_RAW; f->hdr = AFILE_HDR_RAW;
ext = strrchr(path, '.'); ext = strrchr(path, '.');
if (ext != NULL) { if (ext != NULL) {
ext++; ext++;
if (strcasecmp(ext, "aif") == 0 || if (strcasecmp(ext, "aif") == 0 ||
strcasecmp(ext, "aiff") == 0 || strcasecmp(ext, "aiff") == 0 ||
strcasecmp(ext, "aifc") == 0) strcasecmp(ext, "aifc") == 0)
f->hdr = HDR_AIFF; f->hdr = AFILE_HDR_AIFF;
else if (strcasecmp(ext, "au") == 0 || else if (strcasecmp(ext, "au") == 0 ||
strcasecmp(ext, "snd") == 0) strcasecmp(ext, "snd") == 0)
f->hdr = HDR_AU; f->hdr = AFILE_HDR_AU;
else if (strcasecmp(ext, "wav") == 0) else if (strcasecmp(ext, "wav") == 0)
f->hdr = HDR_WAV; f->hdr = AFILE_HDR_WAV;
} }
} }
if (f->flags == WAV_FREAD) { if (f->flags == AFILE_FREAD) {
if (strcmp(path, "-") == 0) { if (strcmp(path, "-") == 0) {
f->path = "stdin"; f->path = "stdin";
f->fd = STDIN_FILENO; f->fd = STDIN_FILENO;
@ -908,22 +908,22 @@ afile_open(struct afile *f, char *path, int hdr, int flags,
return 0; return 0;
} }
} }
if (f->hdr == HDR_WAV) { if (f->hdr == AFILE_HDR_WAV) {
if (!afile_wav_readhdr(f)) if (!afile_wav_readhdr(f))
goto bad_close; goto bad_close;
} else if (f->hdr == HDR_AIFF) { } else if (f->hdr == AFILE_HDR_AIFF) {
if (!afile_aiff_readhdr(f)) if (!afile_aiff_readhdr(f))
goto bad_close; goto bad_close;
} else if (f->hdr == HDR_AU) { } else if (f->hdr == AFILE_HDR_AU) {
if (!afile_au_readhdr(f)) if (!afile_au_readhdr(f))
goto bad_close; goto bad_close;
} else { } else {
f->startpos = 0; f->startpos = 0;
f->endpos = -1; /* read until EOF */ f->endpos = -1; /* read until EOF */
f->enc = ENC_PCM; f->fmt = AFILE_FMT_PCM;
} }
f->curpos = f->startpos; f->curpos = f->startpos;
} else if (flags == WAV_FWRITE) { } else if (flags == AFILE_FWRITE) {
if (strcmp(path, "-") == 0) { if (strcmp(path, "-") == 0) {
f->path = "stdout"; f->path = "stdout";
f->fd = STDOUT_FILENO; f->fd = STDOUT_FILENO;
@ -936,7 +936,7 @@ afile_open(struct afile *f, char *path, int hdr, int flags,
return 0; return 0;
} }
} }
if (f->hdr == HDR_WAV) { if (f->hdr == AFILE_HDR_WAV) {
f->par.bps = (f->par.bits + 7) >> 3; f->par.bps = (f->par.bits + 7) >> 3;
if (f->par.bits > 8) { if (f->par.bits > 8) {
f->par.le = 1; f->par.le = 1;
@ -953,7 +953,7 @@ afile_open(struct afile *f, char *path, int hdr, int flags,
log_puts(": couldn't write .wav header\n"); log_puts(": couldn't write .wav header\n");
goto bad_close; goto bad_close;
} }
} else if (f->hdr == HDR_AIFF) { } else if (f->hdr == AFILE_HDR_AIFF) {
f->par.bps = (f->par.bits + 7) >> 3; f->par.bps = (f->par.bits + 7) >> 3;
if (f->par.bps > 1) if (f->par.bps > 1)
f->par.le = 0; f->par.le = 0;
@ -968,7 +968,7 @@ afile_open(struct afile *f, char *path, int hdr, int flags,
log_puts(": couldn't write .aiff header\n"); log_puts(": couldn't write .aiff header\n");
goto bad_close; goto bad_close;
} }
} else if (f->hdr == HDR_AU) { } else if (f->hdr == AFILE_HDR_AU) {
f->par.bits = (f->par.bits + 7) & ~7; f->par.bits = (f->par.bits + 7) & ~7;
f->par.bps = f->par.bits / 8; f->par.bps = f->par.bits / 8;
f->par.le = 0; f->par.le = 0;

View File

@ -22,22 +22,22 @@
struct afile { struct afile {
struct aparams par; /* file params */ struct aparams par; /* file params */
#define ENC_PCM 0 /* simple integers (fixed point) */ #define AFILE_FMT_PCM 0 /* integers (fixed point) */
#define ENC_ULAW 1 /* 8-bit mu-law */ #define AFILE_FMT_ULAW 1 /* 8-bit mu-law */
#define ENC_ALAW 2 /* 8-bit a-law */ #define AFILE_FMT_ALAW 2 /* 8-bit a-law */
#define ENC_FLOAT 3 /* IEEE 754 32-bit floats */ #define AFILE_FMT_FLOAT 3 /* IEEE 754 32-bit floats */
int enc; /* one of above */ int fmt; /* one of above */
int rate; /* file sample rate */ int rate; /* file sample rate */
int nch; /* file channel count */ int nch; /* file channel count */
#define HDR_AUTO 0 #define AFILE_HDR_AUTO 0 /* guess from file name */
#define HDR_RAW 1 #define AFILE_HDR_RAW 1 /* headerless aka "raw" file */
#define HDR_WAV 2 #define AFILE_HDR_WAV 2 /* microsoft .wav */
#define HDR_AIFF 3 #define AFILE_HDR_AIFF 3 /* apple .aiff */
#define HDR_AU 4 #define AFILE_HDR_AU 4 /* sun/next .au */
int hdr; /* header type */ int hdr; /* header type */
int fd; /* file descriptor */ int fd; /* file descriptor */
#define WAV_FREAD 1 /* open for reading */ #define AFILE_FREAD 1 /* open for reading */
#define WAV_FWRITE 2 /* open for writing */ #define AFILE_FWRITE 2 /* open for writing */
int flags; /* bitmap of above */ int flags; /* bitmap of above */
off_t curpos; /* read/write position (bytes) */ off_t curpos; /* read/write position (bytes) */
off_t startpos; /* where payload starts */ off_t startpos; /* where payload starts */

View File

@ -213,7 +213,7 @@ slot_new(char *path, int mode, struct aparams *par, int hdr,
s = xmalloc(sizeof(struct slot)); s = xmalloc(sizeof(struct slot));
if (!afile_open(&s->afile, path, hdr, if (!afile_open(&s->afile, path, hdr,
mode == SIO_PLAY ? WAV_FREAD : WAV_FWRITE, mode == SIO_PLAY ? AFILE_FREAD : AFILE_FWRITE,
par, rate, cmax - cmin + 1)) { par, rate, cmax - cmin + 1)) {
xfree(s); xfree(s);
return 0; return 0;
@ -235,17 +235,17 @@ slot_new(char *path, int mode, struct aparams *par, int hdr,
log_puts(", "); log_puts(", ");
log_putu(s->afile.rate); log_putu(s->afile.rate);
log_puts("Hz, "); log_puts("Hz, ");
switch (s->afile.enc) { switch (s->afile.fmt) {
case ENC_PCM: case AFILE_FMT_PCM:
aparams_log(&s->afile.par); aparams_log(&s->afile.par);
break; break;
case ENC_ULAW: case AFILE_FMT_ULAW:
log_puts("ulaw"); log_puts("ulaw");
break; break;
case ENC_ALAW: case AFILE_FMT_ALAW:
log_puts("alaw"); log_puts("alaw");
break; break;
case ENC_FLOAT: case AFILE_FMT_FLOAT:
log_puts("f32le"); log_puts("f32le");
break; break;
} }
@ -308,7 +308,7 @@ slot_init(struct slot *s)
s->cmin, s->cmax, s->cmin, s->cmax,
0, dev_pchan - 1, 0, dev_pchan - 1,
0, dev_pchan - 1); 0, dev_pchan - 1);
if (s->afile.enc != ENC_PCM || !aparams_native(&s->afile.par)) { if (s->afile.fmt != AFILE_FMT_PCM || !aparams_native(&s->afile.par)) {
dec_init(&s->conv, &s->afile.par, slot_nch); dec_init(&s->conv, &s->afile.par, slot_nch);
s->convbuf = s->convbuf =
xmalloc(s->round * slot_nch * sizeof(adata_t)); xmalloc(s->round * slot_nch * sizeof(adata_t));
@ -462,17 +462,17 @@ play_filt_dec(struct slot *s, void *in, void *out, int todo)
tmp = s->convbuf; tmp = s->convbuf;
if (tmp) { if (tmp) {
switch (s->afile.enc) { switch (s->afile.fmt) {
case ENC_PCM: case AFILE_FMT_PCM:
dec_do(&s->conv, in, tmp, todo); dec_do(&s->conv, in, tmp, todo);
break; break;
case ENC_ULAW: case AFILE_FMT_ULAW:
dec_do_ulaw(&s->conv, in, tmp, todo, 0); dec_do_ulaw(&s->conv, in, tmp, todo, 0);
break; break;
case ENC_ALAW: case AFILE_FMT_ALAW:
dec_do_ulaw(&s->conv, in, tmp, todo, 1); dec_do_ulaw(&s->conv, in, tmp, todo, 1);
break; break;
case ENC_FLOAT: case AFILE_FMT_FLOAT:
dec_do_float(&s->conv, in, tmp, todo); dec_do_float(&s->conv, in, tmp, todo);
break; break;
} }
@ -1190,23 +1190,23 @@ static int
opt_hdr(char *s, int *hdr) opt_hdr(char *s, int *hdr)
{ {
if (strcmp("auto", s) == 0) { if (strcmp("auto", s) == 0) {
*hdr = HDR_AUTO; *hdr = AFILE_HDR_AUTO;
return 1; return 1;
} }
if (strcmp("raw", s) == 0) { if (strcmp("raw", s) == 0) {
*hdr = HDR_RAW; *hdr = AFILE_HDR_RAW;
return 1; return 1;
} }
if (strcmp("wav", s) == 0) { if (strcmp("wav", s) == 0) {
*hdr = HDR_WAV; *hdr = AFILE_HDR_WAV;
return 1; return 1;
} }
if (strcmp("aiff", s) == 0) { if (strcmp("aiff", s) == 0) {
*hdr = HDR_AIFF; *hdr = AFILE_HDR_AIFF;
return 1; return 1;
} }
if (strcmp("au", s) == 0) { if (strcmp("au", s) == 0) {
*hdr = HDR_AU; *hdr = AFILE_HDR_AU;
return 1; return 1;
} }
log_puts(s); log_puts(s);
@ -1271,7 +1271,7 @@ main(int argc, char **argv)
cmin = 0; cmin = 0;
cmax = 1; cmax = 1;
aparams_init(&par); aparams_init(&par);
hdr = HDR_AUTO; hdr = AFILE_HDR_AUTO;
n_flag = 0; n_flag = 0;
port = NULL; port = NULL;
dev = NULL; dev = NULL;