1 /*(GPL)
2 ---------------------------------------------------------------------------
3 	a_globals.h - Private global audio engine stuff
4 ---------------------------------------------------------------------------
5  * Copyright (C) 2001, 2002, David Olofson
6  *
7  * This program is free software; you can redistribute it and/or modify it
8  * under the terms of the GNU General Public License as published by the
9  * Free Software Foundation; either version 2.1 of the License, or (at your
10  * option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along
18  * with this program; if not, write to the Free Software Foundation, Inc.,
19  * 675 Mass Ave, Cambridge, MA 02139, USA.
20  */
21 
22 #ifndef _A_GLOBALS_H_
23 #define _A_GLOBALS_H_
24 
25 #ifndef	DBG
26 #	define	DBG(x)	x
27 #	define	DBG2(x)
28 #	define	DBG3(x)
29 #endif
30 
31 #include "config.h"
32 
33 #include "audio.h"
34 #include "a_pitch.h"
35 #include "a_commands.h"
36 
37 #ifdef DEBUG
38 #define	PROFILE_AUDIO
39 #endif
40 
41 #define AUDIO_USE_VU
42 #undef	AUDIO_LOCKING
43 
44 /*
45  * Various private types, defaults and limits...
46  */
47 
48 /* Voices; virtually no per-unit overhead. */
49 #define AUDIO_MAX_VOICES	32
50 
51 /* Busses; some overhead, but only for busses that are actually used. */
52 #define	AUDIO_MAX_BUSSES	8
53 
54 /* Bus inserts; minimal per-unit overhead. */
55 #define	AUDIO_MAX_INSERTS	2
56 
57 #define DEFAULT_VOL		65536
58 #define DEFAULT_RVB		65536
59 
60 #define	DEFAULT_LIM_RELEASE	(65536 * 1 / 44100)
61 #define	DEFAULT_LIM_THRESHOLD	32768
62 
63 #define SDL_FRAGMENTS		2
64 #define OSS_FRAGMENTS		3
65 #define	FREQ_BITS		20
66 #define	RAMP_BITS		15
67 #define	VOL_BITS		15
68 
69 /*
70  * Restriction caused by the limited fixed point
71  * range in the resampling voice mixers.
72  */
73 #define	MAX_FRAGMENT_SPAN	(1<<(32 - FREQ_BITS))
74 
75 /*
76  * Maximum size of internal mixing buffers, in frames.
77  *
78  * This is a cache thrashing limiter! Tune
79  * to best trade-off between cache footprint
80  * and looping overhead.
81  */
82 #define	MAX_BUFFER_SIZE		128
83 
84 /*
85  * Minimum *output* buffer size, in frames.
86  * This effectively sets a minimum latency limit.
87  */
88 #define	MIN_BUFFER_SIZE		16
89 
90 /*
91  * Safety limits to prevent locking up the engine with silly input.
92  */
93 #define	MAX_STEP ((AUDIO_MAX_MIX_RATE / AUDIO_MIN_OUTPUT_RATE) << FREQ_BITS)
94 #define MIN_LOOP ((AUDIO_MAX_MIX_RATE / AUDIO_MIN_OUTPUT_RATE) >> 1)
95 
96 /* Global engine settings  */
97 struct settings_t
98 {
99 	int		samplerate;
100 	unsigned	output_buffersize;
101 	unsigned	buffersize;
102 	audio_quality_t	quality;
103 };
104 extern struct settings_t a_settings;
105 
106 /* Defaults... */
107 extern accbank_t a_channel_def_ctl;
108 extern accbank_t a_group_def_ctl;
109 
110 extern abcbank_t a_bus_def_ctl;
111 
112 
113 /* For debug oscilloscope */
114 #ifdef DEBUG
115 #	define	OSCFRAMES	240
116 #	include "a_limiter.h"
117 	extern int *oscbufl;
118 	extern int *oscbufr;
119 	extern int oscframes;
120 	extern limiter_t limiter;
121 	extern int oscpos;
122 	void audio_print_info(void);
123 #endif
124 
125 /* For audio engine profiling */
126 #ifdef PROFILE_AUDIO
127 #	define AUDIO_CPU_FUNCTIONS	10
128 	extern int audio_cpu_ticks;
129 	extern float audio_cpu_total;
130 	extern float audio_cpu_function[AUDIO_CPU_FUNCTIONS];
131 	extern char audio_cpu_funcname[AUDIO_CPU_FUNCTIONS][20];
132 #endif
133 
134 extern int _audio_running;
135 
136 #endif /*_A_GLOBALS_H_*/
137