X-Git-Url: http://git.asbjorn.biz/?p=swftools.git;a=blobdiff_plain;f=lib%2Fwav.c;h=5bd30d7921fdb3fec1e89e2bc7923f505c2363bd;hp=72d95025f319ebb066f28d439418c0b99dc20bff;hb=2c719855eac434f01d47ba0717d76de65939d74e;hpb=3ef17c4cee41231e1eed731c08381d3ddf0c8d1a diff --git a/lib/wav.c b/lib/wav.c index 72d9502..5bd30d7 100644 --- a/lib/wav.c +++ b/lib/wav.c @@ -46,7 +46,7 @@ int getWAVBlock(FILE*fi, struct WAVBlock*block) return 1; } -int wav_read(struct WAV*wav, char* filename) +int wav_read(struct WAV*wav, const char* filename) { FILE*fi = fopen(filename, "rb"); unsigned char b[16]; @@ -74,22 +74,20 @@ int wav_read(struct WAV*wav, char* filename) return 0; } if(block.size + 8 < filesize) - fprintf(stderr, "wav_read: warning - more tags (%d extra bytes)\n", - filesize - block.size - 8); + fprintf(stderr, "wav_read: warning - more tags (%lu extra bytes)\n", filesize - block.size - 8); if(block.size == filesize) /* some buggy software doesn't generate the right tag length */ block.size = filesize - 8; if(block.size + 8 > filesize) - fprintf(stderr, "wav_read: warning - short file (%d bytes missing)\n", - block.size + 8 - filesize); + fprintf(stderr, "wav_read: warning - short file (%lu bytes missing)\n", block.size + 8 - filesize); if(fread(b, 1, 4, fi) < 4) { fclose(fi); return 0; } - if(strncmp(b, "WAVE", 4)) + if(strncmp((const char*)b, "WAVE", 4)) { fprintf(stderr, "wav_read: not a WAV file (2)\n"); fclose(fi); @@ -123,7 +121,7 @@ int wav_read(struct WAV*wav, char* filename) if (!strncmp(block.id, "data", 4)) { int l; - wav->data = malloc(block.size); + wav->data = (unsigned char*)malloc(block.size); if(!wav->data) { fprintf(stderr, "Out of memory (%d bytes needed)", block.size); @@ -131,13 +129,17 @@ int wav_read(struct WAV*wav, char* filename) return 0; } l = fread(wav->data, 1, block.size, fi); - if(l < block.size) - { - fprintf(stderr, "Error while reading data block of size %d (%d bytes missing)", block.size, block.size-l); + if(l<=0) { + fprintf(stderr, "Error: Couldn't read WAV data block\n"); fclose(fi); return 0; + } else if(l < block.size) + { + fprintf(stderr, "Warning: data block of size %d is only %d bytes (%d bytes missing)\n", block.size, l, block.size-l); + wav->size = l; + } else { + wav->size = block.size; } - wav->size = block.size; } pos+=block.size; fseek(fi, pos, SEEK_SET); @@ -147,7 +149,7 @@ int wav_read(struct WAV*wav, char* filename) return 1; } -int wav_write(struct WAV*wav, char*filename) +int wav_write(struct WAV*wav, const char*filename) { FILE*fi = fopen(filename, "wb"); char*b="RIFFWAVEfmt \x10\0\0\0data"; @@ -194,7 +196,7 @@ int wav_write(struct WAV*wav, char*filename) void wav_print(struct WAV*wav) { - printf("tag:%04x channels:%d samples/sec:%d bytes/sec:%d align:%d bits/sample:%d size:%d\n", + printf("tag:%04x channels:%d samples/sec:%lu bytes/sec:%lu align:%d bits/sample:%d size:%d\n", wav->tag, wav->channels, wav->sampsPerSec, wav->bytesPerSec, wav->align, wav->bps, wav->size); }