made some char pointers constant, added workaround for short files
authorkramm <kramm>
Wed, 12 Nov 2008 10:36:26 +0000 (10:36 +0000)
committerkramm <kramm>
Wed, 12 Nov 2008 10:36:26 +0000 (10:36 +0000)
lib/wav.c
lib/wav.h

index 86a8bb3..ff577c7 100644 (file)
--- 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];
@@ -131,13 +131,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 +151,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";
index 4a3126c..8f25326 100644 (file)
--- a/lib/wav.h
+++ b/lib/wav.h
@@ -19,8 +19,8 @@ struct WAV {
     unsigned int size;
 };
 
-int wav_read(struct WAV*wav, char* filename);
-int wav_write(struct WAV*wav, char*filename);
+int wav_read(struct WAV*wav, const char* filename);
+int wav_write(struct WAV*wav, const char*filename);
 void wav_print(struct WAV*wav);
 int wav_convert2mono(struct WAV*src, struct WAV*dest, int rate);