1 /*
2  *  This program is free software; you can redistribute it and/or modify
3  *  it under the terms of the GNU General Public License as published by
4  *  the Free Software Foundation; either version 2 of the License, or
5  *  (at your option) any later version.
6  *
7  *  This program is distributed in the hope that it will be useful,
8  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
9  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10  *  GNU General Public License for more details.
11  *
12  *  You should have received a copy of the GNU General Public License
13  *  along with this program; if not, write to the Free Software
14  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
15  */
16 
17 #ifndef LIBS_SOUND_SOUND_H_ // try avoiding collisions on id
18 #define LIBS_SOUND_SOUND_H_
19 
20 #include "types.h"
21 #include "audiocore.h"
22 #include "decoders/decoder.h"
23 #include "libs/threadlib.h"
24 #include "libs/sndlib.h"
25 
26 
27 #define FIRST_SFX_SOURCE 0
28 #define LAST_SFX_SOURCE  (FIRST_SFX_SOURCE + NUM_SFX_CHANNELS - 1)
29 #define MUSIC_SOURCE (LAST_SFX_SOURCE + 1)
30 #define SPEECH_SOURCE (MUSIC_SOURCE + 1)
31 #define NUM_SOUNDSOURCES (SPEECH_SOURCE + 1)
32 
33 typedef struct
34 {
35 	int in_use;
36 	audio_Object buf_name;
37 	intptr_t data; // user-defined data
38 } TFB_SoundTag;
39 
40 typedef struct tfb_soundcallbacks
41 {
42 	// return TRUE to continue, FALSE to abort
43 	bool (* OnStartStream) (TFB_SoundSample*);
44 	// return TRUE to continue, FALSE to abort
45 	bool (* OnEndChunk) (TFB_SoundSample*, audio_Object);
46 	// return TRUE to continue, FALSE to abort
47 	void (* OnEndStream) (TFB_SoundSample*);
48 	// tagged buffer callback
49 	void (* OnTaggedBuffer) (TFB_SoundSample*, TFB_SoundTag*);
50 	// buffer just queued
51 	void (* OnQueueBuffer) (TFB_SoundSample*, audio_Object);
52 } TFB_SoundCallbacks;
53 
54 
55 extern int musicVolume;
56 extern float musicVolumeScale;
57 extern float sfxVolumeScale;
58 extern float speechVolumeScale;
59 
60 void StopSource (int iSource);
61 void CleanSource (int iSource);
62 
63 void SetSFXVolume (float volume);
64 void SetSpeechVolume (float volume);
65 
66 TFB_SoundSample *TFB_CreateSoundSample (TFB_SoundDecoder*, uint32 num_buffers,
67 		const TFB_SoundCallbacks* /* can be NULL */);
68 void TFB_DestroySoundSample (TFB_SoundSample*);
69 void TFB_SetSoundSampleData (TFB_SoundSample*, void* data);
70 void* TFB_GetSoundSampleData (TFB_SoundSample*);
71 void TFB_SetSoundSampleCallbacks (TFB_SoundSample*,
72 		const TFB_SoundCallbacks* /* can be NULL */);
73 TFB_SoundDecoder* TFB_GetSoundSampleDecoder (TFB_SoundSample*);
74 
75 TFB_SoundTag* TFB_FindTaggedBuffer (TFB_SoundSample*, audio_Object buffer);
76 void TFB_ClearBufferTag (TFB_SoundTag*);
77 bool TFB_TagBuffer (TFB_SoundSample*, audio_Object buffer, intptr_t data);
78 
79 #include "stream.h"
80 
81 #endif // LIBS_SOUND_SOUND_H_
82