Merge branch 'master' of git://github.com/BTAxis/naev into testmission
[naev.git] / src / sound_priv.h
blobe2e3d7a683c38e142c51a79b42a7feaec59b7918
1 /*
2 * See Licensing and Copyright notice in naev.h
3 */
7 #ifndef SOUND_PRIV_H
8 # define SOUND_PRIV_H
11 * Private sound header, do not use outside of the sound subsystem.
14 #if USE_OPENAL
15 #include OPENAL_AL_H
16 #endif /* USE_OPENAL */
18 #if USE_SDLMIX
19 #include "SDL_mixer.h"
20 #endif /* USE_SDLMIX */
24 * Flags.
26 #define VOICE_LOOPING (1<<10) /* voice loops */
27 #define VOICE_STATIC (1<<11) /* voice isn't relative */
30 #define MUSIC_FADEOUT_DELAY 1000 /**< Time it takes to fade out. */
31 #define MUSIC_FADEIN_DELAY 2000 /**< Time it takes to fade in. */
34 /**
35 * @struct alSound
37 * @brief Contains a sound buffer.
39 typedef struct alSound_ {
40 char *name; /**< Buffer's name. */
41 double length; /**< Length of the buffer. */
44 * Backend specific.
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;
61 /**
62 * @typedef voice_state_t
63 * @brief The state of a voice.
64 * @sa alVoice
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;
74 /**
75 * @struct alVoice
77 * @brief Represents a voice in the game.
79 * A voice would be any object that is creating sound.
81 typedef struct alVoice_ {
82 struct alVoice_ *prev; /**< Linked list previous member. */
83 struct alVoice_ *next; /**< Linked list next member. */
85 int id; /**< Identifier of the voice. */
87 voice_state_t state; /**< Current state of the sound. */
88 unsigned int flags; /**< Voice flags. */
91 * Backend specific.
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;
112 * Sound list.
114 extern alVoice *voice_active; /**< Active voices. */
118 * Voice management.
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 );
127 #endif /* SOUND_PRIV_H */