SDLGameEngine

src/sgesound.c

00001 /*
00002  * Copyright (c) 2007 Heiko Irrgang
00003  *
00004  * The license and distribution terms for this file may be
00005  * found in the file COPYING in this distribution or at
00006  * http://93-interactive.com/cms/products/software/sdl-game-engine/license/
00007  */
00008 
00009 #include <sge.h>
00010 
00011 int sgeDefaultSampleRate=44100;
00012 
00013 void sgeSetDefaultSampleRate(int rate) {
00014         sgeDefaultSampleRate=rate;
00015 }
00016 
00017 int sgeGetDefaultSampleRate() {
00018         return sgeDefaultSampleRate;
00019 }
00020 
00021 int sgeGlobalVolume=MIX_MAX_VOLUME;
00022 
00023 void sgeSetVolume(int volume) {
00024         sgeGlobalVolume=volume;
00025         Mix_Volume(-1, volume);
00026 }
00027 
00028 int sgeGetVolume() {
00029         return sgeGlobalVolume;
00030 }
00031 
00032 SGESOUND *sgeSoundNew(SGEFILE *f, const char *name) {
00033         SGESOUND *ret;
00034         sgeNew(ret, SGESOUND);
00035         ret->data=sgeReadSound(f, name);
00036         ret->playing=0;
00037         ret->channel=-1;
00038         return ret;
00039 }
00040 
00041 void sgeSoundDestroy(SGESOUND *m) {
00042         if (m->playing) {
00043                 Mix_HaltChannel(m->channel);
00044         }
00045         Mix_FreeChunk(m->data);
00046         sgeFree(m);
00047 }
00048 
00049 void sgeSoundPlay(SGESOUND *m, int loop, int fadeinms) {
00050         if (m->playing) return;
00051 
00052         if (fadeinms==0) {
00053                 m->channel=Mix_PlayChannel(-1, m->data, loop);
00054         } else {
00055                 m->channel=Mix_FadeInChannel(-1, m->data, loop, fadeinms);
00056         }
00057         m->playing=1;
00058 }
00059 
00060 void sgeSoundStop(SGESOUND *m, int fadeoutms) {
00061         if (!m->playing) return;
00062 
00063         if (fadeoutms==0) {
00064                 Mix_HaltChannel(m->channel);
00065         } else {
00066                 Mix_FadeOutChannel(m->channel, fadeoutms);
00067         }
00068         m->channel=-1;
00069         m->playing=0;
00070 }
00071 
00072 int sgeSoundIsPlaying(SGESOUND *m) {
00073         if (m->channel<0) return 0;
00074         return Mix_Playing(m->channel);
00075 }
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines