summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Baldeck <alexander@archlinux.org>2004-09-29 06:39:57 +0000
committerAlexander Baldeck <alexander@archlinux.org>2004-09-29 06:39:57 +0000
commit92f7df43e255dda51f5ece57d2141645bd693afb (patch)
treed7c8ab8f85408d6aef341aea7cc01babbee5e57e
parentc9de7c64417f836358298a83e98a11e413892ac2 (diff)
downloadmana-92f7df43e255dda51f5ece57d2141645bd693afb.tar.gz
mana-92f7df43e255dda51f5ece57d2141645bd693afb.tar.bz2
mana-92f7df43e255dda51f5ece57d2141645bd693afb.tar.xz
mana-92f7df43e255dda51f5ece57d2141645bd693afb.zip
added simple soundpool (LoadItem)
-rw-r--r--src/sound/sound.cpp68
-rw-r--r--src/sound/sound.h115
2 files changed, 121 insertions, 62 deletions
diff --git a/src/sound/sound.cpp b/src/sound/sound.cpp
index f85f4927..900262d8 100644
--- a/src/sound/sound.cpp
+++ b/src/sound/sound.cpp
@@ -53,33 +53,35 @@
32/20 sounds realistic here.
*/
void TmwSound::Init(int voices, int mod_voices) {
- isOk = -1;
+ isOk = -1;
- if(mod_voices >= voices)
- throw("No voices left for SFX! Sound will be disabled!");
+ if(mod_voices >= voices)
+ throw("No voices left for SFX! Sound will be disabled!");
- install_timer();
- reserve_voices (voices, -1);
+ install_timer();
+ reserve_voices (voices, -1);
- #ifdef WIN32
- if (install_sound (DIGI_AUTODETECT, MIDI_AUTODETECT, NULL) < 0)
- #else
- if (install_sound (DIGI_AUTODETECT, MIDI_NONE, NULL) < 0)
- #endif
- throw("Could not initialize sound... :-(");
+ #ifdef WIN32
+ if (install_sound (DIGI_AUTODETECT, MIDI_AUTODETECT, NULL) < 0)
+ #else
+ if (install_sound (DIGI_AUTODETECT, MIDI_NONE, NULL) < 0)
+ #endif
+ throw("Could not initialize sound... :-(");
- if (install_mod (mod_voices) < 0)
- throw("Could not install MOD player... :-(");
+ if (install_mod (mod_voices) < 0)
+ throw("Could not install MOD player... :-(");
- mod = NULL;
- mid = NULL;
- sfx = NULL;
+ mod = NULL;
+ mid = NULL;
+ sfx = NULL;
- pan = 128;
- pitch=1000;
+ pan = 128;
+ pitch=1000;
- isOk = 0;
+ items = 0;
+
+ isOk = 0;
}
/**
@@ -126,6 +128,32 @@ void TmwSound::SetAdjVol(int adigi, int amid, int amod) {
}
/**
+ preloads a sound-item into buffer
+ char *fpath -> full path to file
+ char type -> type of item (TMWSOUND_MOD, TMWSOUND_MID, TMWSOUND_SFX)
+
+ NOTE:
+ only TMWSOUND_SFX items get preloaded. everything
+ else will only store the full path to the file
+*/
+TMWSOUND_SID TmwSound::LoadItem(char *fpath, char type) {
+ POOL_ITEM item;
+ if(type == TMWSOUND_SFX) {
+ item.data = (void*)load_sample(fpath);
+ if(item.data == NULL)
+ throw(sprintf("Unable to load sample: %s\n", fpath));
+ }
+
+ items++;
+ item.id = items;
+ item.type = type;
+ item.fname = fpath;
+
+ soundpool.push_front(item);
+ return item.id;
+}
+
+/**
start BGM using a midi file
char *in -> full path of midi file
int loop -> how many times should the midi be looped? (-1 = infinite)
@@ -230,7 +258,7 @@ void TmwSound::StopBGM() {
*/
void TmwSound::StartWAV(char * in, int pan) {
if(isOk==-1)
- return;
+ return;
sfx = load_sample(in);
if (!sfx)
diff --git a/src/sound/sound.h b/src/sound/sound.h
index 12300e58..4fbe3e45 100644
--- a/src/sound/sound.h
+++ b/src/sound/sound.h
@@ -24,8 +24,12 @@
#ifndef __SOUND_H
#define __SOUND_H
+#include <list>
+#include <string>
+#include <fstream>
+
#ifdef WIN32
- #pragma warning(disable:4312)
+ #pragma warning(disable:4312)
#endif
#include <allegro.h>
#include <jgmod.h>
@@ -33,51 +37,78 @@
using namespace std;
/**
- rewrite of non-existend sdl-soundengine using allegro
-
- Author: kth5 aka Alexander Baldeck
- pipe your question, suggestions and flames to: kth5@gawab.com
+ rewrite of non-existend sdl-soundengine using allegro
+
+ Bestviewd w/ Bitstream Vera Sans Mono @ 9pt and a tab-width of 2 spaces
- NOTE:
- i documented all functions in their implementation. ;-)
+ Author: kth5 aka Alexander Baldeck
+ pipe your question, suggestions and flames to: kth5@gawab.com
+
+ NOTE:
+ i documented all functions in their implementation. ;-)
*/
+#define TMWSOUND_MOD 1
+#define TMWSOUND_MID 2
+#define TMWSOUND_SFX 3
+
+typedef unsigned short TMWSOUND_SID ;
+
class TmwSound {
- public:
- void Init(int, int);
- int Close();
-
- void StartMIDI(char *, int);
- void StartMOD(char *, int);
- void StopBGM();
-
- void StartWAV(char *, int);
- void SetVol(int, int, int);
- void SetAdjVol(int adigi, int amid, int amod);
-
- TmwSound() {isOk=-1;}
- ~TmwSound() {StopBGM(); Close();}; // if allegros shuts down or object is deleted
- // any BGM is stopped and SFX runout
- private:
- int isOk; // initial value is -1 which means error.
- // you can only play sounds and bgm if this is 0.
- // should be the case after calling Init()
- // successfully
-
- MIDI * mid;
- JGMOD * mod;
- SAMPLE * sfx;
-
- int pan;
- int pitch;
-
- int ret;
- int vol_digi;
- int vol_midi;
- int vol_mod;
-
- bool isMaxVol(int);
-};
+ public:
+ void Init(int, int);
+ int Close();
+
+ void StartMIDI(char *, int);
+ void StartMOD(char *, int);
+ void StopBGM();
+
+ void StartWAV(char *, int);
+ void SetVol(int, int, int);
+ void SetAdjVol(int, int, int);
+ TMWSOUND_SID LoadItem(char *, char);
+
+ TmwSound() {isOk=-1;}
+
+ /* if allegro is shut down or object is deleted any BGM is
+ stopped and SFX run out */
+ ~TmwSound() {StopBGM(); Close();};
+ private:
+ /* initial value is -1 which means error or noninitialzed.
+ you can only play sounds and bgm if this is 0.
+ that should be the case after calling Init() successfully */
+ int isOk;
+
+ MIDI * mid;
+ JGMOD * mod;
+ SAMPLE * sfx;
+
+ int pan;
+ int pitch;
+
+ int ret;
+ int vol_digi;
+ int vol_midi;
+ int vol_mod;
+
+ typedef struct POOL_ITEM {
+ /* incremental id of pool item */
+ TMWSOUND_SID id;
+ /* type of item */
+ char type;
+ /* (file-)name of sfx only kept for human reasons ^_^ */
+ string fname;
+ /* generic data casted before used */
+ void * data;
+ };
+
+ /* list of preloaded sound data / items */
+ list<POOL_ITEM> soundpool;
+ list<POOL_ITEM>::iterator sounditem;
+ TMWSOUND_SID items;
+
+ bool isMaxVol(int);
+};
#endif