Forgot to add iotest.c
[cantaveria.git] / sfx.c
blobc410b0020fe775f91a168b77562f794d9ddc59f7
1 #include <stdlib.h>
3 #include <list.h>
4 #include <loader.h>
5 #include <sfx.h>
7 float* sfx[SFX_COUNT];
8 int sfx_len[SFX_COUNT];
11 int load_sound(char* filename, sfx_id id){
12 /* load a wave file */
13 reader* r = data_open("sounds", filename);
14 if(r==NULL){
15 return -1;
18 int i;
19 for(i=0; i<40; i++){
20 read_byte(r);
23 int N = read_int(r) / 2;
24 float* buffer = malloc(N);
26 for(i=0; i<N; i++){
27 int s = read_short(r);
28 buffer[i] = s / 32767.0f;
31 sfx[id] = buffer;
32 sfx_len[id] = N;
34 loader_close(r);
35 return 0;
38 void play_sound(sfx_id id){