1 /*
2  * See Licensing and Copyright notice in naev.h
3  */
4 
5 
6 
7 #ifndef SOUND_PRIV_H
8 #  define SOUND_PRIV_H
9 
10 /*
11  * Private sound header, do not use outside of the sound subsystem.
12  */
13 
14 #if USE_OPENAL
15 #include OPENAL_AL_H
16 #endif /* USE_OPENAL */
17 
18 #if USE_SDLMIX
19 #include "SDL_mixer.h"
20 #endif /* USE_SDLMIX */
21 
22 
23 /*
24  * Flags.
25  */
26 #define VOICE_LOOPING      (1<<10) /* voice loops */
27 #define VOICE_STATIC       (1<<11) /* voice isn't relative */
28 
29 
30 #define MUSIC_FADEOUT_DELAY   1000 /**< Time it takes to fade out. */
31 #define MUSIC_FADEIN_DELAY    2000 /**< Time it takes to fade in. */
32 
33 
34 /**
35  * @struct alSound
36  *
37  * @brief Contains a sound buffer.
38  */
39 typedef struct alSound_ {
40    char *name; /**< Buffer's name. */
41    double length; /**< Length of the buffer. */
42 
43    /*
44     * Backend specific.
45     */
46    union {
47 #if USE_OPENAL
48       struct {
49          ALuint buf; /**< Buffer data. */
50       } al; /**< For OpenAL backend. */
51 #endif /* USE_OPENAL */
52 #if USE_SDLMIX
53       struct {
54          Mix_Chunk *buf;
55       } mix; /**< For SDL_mixer backend. */
56 #endif /* USE_SDLMIX */
57    } u; /**< For backend. */
58 } alSound;
59 
60 
61 /**
62  * @typedef voice_state_t
63  * @brief The state of a voice.
64  * @sa alVoice
65  */
66 typedef enum voice_state_ {
67    VOICE_STOPPED, /**< Voice is stopped. */
68    VOICE_PLAYING, /**< Voice is playing. */
69    VOICE_FADEOUT, /**< Voice is fading out. */
70    VOICE_DESTROY  /**< Voice should get destroyed asap. */
71 } voice_state_t;
72 
73 
74 /**
75  * @struct alVoice
76  *
77  * @brief Represents a voice in the game.
78  *
79  * A voice would be any object that is creating sound.
80  */
81 typedef struct alVoice_ {
82    struct alVoice_ *prev; /**< Linked list previous member. */
83    struct alVoice_ *next; /**< Linked list next member. */
84 
85    int id; /**< Identifier of the voice. */
86 
87    voice_state_t state; /**< Current state of the sound. */
88    unsigned int flags; /**< Voice flags. */
89 
90    /*
91     * Backend specific.
92     */
93    union {
94 #if USE_OPENAL
95       struct {
96          ALfloat pos[3]; /**< Position of the voice. */
97          ALfloat vel[3]; /**< Velocity of the voice. */
98          ALuint source; /**< Source current in use. */
99          ALuint buffer; /**< Buffer attached to the voice. */
100       } al; /**< For OpenAL backend. */
101 #endif /* USE_OPENAL */
102 #if USE_SDLMIX
103       struct {
104          int channel; /**< Channel sound is playing on. */
105       } mix; /**< For SDL_mixer backend. */
106 #endif /* USE_SDLMIX */
107    } u; /**< For backend. */
108 } alVoice;
109 
110 
111 /*
112  * Sound list.
113  */
114 extern alVoice *voice_active; /**< Active voices. */
115 
116 
117 /*
118  * Voice management.
119  */
120 void voice_lock (void);
121 void voice_unlock (void);
122 alVoice* voice_new (void);
123 int voice_add( alVoice* v );
124 alVoice* voice_get( int id );
125 
126 
127 #endif /* SOUND_PRIV_H */
128