OSDN Git Service

Fix README.win32 for Win32 compilation. master
authorYing-Chun Liu (PaulLiu) <paulliu@debian.org>
Fri, 1 May 2015 08:34:18 +0000 (16:34 +0800)
committerYing-Chun Liu (PaulLiu) <paulliu@debian.org>
Fri, 1 May 2015 08:34:18 +0000 (16:34 +0800)
Fix fopen mode. Add "b" to fix the bug in win32.
Use int16_t instead of short.

README.win32
src/wfd.c
src/wfh.c

index 75c6630..204511d 100644 (file)
@@ -8,12 +8,12 @@ This program depends on libsndfile. So we need to have win32 libsndfile first.
 In Debian we can do the following to get libsndfile dll.
 
  1. apt-get source libsndfile
- 2. ./configure --disable-sqlite --disable-external-libs --host 'i586-mingw32msvc'; make
+ 2. ./configure --disable-sqlite --disable-external-libs --host 'i686-w64-mingw32'; make
  3. libsndfile-1.dll will be at src/.libs/
 
 Now we start build wavtool-pl.
 
- 1. ./configure --host 'i586-mingw32msvc' SNDFILE_LIBS="-L/tmp/libsndfile-*/src/.libs -lsndfile-1" SNDFILE_CFLAGS="-I/tmp/libsndfile-*/src/"
+ 1. ./configure --host 'i686-w64-mingw32' SNDFILE_LIBS="-L/tmp/libsndfile-*/src/.libs -lsndfile-1" SNDFILE_CFLAGS="-I/tmp/libsndfile-*/src/"
  2. make
  3. wavtool-pl.exe will be at src/
 
index e4bfe49..b0d89b7 100644 (file)
--- a/src/wfd.c
+++ b/src/wfd.c
@@ -19,6 +19,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <stdint.h>
 
 #include <sndfile.h>
 
@@ -91,11 +92,11 @@ double wfd_append_linear_volume(int frame, const int *p, const double *v) {
  * @param b sample B
  * @return sample of A mix B
  */
-short wfd_mix(short a, short b) {
+int16_t wfd_mix(int16_t a, int16_t b) {
   int a_t;
   int b_t;
   int r1;
-  short ret=0.0;
+  int16_t ret=0;
 
   a_t = ((int)a)+32768;
   b_t = ((int)b)+32768;
@@ -109,7 +110,7 @@ short wfd_mix(short a, short b) {
     }
   }
   r1 = r1 - 32768;
-  ret = ((short)r1);
+  ret = ((int16_t)r1);
   return ret;
 }
 
@@ -133,18 +134,18 @@ int wfd_append(const char *outputfilename, const char *inputfilename,
   FILE *outfile=NULL;
   SNDFILE *inputfile=NULL;
   SF_INFO inputfileinfo;
-  short *buf=NULL;
+  int16_t *buf=NULL;
   int p_f[7];
   double v_f[7];
   int currentFrame=0;
   int ovrFrames=0;
   int outputFrames=0;
   int i;
-  short sum;
+  int16_t sum;
   int c1,c2;
 
   memset(&inputfileinfo,0,sizeof(SF_INFO));
-  outfile = fopen(outputfilename,"r+");
+  outfile = fopen(outputfilename,"r+b");
   fseek(outfile,0,SEEK_END);
   if (inputfilename) {
     inputfile = sf_open(inputfilename,SFM_READ,&inputfileinfo);
@@ -208,22 +209,23 @@ int wfd_append(const char *outputfilename, const char *inputfilename,
        }
       }
     }
+    fflush(outfile);
     fseek(outfile,0,SEEK_CUR);
     ovr=0.0;
     ovrFrames=0;
   }
 
   /* output */
-  buf = (short *)malloc(sizeof(short)*(inputfileinfo.channels));
-  memset(buf,0,sizeof(short)*(inputfileinfo.channels));
+  buf = (int16_t *)malloc(sizeof(int16_t)*(inputfileinfo.channels));
+  memset(buf,0,sizeof(int16_t)*(inputfileinfo.channels));
 
   currentFrame = 0;
   for ( ; outputFrames > 0; outputFrames--) {
     if (inputfile) {
       int result1;
-      result1 = sf_readf_short(inputfile,buf,1);
+      result1 = (int)sf_readf_short(inputfile,buf,1);
       if (result1 < 1) {
-       memset(buf,0,sizeof(short)*(inputfileinfo.channels));
+       memset(buf,0,sizeof(int16_t)*(inputfileinfo.channels));
        sf_close(inputfile);
        inputfile=NULL;
       }
@@ -238,12 +240,12 @@ int wfd_append(const char *outputfilename, const char *inputfilename,
       double vf;
       sum = sum/inputfileinfo.channels;
       vf = wfd_append_linear_volume(currentFrame,p_f,v_f);
-      sum = (short)(((double)sum)*(vf/100.0));
+      sum = (int16_t)(((double)sum)*(vf/100.0));
     } else {
       sum=0;
     }
     if (ovrFrames>0) {
-      short d,r;
+      int16_t d,r;
       c1 = fgetc(outfile);
       if (c1 == EOF) {
        ovrFrames=0;
@@ -257,14 +259,16 @@ int wfd_append(const char *outputfilename, const char *inputfilename,
       fseek(outfile,-2,SEEK_CUR);
       d = (c1 & (0x00ff)) | (((c2 & 0x00ff) << 8) & 0xff00);
       r = wfd_mix(sum,d);
-      fputc( (char)(r & (0x00ff)), outfile);
-      fputc( (char)((r>>8) & 0x00ff), outfile);
+      fputc( (int)((r) & (0x00ff)), outfile);
+      fputc( (int)((r>>8) & 0x00ff), outfile);
+      fflush(outfile);
       fseek(outfile,0,SEEK_CUR);
       ovrFrames--;
     } else {
     wfd_append_normal:
-      fputc( (char)(sum & (0x00ff)), outfile);
-      fputc( (char)((sum>>8) & 0x00ff), outfile);
+      fputc( (int)((sum) & (0x00ff)), outfile);
+      fputc( (int)((sum>>8) & 0x00ff), outfile);
+      fflush(outfile);
       fseek(outfile,0,SEEK_CUR);
     }
     currentFrame++;
index 59097ff..782a970 100644 (file)
--- a/src/wfh.c
+++ b/src/wfh.c
@@ -43,6 +43,7 @@ int wfh_readint(FILE *file1,int len) {
     }
     ret = ret + (int)((c & 0x00ff)*(0x01<<(8*i)));
   }
+  fseek(file1,0,SEEK_CUR);
   return ret;
 }
 
@@ -63,6 +64,8 @@ void wfh_writeint(FILE *file1,int data, int len) {
     d = d/256;
     fputc(w,file1);
   }
+  fflush(file1);
+  fseek(file1,0,SEEK_CUR);
 }
 
 /**
@@ -72,7 +75,7 @@ void wfh_writeint(FILE *file1,int data, int len) {
  */
 void wfh_init(const char *filename) {
   FILE *file1=NULL;
-  file1 = fopen(filename,"w");
+  file1 = fopen(filename,"wb");
   if (!file1) {
     return;
   }
@@ -109,7 +112,7 @@ int wfh_getlength(const char *filename) {
   int ret=-1;
   char com1[100];
   int s;
-  file1=fopen(filename,"r");
+  file1=fopen(filename,"rb");
   if (!file1) {
     return ret;
   }
@@ -182,7 +185,7 @@ int wfh_putlength(const char *filename, int length) {
   int ret=-1;
   char com1[100];
   int s;
-  file1=fopen(filename,"r+");
+  file1=fopen(filename,"r+b");
   if (!file1) {
     return ret;
   }