From 5825302e0394f676c0f31584783574d024536e9d Mon Sep 17 00:00:00 2001 From: Abramo Bagnara Date: Thu, 1 Jun 2000 11:37:43 +0000 Subject: [PATCH] Uros Bizjak : - fixes compilation (format.voices -> format.channels) - ntohl -> BE_INT for AU files - recoded AU_MAGIC header for AU files --- aplay/aplay.c | 37 +++++++++++++++++-------------------- aplay/formats.h | 8 ++++++-- 2 files changed, 23 insertions(+), 22 deletions(-) diff --git a/aplay/aplay.c b/aplay/aplay.c index 71ac679..df3e37a 100644 --- a/aplay/aplay.c +++ b/aplay/aplay.c @@ -35,7 +35,6 @@ #include #include #include -#include #include #include #include @@ -578,12 +577,12 @@ static int test_au(int fd, void *buffer) { AuHeader *ap = buffer; - if (ntohl(ap->magic) != AU_MAGIC) + if (ap->magic != AU_MAGIC) return -1; - if (ntohl(ap->hdr_size) > 128 || ntohl(ap->hdr_size) < 24) + if (BE_INT(ap->hdr_size) > 128 || BE_INT(ap->hdr_size) < 24) return -1; - count = ntohl(ap->data_size); - switch (ntohl(ap->encoding)) { + count = BE_INT(ap->data_size); + switch (BE_INT(ap->encoding)) { case AU_FMT_ULAW: format.format = SND_PCM_SFMT_MU_LAW; break; @@ -596,13 +595,13 @@ static int test_au(int fd, void *buffer) default: return -1; } - format.rate = ntohl(ap->sample_rate); + format.rate = BE_INT(ap->sample_rate); if (format.rate < 2000 || format.rate > 256000) return -1; - format.channels = ntohl(ap->channels); + format.channels = BE_INT(ap->channels); if (format.channels < 1 || format.channels > 128) return -1; - if (read(fd, buffer + sizeof(AuHeader), ntohl(ap->hdr_size) - sizeof(AuHeader)) < 0) { + if (read(fd, buffer + sizeof(AuHeader), BE_INT(ap->hdr_size) - sizeof(AuHeader)) < 0) { fprintf(stderr, "%s: read error\n", command); exit(EXIT_FAILURE); } @@ -735,7 +734,6 @@ static ssize_t pcm_write(u_char *data, size_t count) count = buffer_size; } while (count > 0) { - struct pollfd pfd; r = write_func(pcm_handle, data, count); if (r == -EAGAIN || (r >= 0 && r < count)) { struct pollfd pfd; @@ -1254,7 +1252,7 @@ static void begin_wave(int fd, size_t cnt) f.type = WAV_FMT; f.length = LE_INT(16); f.format = LE_INT(WAV_PCM_CODE); - f.modus = LE_SHORT(format.voices); + f.modus = LE_SHORT(format.channels); f.sample_fq = LE_INT(format.rate); #if 0 tmp2 = (samplesize == 8) ? 1 : 2; @@ -1262,7 +1260,7 @@ static void begin_wave(int fd, size_t cnt) tmp2 = dsp_speed * format.channels * tmp2; f.byte_p_sec = LE_SHORT(tmp2); #else - tmp2 = format.voices * ((bits + 7) / 8); + tmp2 = format.channels * ((bits + 7) / 8); f.byte_p_spl = LE_SHORT(tmp2); tmp2 = tmp2 * format.rate; f.byte_p_sec = LE_SHORT(tmp2); @@ -1285,25 +1283,25 @@ static void begin_au(int fd, size_t cnt) { AuHeader ah; - ah.magic = htonl(AU_MAGIC); - ah.hdr_size = htonl(24); - ah.data_size = htonl(cnt); + ah.magic = AU_MAGIC; + ah.hdr_size = BE_INT(24); + ah.data_size = BE_INT(cnt); switch (format.format) { case SND_PCM_SFMT_MU_LAW: - ah.encoding = htonl(AU_FMT_ULAW); + ah.encoding = BE_INT(AU_FMT_ULAW); break; case SND_PCM_SFMT_U8: - ah.encoding = htonl(AU_FMT_LIN8); + ah.encoding = BE_INT(AU_FMT_LIN8); break; case SND_PCM_SFMT_S16_LE: - ah.encoding = htonl(AU_FMT_LIN16); + ah.encoding = BE_INT(AU_FMT_LIN16); break; default: fprintf(stderr, "%s: Sparc Audio doesn't support %s format...\n", command, snd_pcm_get_format_name(format.format)); exit(EXIT_FAILURE); } - ah.sample_rate = htonl(format.rate); - ah.channels = htonl(format.channels); + ah.sample_rate = BE_INT(format.rate); + ah.channels = BE_INT(format.channels); if (write(fd, &ah, sizeof(AuHeader)) != sizeof(AuHeader)) { fprintf(stderr, "%s: write error\n", command); exit(EXIT_FAILURE); @@ -1507,7 +1505,6 @@ static void capture(char *name) void playbackv_go(int* fds, unsigned int channels, size_t loaded, size_t count, int rtype, char **names) { int r; - size_t c, expected; size_t vsize; unsigned int channel; u_char *bufs[channels]; diff --git a/aplay/formats.h b/aplay/formats.h index a26b473..c9bd144 100644 --- a/aplay/formats.h +++ b/aplay/formats.h @@ -48,10 +48,14 @@ typedef struct voc_ext_block { #define COMPOSE_ID(a,b,c,d) ((a) | ((b)<<8) | ((c)<<16) | ((d)<<24)) #define LE_SHORT(v) (v) #define LE_INT(v) (v) +#define BE_SHORT(v) bswap_16(v) +#define BE_INT(v) bswap_32(v) #else #define COMPOSE_ID(a,b,c,d) ((d) | ((c)<<8) | ((b)<<16) | ((a)<<24)) #define LE_SHORT(v) bswap_16(v) #define LE_INT(v) bswap_32(v) +#define BE_SHORT(v) (v) +#define BE_INT(v) (v) #endif #define WAV_RIFF COMPOSE_ID('R','I','F','F') @@ -88,14 +92,14 @@ typedef struct { /* Definitions for Sparc .au header */ -#define AU_MAGIC 0x2e736e64 +#define AU_MAGIC COMPOSE_ID('.','s','n','d') #define AU_FMT_ULAW 1 #define AU_FMT_LIN8 2 #define AU_FMT_LIN16 3 typedef struct au_header { - u_int magic; /* magic '.snd' */ + u_int magic; /* '.snd' */ u_int hdr_size; /* size of header (min 24) */ u_int data_size; /* size of data */ u_int encoding; /* see to AU_FMT_XXXX */