1 /* 2 Sound Server IO 3 */ 4 5 #ifndef SOUND_H 6 #define SOUND_H 7 8 #include <sys/types.h> 9 10 /* 11 * Sound flags type: 12 */ 13 #define snd_flags_t unsigned int 14 15 16 /* 17 * Sound priority levels: 18 */ 19 #define SND_PRIORITY_BACKGROUND 0 20 #define SND_PRIORITY_FOREGROUND 1 21 #define SND_PRIORITY_PREEMPT 2 22 23 24 /* 25 * Sound play options: 26 */ 27 #define SND_PLAY_OPTION_MUTE (1 << 0) 28 #define SND_PLAY_OPTION_REPEATING (1 << 1) 29 30 #ifdef HAVE_SDL_MIXER 31 #define SDL_H 32 #include <SDL/SDL.h> 33 #include <SDL/SDL_mixer.h> 34 #endif 35 36 /* 37 * Sound object play structure: 38 * 39 * For keeping track of currently playing sound objects. 40 */ 41 typedef struct { 42 43 /* Pointer to sound server specific play id. */ 44 void *data; 45 46 /* Last set volume (from 0.0 to 1.0). This is used to check 47 * if sound play values actually need to be adjusted when 48 * requested. 49 */ 50 float volume_left, volume_right; 51 52 /* Applied sample rate. */ 53 int sample_rate; 54 55 /* Play options. */ 56 snd_flags_t options; 57 #ifdef HAVE_SDL_MIXER 58 Mix_Chunk *chunk; 59 #endif 60 61 } snd_play_struct; 62 63 #define SND_PLAY(p) ((snd_play_struct *)(p)) 64 65 66 /* 67 * Recorder (sound server connection) structure: 68 */ 69 typedef struct { 70 71 #define SNDSERV_TYPE_NONE 0 72 #define SNDSERV_TYPE_Y 1 73 #define SNDSERV_TYPE_SDL 2 74 #define SOUND_DEFAULT 99 75 76 /* Sound server type, one of SNDSERV_TYPE_*. */ 77 int type; 78 79 /* Opaque pointer to the connection to the sound server. */ 80 void *con; 81 82 /* Current Audio parameters. */ 83 int sample_rate; 84 int sample_size; 85 int channels; 86 int bytes_per_cycle; 87 88 /* Current background music sound object being played (can be 89 * NULL to indicate no background music being played) 90 */ 91 snd_play_struct *background_music_sndobj; 92 93 } snd_recorder_struct; 94 95 #define SND_RECORDER(p) ((snd_recorder_struct *)(p)) 96 97 98 extern snd_recorder_struct *SoundInit( 99 void *core, 100 int type, 101 const char *connect_arg, 102 const char *start_arg, 103 void *window 104 ); 105 extern int SoundManageEvents(snd_recorder_struct *recorder); 106 extern void SoundShutdown(snd_recorder_struct *recorder); 107 108 extern int SoundChangeMode( 109 snd_recorder_struct *recorder, const char *mode_name 110 ); 111 112 extern snd_play_struct *SoundStartPlay( 113 snd_recorder_struct *recorder, 114 const char *object, /* Full path to object. */ 115 float volume_left, /* Volume, from 0.0 to 1.0. */ 116 float volume_right, 117 int sample_rate, /* Applied sample rate, can be 0. */ 118 snd_flags_t options /* Any of SND_PLAY_OPTION_*. */ 119 ); 120 extern void SoundStartPlayVoid( 121 snd_recorder_struct *recorder, 122 const char *object, /* Full path to object. */ 123 float volume_left, /* Volume, from 0.0 to 1.0. */ 124 float volume_right, 125 int sample_rate, /* Applied sample rate, can be 0. */ 126 snd_flags_t options /* Any of SND_PLAY_OPTION_*. */ 127 ); 128 extern void SoundPlayMute( 129 snd_recorder_struct *recorder, snd_play_struct *snd_play, 130 int mute 131 ); 132 extern void SoundChangePlayVolume( 133 snd_recorder_struct *recorder, snd_play_struct *snd_play, 134 float volume_left, /* Volume, from 0.0 to 1.0. */ 135 float volume_right 136 ); 137 extern void SoundChangePlaySampleRate( 138 snd_recorder_struct *recorder, snd_play_struct *snd_play, 139 int sample_rate /* Applied sample rate, can be 0. */ 140 ); 141 extern void SoundStopPlay( 142 snd_recorder_struct *recorder, snd_play_struct *snd_play 143 ); 144 145 extern int SoundMusicStartPlay( 146 snd_recorder_struct *recorder, 147 const char *object, /* Full path to object. */ 148 int repeats /* Number of repeats, -1 for infinate. */ 149 ); 150 extern int SoundMusicIsPlaying(snd_recorder_struct *recorder); 151 extern void SoundMusicStopPlay(snd_recorder_struct *recorder); 152 153 extern void SoundMixerGet( 154 snd_recorder_struct *recorder, const char *channel_name, 155 float *left, float *right /* 0.0 to 1.0 */ 156 ); 157 extern void SoundMixerSet( 158 snd_recorder_struct *recorder, const char *channel_name, 159 float left, float right /* 0.0 to 1.0 */ 160 ); 161 162 163 #endif /* SOUND_H */ 164