Data-Over-Voice
[lcr.git] / genwave.c
index d0d024e..685b5fa 100644 (file)
--- a/genwave.c
+++ b/genwave.c
@@ -86,8 +86,8 @@ static short isdn_audio_alaw_to_s16[] =
 struct fmt {
        unsigned short  stereo; /* 1 = pcm, 2 = adpcm */
        unsigned short  channels; /* number of channels */
 struct fmt {
        unsigned short  stereo; /* 1 = pcm, 2 = adpcm */
        unsigned short  channels; /* number of channels */
-       unsigned long   sample_rate; /* sample rate */
-       unsigned long   data_rate; /* data rate */
+       unsigned int    sample_rate; /* sample rate */
+       unsigned int    data_rate; /* data rate */
        unsigned short  bytes_sample; /* bytes per sample (all channels) */
        unsigned short  bits_sample; /* bits per sample (one channel) */
 };
        unsigned short  bytes_sample; /* bytes per sample (all channels) */
        unsigned short  bits_sample; /* bits per sample (one channel) */
 };
@@ -97,16 +97,16 @@ void write_law(FILE *fp, char *name, char law)
        unsigned char buffer[256];
        struct fmt fmt;
        FILE *lfp;
        unsigned char buffer[256];
        struct fmt fmt;
        FILE *lfp;
-       unsigned long i;
+       unsigned int i;
        short sample;
        short sample;
-       unsigned long size, wsize;
+       unsigned int size, wsize;
+       int ret;
 
 
-       if ((lfp=fopen(name,"r")))
-       {
+       if ((lfp=fopen(name,"r"))) {
                /* get size */
                fseek(lfp, 0, SEEK_END);
                size = ftell(lfp);
                /* get size */
                fseek(lfp, 0, SEEK_END);
                size = ftell(lfp);
-               printf("samples: %ld\n", size);
+               printf("samples: %d\n", size);
                size += size;
                fseek(lfp, 0, SEEK_SET);
 
                size += size;
                fseek(lfp, 0, SEEK_SET);
 
@@ -119,26 +119,25 @@ void write_law(FILE *fp, char *name, char law)
                fprintf(fp, "WAVE");
 
                /* fmt */
                fprintf(fp, "WAVE");
 
                /* fmt */
-               fprintf(fp, "fmt %c%c%c%c", sizeof(fmt), 0, 0, 0);
+               fprintf(fp, "fmt %c%c%c%c", (unsigned int)sizeof(fmt), 0, 0, 0);
                fmt.stereo = 1;
                fmt.channels = 1;
                fmt.sample_rate = 8000;
                fmt.data_rate = 16000;
                fmt.bytes_sample = 2;
                fmt.bits_sample = 16;
                fmt.stereo = 1;
                fmt.channels = 1;
                fmt.sample_rate = 8000;
                fmt.data_rate = 16000;
                fmt.bytes_sample = 2;
                fmt.bits_sample = 16;
-               fwrite(&fmt, sizeof(fmt), 1, fp);
+               ret = fwrite(&fmt, sizeof(fmt), 1, fp);
 
                /* data */
                fprintf(fp, "data%c%c%c%c", (char)(size&0xff), (char)((size>>8)&0xff), (char)((size>>16)&0xff), (char)(size>>24));
                i = 0;
 
                /* data */
                fprintf(fp, "data%c%c%c%c", (char)(size&0xff), (char)((size>>8)&0xff), (char)((size>>16)&0xff), (char)(size>>24));
                i = 0;
-               while(i < size)
-               {
-                       fread(buffer, 1, 1, lfp);
+               while(i < size) {
+                       ret = fread(buffer, 1, 1, lfp);
                        if (law == 'a')
                                sample = isdn_audio_alaw_to_s16[*buffer];
                        else
                                sample = isdn_audio_ulaw_to_s16[*buffer];
                        if (law == 'a')
                                sample = isdn_audio_alaw_to_s16[*buffer];
                        else
                                sample = isdn_audio_ulaw_to_s16[*buffer];
-                       fwrite(&sample, 2, 1, fp);
+                       ret = fwrite(&sample, 2, 1, fp);
                        i+=2;
                }
 
                        i+=2;
                }
 
@@ -156,8 +155,7 @@ int main(int argc, char *argv[])
 {
        FILE *fp;
 
 {
        FILE *fp;
 
-       if (argc <= 1)
-       {
+       if (argc <= 1) {
                usage:
                printf("Usage:\n");
                printf("%s ulaw2wave <alaw file> <wav file>\n", argv[0]);
                usage:
                printf("Usage:\n");
                printf("%s ulaw2wave <alaw file> <wav file>\n", argv[0]);
@@ -165,29 +163,23 @@ int main(int argc, char *argv[])
                return(0);
        }
 
                return(0);
        }
 
-       if (!strcmp(argv[1], "alaw2wave"))
-       {
+       if (!strcmp(argv[1], "alaw2wave")) {
                if (argc <= 3)
                        goto usage;
                if (argc <= 3)
                        goto usage;
-               if ((fp=fopen(argv[3],"w")))
-               {
+               if ((fp=fopen(argv[3],"w"))) {
                        write_law(fp,argv[2],'a');
                        fclose(fp);
                        write_law(fp,argv[2],'a');
                        fclose(fp);
-               } else
-               {
+               } else {
                        printf("Cannot open wave file %s\n",argv[3]);
                }
        } else
                        printf("Cannot open wave file %s\n",argv[3]);
                }
        } else
-       if (!strcmp(argv[1], "ulaw2wave"))
-       {
+       if (!strcmp(argv[1], "ulaw2wave")) {
                if (argc <= 3)
                        goto usage;
                if (argc <= 3)
                        goto usage;
-               if ((fp=fopen(argv[3],"w")))
-               {
+               if ((fp=fopen(argv[3],"w"))) {
                        write_law(fp,argv[2],'u');
                        fclose(fp);
                        write_law(fp,argv[2],'u');
                        fclose(fp);
-               } else
-               {
+               } else {
                        printf("Cannot open wave file %s\n",argv[3]);
                }
        } else
                        printf("Cannot open wave file %s\n",argv[3]);
                }
        } else