From: bogglez <bo...@us...> - 2017-03-09 19:39:11
|
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "A pseudo Operating System for the Dreamcast.". The branch, master has been updated via c77634aa22982a426e3423693e40a84c7a3b4ff1 (commit) via b84b7774361980f07703cf443ce4bef0e0fae17a (commit) from 9303b215c101f710bc04cb40adc3f2ebad1a104a (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit c77634aa22982a426e3423693e40a84c7a3b4ff1 Author: bogglez <bo...@pr...> Date: Thu Mar 9 20:38:25 2017 +0100 wav2adpcm: add man page commit b84b7774361980f07703cf443ce4bef0e0fae17a Author: bogglez <bo...@pr...> Date: Thu Mar 9 20:37:44 2017 +0100 wav2adpcm: add fread/fwrite error detection ----------------------------------------------------------------------- Summary of changes: utils/wav2adpcm/wav2adpcm.1 | 39 ++++++++++++++++++++++++++++++++ utils/wav2adpcm/wav2adpcm.c | 54 +++++++++++++++++++++++++++++++++------------ 2 files changed, 79 insertions(+), 14 deletions(-) create mode 100644 utils/wav2adpcm/wav2adpcm.1 diff --git a/utils/wav2adpcm/wav2adpcm.1 b/utils/wav2adpcm/wav2adpcm.1 new file mode 100644 index 0000000..3ea34f5 --- /dev/null +++ b/utils/wav2adpcm/wav2adpcm.1 @@ -0,0 +1,39 @@ +.TH WAV2ADPCM 1 "Mar 2017" "Version 1.0" +.SH NAME +wav2adpcm \- Convert between WAV and ADPCM audio data +.SH SYNOPSIS +.B wav2adpcm +.B \-t +.B \-f +.IR from.wav +.IR to.wav + +.SH DESCRIPTION +.B wav2adpcm +is used to convert WAV audio data to the ADPCM format supported by the +hardware of the SEGA Dreamcast game console. +.SH OPTIONS +.TP +.BI -t +Convert from WAV to ADPCM +.BI -f +Convert from ADPCM to WAV + +.SH EXAMPLES + +.EX +.B + wav2adpcm -t from.wav to_adpcm.wav +.EE + +.EX +.B + wav2adpcm -f from_adpcm.wav to.wav +.EE + +.SH AUTHOR +This manual page was initially written by Stefan Galowicz <bo...@pr...>, +for the KOS project. +.TP +The program has been initially written by BERO <be...@ge...> and modified by Dan Potter. +.SH SEE ALSO diff --git a/utils/wav2adpcm/wav2adpcm.c b/utils/wav2adpcm/wav2adpcm.c index 06e2ec2..02e5a5f 100644 --- a/utils/wav2adpcm/wav2adpcm.c +++ b/utils/wav2adpcm/wav2adpcm.c @@ -190,12 +190,16 @@ int wav2adpcm(const char *infile, const char *outfile) { in = fopen(infile, "rb"); - if(in == NULL) { + if(!in) { printf("can't open %s\n", infile); return -1; } - fread(&wavhdr, 1, sizeof(wavhdr), in); + if(fread(&wavhdr, sizeof(wavhdr), 1, in) != 1) { + fprintf(stderr, "Cannot read header.\n"); + fclose(in); + return -1; + } if(memcmp(wavhdr.hdr1, "RIFF", 4) || memcmp(wavhdr.hdr2, "WAVEfmt ", 8) @@ -204,7 +208,7 @@ int wav2adpcm(const char *infile, const char *outfile) { || wavhdr.format != 1 || (wavhdr.channels != 1 && wavhdr.channels != 2) || wavhdr.bits != 16) { - printf("unsupport format\n"); + fprintf(stderr, "Unsupported format.\n"); fclose(in); return -1; } @@ -215,7 +219,11 @@ int wav2adpcm(const char *infile, const char *outfile) { pcmbuf = malloc(pcmsize); adpcmbuf = malloc(adpcmsize); - fread(pcmbuf, 1, pcmsize, in); + if(fread(pcmbuf, pcmsize, 1, in) != 1) { + fprintf(stderr, "Cannot read data.\n"); + fclose(in); + return -1; + } fclose(in); if(wavhdr.channels == 1) { @@ -229,13 +237,18 @@ int wav2adpcm(const char *infile, const char *outfile) { pcm2adpcm(adpcmbuf + adpcmsize / 2, pcmbuf + pcmsize / 4, pcmsize / 2); } - out = fopen(outfile, "wb"); wavhdr.datasize = adpcmsize; wavhdr.format = 20; /* ITU G.723 ADPCM (Yamaha) */ wavhdr.bits = 4; wavhdr.totalsize = wavhdr.datasize + sizeof(wavhdr) - 8; - fwrite(&wavhdr, 1, sizeof(wavhdr), out); - fwrite(adpcmbuf, 1, adpcmsize, out); + + out = fopen(outfile, "wb"); + if(fwrite(&wavhdr, sizeof(wavhdr), 1, out) != 1 + || fwrite(adpcmbuf, adpcmsize, 1, out) != 1) { + fprintf(stderr, "Cannot write ADPCM data.\n"); + fclose(out); + return -1; + } fclose(out); return 0; @@ -250,12 +263,16 @@ int adpcm2wav(const char *infile, const char *outfile) { in = fopen(infile, "rb"); - if(in == NULL) { - printf("can't open %s\n", infile); + if(!in) { + fprintf(stderr, "Cannot open %s\n", infile); return -1; } - fread(&wavhdr, 1, sizeof(wavhdr), in); + if(fread(&wavhdr, sizeof(wavhdr), 1, in) != 1) { + fprintf(stderr, "Cannot read header.\n"); + fclose(in); + return -1; + } if(memcmp(wavhdr.hdr1, "RIFF", 4) || memcmp(wavhdr.hdr2, "WAVEfmt ", 8) @@ -264,7 +281,7 @@ int adpcm2wav(const char *infile, const char *outfile) { || wavhdr.format != 20 || (wavhdr.channels != 1 && wavhdr.channels != 2) || wavhdr.bits != 4) { - printf("unsupport format\n"); + fprintf(stderr, "Unsupported format.\n"); fclose(in); return -1; } @@ -274,7 +291,11 @@ int adpcm2wav(const char *infile, const char *outfile) { adpcmbuf = malloc(adpcmsize); pcmbuf = malloc(pcmsize); - fread(adpcmbuf, 1, adpcmsize, in); + if(fread(adpcmbuf, adpcmsize, 1, in) != 1) { + fprintf(stderr, "Cannot read data.\n"); + fclose(in); + return -1; + } fclose(in); if(wavhdr.channels == 1) { @@ -294,8 +315,13 @@ int adpcm2wav(const char *infile, const char *outfile) { wavhdr.bits = 16; out = fopen(outfile, "wb"); - fwrite(&wavhdr, 1, sizeof(wavhdr), out); - fwrite(pcmbuf, 1, pcmsize, out); + if(fwrite(&wavhdr, sizeof(wavhdr), 1, out) != 1 + || fwrite(pcmbuf, pcmsize, 1, out) != 1) { + fprintf(stderr, "Cannot write WAV data.\n"); + fclose(out); + return -1; + } + fclose(out); return 0; hooks/post-receive -- A pseudo Operating System for the Dreamcast. |