1 /*
2    Copyright (C) 2000 Andrew Henderson <hendersa@db.erau.edu>
3    Part of the Adonthell Project <http://adonthell.nongnu.org>
4 
5    Adonthell is free software; you can redistribute it and/or modify
6    it under the terms of the GNU General Public License as published by
7    the Free Software Foundation; either version 2 of the License, or
8    (at your option) any later version.
9 
10    Adonthell is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13    GNU General Public License for more details.
14 
15    You should have received a copy of the GNU General Public License
16    along with Adonthell.  If not, see <http://www.gnu.org/licenses/>.
17 */
18 
19 #ifndef __AUDIO_H__
20 #define __AUDIO_H__
21 
22 #include <SDL_mixer.h>
23 #include "prefs.h"
24 #include "py_object.h"
25 // #include "audio_loop.h"
26 
27 // We'll only load five waves into memory
28 #define NUM_WAVES 5
29 // We'll only load three .ogg files into memory
30 #define NUM_MUSIC 3
31 // We can play four SFX at once
32 #define NUM_CHANNELS 4
33 
34 class audio
35 {
36 public:
37     static void init(config*);
38     static void cleanup(void);
39 
40     // state saving/loading
41     static s_int8 put_state (ogzstream& file);
42     static s_int8 get_state (igzstream& file);
43 
44     // Background Music functions:
45     // Use these to load/unload background music
46     static int load_background(int slot, char *filename);
47     static void unload_background(int slot);
48 
49     // All input is clamped from 0 to 100
50     static void set_background_volume(int);
51 
52     // Use only when music is loaded
53     static void pause_music(void);
54     static void unpause_music(void);
55 
56     // Use these to load/unload wave files
57     static int load_wave(int slot, char *filename);
58     static void unload_wave(int slot);
59 
60     // Used to just start sounds playing
61     static void play_wave(int channel, int slot);
62     static void play_background(int slot);
63 
64     // Fade in and fade out background music (time in ms)
65     // Fadeout unselects current tune when done
66     static void fade_in_background(int slot, int time);
67     static void fade_out_background(int time);
68 
69     // Temporary convience function to change background
70     static void change_background(int slot, int time);
71 
is_initialized()72     static bool is_initialized () { return audio_initialized; }
is_schedule_activated()73     static bool is_schedule_activated () { return schedule_active; }
is_background_finished()74     static bool is_background_finished () { return !Mix_PlayingMusic (); }
75 
set_schedule_active(bool a)76     static void set_schedule_active (bool a) { schedule_active = a; }
77 
78     static void set_schedule (string file, PyObject * args = NULL);
79     static void run_schedule ();
80 
81 #ifdef OGG_MUSIC
82     // static loop_info *loop[NUM_MUSIC];
83 
84     // static int get_loop_start() { return loop[current_background]->start; }
85     // static int get_loop_end() { return loop[current_background]->end; }
86     // static int get_start_page_pcm() { return loop[current_background]->start_page_pcm; }
87     // static int get_start_page_raw() { return loop[current_background]->start_page_raw; }
88     // static OggVorbis_File* get_vorbisfile();
89 #endif
90 
91 private:
92 #ifndef SWIG
93     static bool schedule_active;
94     static bool audio_initialized;
95     static int background_volume;
96     static int effects_volume;
97     static Mix_Music *music[NUM_MUSIC];
98     static string music_file[NUM_MUSIC];
99     static Mix_Chunk *sounds[NUM_WAVES];
100     static int current_background;
101     static int last_background;
102     static bool background_paused;
103     static int audio_rate;
104     static Uint16 buffer_size;
105     static Uint16 audio_format;
106     static int audio_channels;
107     static py_object schedule;
108     static PyObject *schedule_args;
109 #endif
110 };
111 
112 #endif
113