1dnl ==================================================================
2dnl Checks for sound
3dnl ==================================================================
4
5dnl AC_ARG_ENABLE(samplerate,
6dnl [  --disable-samplerate    disable libsamplerate support],
7dnl )
8HAVE_SAMPLERATE=no
9SAMPLERATE_LIBS=""
10if test "x$enable_samplerate" != "xno"; then
11	if test "x$PKG_CONFIG" != "x"; then
12		PKG_CHECK_MODULES([SAMPLERATE], [samplerate], HAVE_SAMPLERATE=yes,
13						  HAVE_SAMPLERATE=no)
14		if test "x$HAVE_SAMPLERATE" = "xyes"; then
15			AC_DEFINE(HAVE_SAMPLERATE, 1, [Define if you have libsamplerate])
16		fi
17	else
18		AC_CHECK_LIB(samplerate, src_callback_new, HAVE_SAMPLERATE=yes,
19					 HAVE_SAMPLERATE=no, [$LIBS])
20		if test "x$HAVE_SAMPLERATE" = "xyes"; then
21			AC_CHECK_HEADER(samplerate.h, HAVE_SAMPLERATE=yes,
22							HAVE_SAMPLERATE=no)
23			if test "x$HAVE_SAMPLERATE" = "xyes"; then
24				SAMPLERATE_LIBS="-lsamplerate"
25				AC_DEFINE(HAVE_SAMPLERATE, 1,
26						  [Define if you have libsamplerate])
27			fi
28		fi
29	fi
30fi
31AC_SUBST(SAMPLERATE_LIBS)
32dnl AM_CONDITIONAL(HAVE_SAMPLERATE, test "$HAVE_SAMPLERATE" = "yes")
33if test "x$HAVE_SAMPLERATE" = "xno"; then
34	AC_MSG_WARN([libsamplerate is required but was not found.]
35				[Sound will be disabled.])
36	enable_sound=no
37fi
38
39if test "x$enable_sound" != "xno"; then
40	AC_CHECK_LIB(mme, waveOutOpen, HAVE_LIBMME=yes)
41
42	AC_ARG_ENABLE(alsa,
43		[  --disable-alsa          disable checks for ALSA support])
44
45	AC_ARG_ENABLE(oss,
46		[  --disable-oss           disable checks for OSS support])
47
48	AC_ARG_ENABLE(sun,
49		[  --disable-sun           disable checks for Sun audio support])
50
51	AC_ARG_ENABLE(sound,
52		[  --disable-sound         disable sound outright])
53
54	unset SOUND_TYPES
55
56	HAVE_ALSA=no
57	if test "x$enable_alsa" != "xno"; then
58		if test "x$ac_cv_header_sys_asoundlib_h" = "xyes" -o \
59			"x$ac_cv_header_alsa_asoundlib_h" = "xyes"; then
60				AC_EGREP_CPP([QF_maGiC_VALUE],
61				[
62#include <alsa/asoundlib.h>
63#if defined(SND_LIB_MAJOR) && defined(SND_LIB_MINOR) && \
64	defined(SND_LIB_SUBMINOR)
65#if SND_LIB_MAJOR > 0 || (SND_LIB_MAJOR == 0 && SND_LIB_MINOR >= 9 && \
66			  SND_LIB_SUBMINOR >= 8)
67QF_maGiC_VALUE
68#endif
69#endif
70				],
71				SOUND_TYPES="$SOUND_TYPES ALSA"
72				QF_NEED(snd_output, [alsa])
73				QF_NEED(snd_render, [default])
74				ALSA_LIBS="-lasound"
75				HAVE_ALSA=yes,
76				AC_EGREP_CPP([QF_maGiC_VALUE],
77					[
78#include <sys/asoundlib.h>
79#if defined(SND_LIB_MAJOR) && defined(SND_LIB_MINOR) && \
80	defined(SND_LIB_SUBMINOR)
81#if SND_LIB_MAJOR > 0 || (SND_LIB_MAJOR == 0 && SND_LIB_MINOR >= 9 && \
82			  SND_LIB_SUBMINOR >= 8)
83QF_maGiC_VALUE
84#endif
85#endif
86					],
87					SOUND_TYPES="$SOUND_TYPES ALSA"
88					QF_NEED(snd_output, [alsa])
89					QF_NEED(snd_render, [default])
90					ALSA_LIBS="-lasound"
91					HAVE_ALSA=yes
92				)
93			)
94		fi
95	fi
96	AC_SUBST(ALSA_LIBS)
97
98	AC_ARG_ENABLE(jack,
99	[  --disable-jack          disable jack support],
100	)
101	HAVE_JACK=no
102	JACK_LIBS=""
103	if test "x$enable_jack" != "xno"; then
104		if test "x$PKG_CONFIG" != "x"; then
105			PKG_CHECK_MODULES([JACK], [jack], HAVE_JACK=yes, HAVE_JACK=no)
106			if test "x$HAVE_JACK" = "xyes"; then
107				AC_DEFINE(HAVE_JACK, 1, [Define if you have libjack])
108				SOUND_TYPES="$SOUND_TYPES JACK"
109				QF_NEED(snd_render, [jack])
110			fi
111		else
112			AC_CHECK_LIB(jack, jack_client_open, HAVE_JACK=yes, HAVE_JACK=no,
113						 [$LIBS])
114			if test "x$HAVE_JACK" = "xyes"; then
115				AC_CHECK_HEADER(jack/jack.h, HAVE_JACK=yes, HAVE_JACK=no)
116				if test "x$HAVE_JACK" = "xyes"; then
117					JACK_LIBS="-ljack"
118					AC_DEFINE(HAVE_JACK, 1, [Define if you have libjack])
119					SOUND_TYPES="$SOUND_TYPES JACK"
120					QF_NEED(snd_render, [jack])
121				fi
122			fi
123		fi
124	fi
125	AC_SUBST(JACK_LIBS)
126
127	SOUND_TYPES="$SOUND_TYPES DISK"
128	QF_NEED(snd_output, [disk])
129	QF_NEED(snd_render, [default])
130
131	dnl MME
132	if test "x$ac_cv_header_mme_mmsystem_h" = "xyes" -a \
133			"x$HAVE_LIBMME" = "xyes"; then
134		AC_EGREP_CPP([QF_maGiC_VALUE],
135			[
136#include <mme/mmsystem.h>
137#ifdef WAVE_OPEN_SHAREABLE
138QF_maGiC_VALUE
139#endif
140			],
141			SOUND_TYPES="$SOUND_TYPES MME"
142			QF_NEED(snd_output, [mme])
143			QF_NEED(snd_render, [default])
144			MME_LIBS="-lmme"
145		)
146	fi
147	AC_SUBST(MME_LIBS)
148
149	dnl OSS
150	HAVE_OSS=no
151	if test "x$enable_oss" != "xno" -a "x$ac_cv_header_sys_shm_h" = "xyes"; then
152		if test "x$ac_cv_header_sys_soundcard_h" = "xyes" -o \
153			"x$ac_cv_header_machine_soundcard_h" = "xyes" -o \
154			"x$ac_cv_header_linux_soundcard_h" = "xyes"; then
155		AC_EGREP_CPP([QF_maGiC_VALUE],
156			[
157#include <sys/soundcard.h>
158#ifdef SNDCTL_DSP_SETTRIGGER
159QF_maGiC_VALUE
160#endif
161			],
162			SOUND_TYPES="$SOUND_TYPES OSS"
163			QF_NEED(snd_output, [oss])
164			QF_NEED(snd_render, [default])
165			HAVE_OSS=yes
166			OSS_LIBS=
167			,
168			AC_EGREP_CPP([QF_maGiC_VALUE],
169				[
170#include <linux/soundcard.h>
171#ifdef SNDCTL_DSP_SETTRIGGER
172QF_maGiC_VALUE
173#endif
174				],
175				SOUND_TYPES="$SOUND_TYPES OSS"
176				QF_NEED(snd_output, [oss])
177				QF_NEED(snd_render, [default])
178				HAVE_OSS=yes
179				OSS_LIBS=
180				,
181				AC_EGREP_CPP([QF_maGiC_VALUE],
182					[
183#include <machine/soundcard.h>
184#ifdef SNDCTL_DSP_SETTRIGGER
185QF_maGiC_VALUE
186#endif
187					],
188					SOUND_TYPES="$SOUND_TYPES OSS"
189					QF_NEED(snd_output, [oss])
190					QF_NEED(snd_render, [default])
191					HAVE_OSS=yes
192					OSS_LIBS=
193				)
194			)
195		)
196		fi
197	fi
198	AC_SUBST(OSS_LIBS)
199
200	dnl SDL digital audio
201	if test "x$HAVE_SDL_AUDIO" = "xyes"; then
202		SOUND_TYPES="$SOUND_TYPES SDL"
203		QF_NEED(snd_output, [sdl])
204		QF_NEED(snd_render, [default])
205	fi
206
207	dnl SGI
208	if test "x$ac_cv_header_dmedia_audio_h" = "xyes"; then
209	   AC_EGREP_CPP([QF_maGiC_VALUE],
210			[
211#include <dmedia/audio.h>
212#ifdef AL_SAMPLE_16
213# ifdef AL_RATE
214QF_maGiC_VALUE
215# endif
216#endif
217			],
218			SOUND_TYPES="$SOUND_TYPES SGI"
219			QF_NEED(snd_output, [sgi])
220			QF_NEED(snd_render, [default])
221			SGISND_LIBS="-laudio")
222	fi
223	AC_SUBST(SGISND_LIBS)
224
225	dnl Sun
226	if test "x$enable_sun" != "xno"; then
227		if test "x$ac_cv_header_sys_audioio_h" = "xyes"; then
228			AC_EGREP_CPP([QF_maGiC_VALUE],
229				[
230#include <sys/audioio.h>
231#ifdef AUDIO_SETINFO
232QF_maGiC_VALUE
233#endif
234				],
235				SOUND_TYPES="$SOUND_TYPES SUN"
236				QF_NEED(snd_output, [sun])
237				QF_NEED(snd_render, [default])
238			)
239		fi
240	fi
241
242	dnl Win32
243	if test "x$ac_cv_header_windows_h" = "xyes"; then
244		SOUND_TYPES="$SOUND_TYPES Win32"
245		QF_NEED(snd_output, [win])
246		QF_NEED(snd_render, [default])
247		WINSND_LIBS="-lwinmm"
248		if test "x$ac_cv_header_dsound_h" = "xyes"; then
249		AC_EGREP_CPP([QF_maGiC_VALUE],
250			[
251#include <windows.h>
252#include <dsound.h>
253#ifdef GMEM_MOVEABLE
254# ifdef DirectSoundEnumerate
255QF_maGiC_VALUE
256# endif
257#endif
258			],
259			SOUND_TYPES="$SOUND_TYPES DirectX"
260			QF_NEED(snd_output, [dx])
261			QF_NEED(snd_render, [default])
262		)
263		fi
264	fi
265	AC_SUBST(WINSND_LIBS)
266
267fi
268