Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up code #14

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 11 additions & 22 deletions bchunk.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -78,7 +76,6 @@

struct track_t {
int num;
int mode;
int audio;
char *modes;
char *extension;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}