diff --git a/bchunk.c b/bchunk.c index 52f1aa9..c2a69ff 100644 --- a/bchunk.c +++ b/bchunk.c @@ -47,10 +47,8 @@ #define CUELLEN 1024 #define SECTLEN 2352 -#define WAV_RIFF_HLEN 12 #define WAV_FORMAT_HLEN 24 #define WAV_DATA_HLEN 8 -#define WAV_HEADER_LEN WAV_RIFF_HLEN + WAV_FORMAT_HLEN + WAV_DATA_HLEN /* * Ugly way to convert integers to little-endian format. @@ -78,7 +76,6 @@ struct track_t { int num; - int mode; int audio; char *modes; char *extension; @@ -271,7 +268,8 @@ int writetrack(FILE *bf, struct track_t *track, char *bname) FILE *f; char buf[SECTLEN+10]; long sz, sect, realsz, reallen; - char c, *p, *p2, *ep; + char c; + int p; int32_t l; int16_t i; float fl; @@ -304,7 +302,7 @@ int writetrack(FILE *bf, struct track_t *track, char *bname) printf(" "); - if ((track->audio) && (towav)) { + if (track->audio && towav) { // RIFF header fputs("RIFF", f); l = htolel(reallen + WAV_DATA_HLEN + WAV_FORMAT_HLEN + 4); @@ -337,18 +335,12 @@ int writetrack(FILE *bf, struct track_t *track, char *bname) sect = track->startsect; fl = 0; while ((sect <= track->stopsect) && (fread(buf, SECTLEN, 1, bf) > 0)) { - if (track->audio) { - if (swabaudio) { - /* swap low and high bytes */ - p = &buf[track->bstart]; - ep = p + track->bsize; - while (p < ep) { - p2 = p + 1; - c = *p; - *p = *p2; - *p2 = c; - p += 2; - } + if (track->audio && swabaudio) { + /* swap low and high bytes */ + for (p = track->bstart; p < track->bstart + track->bsize; p += 2) { + c = buf[p]; + buf[p] = buf[p + 1]; + buf[p + 1] = c; } } if (fwrite(&buf[track->bstart], track->bsize, 1, f) < 1) { @@ -451,10 +443,8 @@ int main(int argc, char **argv) printf("%2d: %-12.12s ", track->num, p); track->modes = strdup(p); track->extension = NULL; - track->mode = 0; track->audio = 0; track->bsize = track->bstart = -1; - track->bsize = -1; track->startsect = track->stopsect = -1; gettrackmode(track, p); @@ -491,14 +481,13 @@ int main(int argc, char **argv) printf("\n\n"); - + printf("Writing tracks:\n\n"); for (track = tracks; (track); track = track->next) writetrack(binf, track, basefile); fclose(binf); fclose(cuef); - + return 0; } -