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