rocks_n_diamonds-0.9b
[rocksndiamonds.git] / src / sound.h
1 /***********************************************************
2 *  Rocks'n'Diamonds -- McDuffin Strikes Back!              *
3 *----------------------------------------------------------*
4 *  ©1995 Artsoft Development                               *
5 *        Holger Schemel                                    *
6 *        33659 Bielefeld-Senne                             *
7 *        Telefon: (0521) 493245                            *
8 *        eMail: aeglos@valinor.owl.de                      *
9 *               aeglos@uni-paderborn.de                    *
10 *               q99492@pbhrzx.uni-paderborn.de             *
11 *----------------------------------------------------------*
12 *  sound.c                                                 *
13 ***********************************************************/
14
15 #ifndef SOUND_H
16 #define SOUND_H
17
18 #include "main.h"
19 #include <math.h>
20
21 #ifdef linux
22 #include <linux/soundcard.h>
23 #ifndef VOXWARE
24 #define VOXWARE
25 #endif
26 /* where is the right declaration for 'ioctl'? */
27 extern void ioctl(long, long, void *);
28 #endif
29
30 #ifdef __FreeBSD__
31 #include <machine/soundcard.h>
32 #endif
33
34 #define SND_BLOCKSIZE 4096
35
36 #ifdef _HPUX_SOURCE
37 #include <sys/audio.h>
38 #undef  SND_BLOCKSIZE
39 #define SND_BLOCKSIZE 32768
40 #define HPUX_AUDIO
41 #endif /* _HPUX_SOURCE */
42
43 #define MAX_SOUNDS_PLAYING      16
44
45 /* some values for PlaySound(), StopSound() and friends */
46 #define PSND_SILENCE            0
47 #define PSND_MAX_VOLUME_BITS    7
48 #define PSND_MIN_VOLUME         0
49 #define PSND_MAX_VOLUME         (1 << PSND_MAX_VOLUME_BITS)
50 #define PSND_NO_LOOP            0
51 #define PSND_LOOP               1
52 #define PSND_MIDDLE             0
53 #define PSND_MAX_STEREO_BITS    7
54 #define PSND_MAX_STEREO         (1 << PSND_MAX_STEREO_BITS)
55 #define PSND_MAX_LEFT           (-PSND_MAX_STEREO)
56 #define PSND_MAX_RIGHT          (+PSND_MAX_STEREO)
57 #define PSND_MAX_LEFT2RIGHT_BITS (PSND_MAX_STEREO_BITS+1)
58 #define PSND_MAX_LEFT2RIGHT     (1 << PSND_MAX_LEFT2RIGHT_BITS)
59
60 #define SSND_FADE_SOUND         (1<<0)
61 #define SSND_FADE_ALL_SOUNDS    (1<<1)
62 #define SSND_FADING(x)          (x & (SSND_FADE_SOUND | SSND_FADE_ALL_SOUNDS))
63 #define SSND_STOP_SOUND         (1<<2)
64 #define SSND_STOP_ALL_SOUNDS    (1<<3)
65 #define SSND_STOPPING(x)        (x & (SSND_STOP_SOUND | SSND_STOP_ALL_SOUNDS))
66 #define SSND_ALL(x)             (x&(SSND_FADE_ALL_SOUNDS|SSND_STOP_ALL_SOUNDS))
67
68 #define TRUE    1
69 #define FALSE   0
70
71 /* settings for sound path, sound device, etc. */
72 #ifndef SND_PATH
73 #define SND_PATH        "./sounds"
74 #endif
75
76 #define DEV_AUDIO       "/dev/audio"
77 #define DEV_DSP         "/dev/dsp"
78
79 #ifdef  VOXWARE
80 #define SOUND_DEVICE    DEV_DSP
81 #else
82 #define SOUND_DEVICE    DEV_AUDIO
83 #endif
84
85 #define SOUND_OFF       0
86 #define SOUND_AVAILABLE 1
87
88 #ifdef NO_SOUNDS
89 #define SOUND_STATUS    SOUND_OFF
90 #else
91 #define SOUND_STATUS    SOUND_AVAILABLE
92 #endif
93
94 struct SoundHeader_SUN
95 {
96   unsigned long magic;
97   unsigned long hdr_size;
98   unsigned long data_size;
99   unsigned long encoding;
100   unsigned long sample_rate;
101   unsigned long channels;
102 };
103
104 struct SoundHeader_8SVX
105 {
106   char magic_FORM[4];
107   unsigned long chunk_size;
108   char magic_8SVX[4];
109 };
110
111 struct SoundInfo
112
113   char *name;
114   char *file_ptr, *data_ptr;
115   long file_len, data_len;
116 };
117
118 struct SoundControl
119 {
120   int nr;
121   int volume;
122   int stereo;
123   BOOL active;
124   BOOL loop;
125   BOOL fade_sound;
126   BOOL stop_sound;
127   BOOL stop_all_sounds;
128   int playingtime;
129   long playingpos;
130   long data_len;
131   char *data_ptr;
132 };
133
134 /* function from "misc.c" */
135 unsigned long be2long(unsigned long *);
136
137 /* sound server functions */
138 void SoundServer(void);
139 void SoundServer_InsertNewSound(struct SoundControl);
140 void SoundServer_StopSound(int);
141 void SoundServer_StopAllSounds(void);
142 void HPUX_Audio_Control(void);
143 unsigned char linear_to_ulaw(int);
144 int ulaw_to_linear(unsigned char);
145
146 /* application functions */
147 BOOL LoadSound(struct SoundInfo *);
148 void PlaySound(int);
149 void PlaySoundStereo(int, int);
150 void PlaySoundLoop(int);
151 void PlaySoundExt(int, int, int, BOOL);
152 void FadeSound(int);
153 void FadeSounds(void);
154 void StopSound(int);
155 void StopSounds(void);
156 void StopSoundExt(int, int);
157 void FreeSounds(int);
158
159 #endif