3 PROGRAM_NAME PROGRAM_VERSION - PROGRAM_DESCRIPTION
5 Copyright (C) 2003 Angel Ortega <angel@triptico.com>
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 as published by the Free Software Foundation; either version 2
10 of the License, or (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 http://www.triptico.com
34 extern int _frequency
;
58 c
+=(fgetc(f
) * 65536);
59 c
+=(fgetc(f
) * 16777216);
65 int load_sample(FILE * f
, int bits
)
77 s|=(((unsigned char)fgetc(f)) << 8);*/
85 void load_pcm_wave(FILE * f
, int * size
, int bits
, int channels
,
86 int frequency
, int ** lwave
, int ** rwave
)
92 ls
=(int *)malloc(*size
* sizeof(int));
95 rs
=(int *)malloc(*size
* sizeof(int));
99 for(n
=0;n
< *size
;n
++)
101 ls
[n
]=load_sample(f
, bits
);
104 rs
[n
]=load_sample(f
, bits
);
107 /* resample if needed */
108 if(frequency
!= _frequency
)
110 ls
=wave_resample(ls
, frequency
, size
);
113 rs
=wave_resample(rs
, frequency
, size
);
123 int * wave_resample(int * wave
, int freq
, int * size
)
131 ratio
=(double) freq
/ (double) _frequency
;
132 new_size
=(int)((double) (*size
) / ratio
);
134 new_wave
=(int *)malloc(new_size
* sizeof(int));
136 printf("wave_resample: ratio %f\n", (float)ratio
);
138 for(n
=i
=0;n
< new_size
;n
++,i
+=ratio
)
139 new_wave
[n
]=wave
[(int)i
];
143 /* free the old wave */
150 int load_wav_file(char * filename
, int * size
, int ** lwave
, int ** rwave
)
155 short int b_per_sec
,num_channels
,tag
;
156 char riffid
[5],waveid
[5],fmtid
[5],dataid
[5];
157 int wav_frequency
, wav_bits
;
161 if((f
=fopen(filename
,"r"))==NULL
)
170 if(strcmp(waveid
,"WAVE"))
185 num_channels
=fget16(f
);
186 wav_frequency
=fget32(f
);
189 wav_bits
=fget16(f
) / num_channels
;
192 fread(dummydata
,1,(size_t)flen
-14,f
);
197 if(wav_bits
==16) (*size
)/=2;
198 if(num_channels
==2) (*size
)/=2;
200 load_pcm_wave(f
, size
, wav_bits
, num_channels
,
201 wav_frequency
, &ls
, &rs
);