partilces get velocity from originating lilanek
[Lilanci.git] / snd.c
blob17fe2777fb0391ca4db5f93a3ab5c7195861a909
1 #include "snd.h"
2 #include <SDL/SDL.h>
3 #include <SDL/SDL_mixer.h>
4 #include <stdlib.h>
5 #include <string.h>
7 typedef struct{
8 Mix_Chunk *sound;
9 char *filename;
10 }TSound;
12 typedef struct{
13 TSound *sounds;
14 int allocated;
15 int no_sounds;
16 }TSoundLibrary;
18 TSoundLibrary g_snd_lib;
20 int RegenerateSounds(){
21 printf("RegenerateSounds not implemented\n");
22 return 0;
25 void InvalidateSounds(){
26 printf("InvalidateSounds not implemented\n");
29 void PlaySound(int id){
30 int channel;
31 if(id<0 || id>=g_snd_lib.no_sounds) return;
32 channel = Mix_PlayChannel(id, g_snd_lib.sounds[id].sound, 0);
33 if(channel == -1) {
34 fprintf(stderr, "Unable to play WAV file: %s\n", Mix_GetError());
36 printf("Play sound %d\n",id);
39 int LoadSound(char *path){
40 int i;
41 if((i=(++g_snd_lib.no_sounds))>g_snd_lib.allocated){
42 g_snd_lib.allocated *=2;
43 g_snd_lib.allocated +=1;
44 g_snd_lib.sounds = realloc(g_snd_lib.sounds, sizeof(TSound)* g_snd_lib.allocated);
46 i--;
47 g_snd_lib.sounds[i].filename = calloc(strlen(path)+1,sizeof(char));
48 strcpy(g_snd_lib.sounds[i].filename, path);
49 g_snd_lib.sounds[i].sound = Mix_LoadWAV(path);
50 if(g_snd_lib.sounds[i].sound == NULL) {
51 fprintf(stderr, "Unable to load WAV file: %s\n", Mix_GetError());
54 return i;
57 void DestroySound(int id){
58 printf("DestroySound not implemented\n");
61 void SoundInit(){
62 int audio_rate = 22050;
63 Uint16 audio_format = AUDIO_S16SYS;
64 int audio_channels = 2;
65 int audio_buffers = 4096;
67 if(Mix_OpenAudio(audio_rate, audio_format, audio_channels, audio_buffers) != 0) {
68 fprintf(stderr, "Unable to initialize audio: %s\n", Mix_GetError());
69 exit(1);
72 memset(&g_snd_lib, 0, sizeof(TSoundLibrary));
74 void SoundKill(){
75 Mix_CloseAudio();
78 void SoundDestroyAll(){
79 printf("SoundDestroyAll not implemented\n");