+
+/* ------------------------------------------------------------------------- */
+/* platform dependant audio initialization code */
+/* ------------------------------------------------------------------------- */
+
+#if defined(AUDIO_LINUX_IOCTL)
+static boolean InitAudioDevice_Linux(long fragment_size, int sample_rate)
+{
+ /* "ioctl()" expects pointer to 'int' value for stereo flag
+ (boolean is defined as 'char', which will not work here) */
+ int stereo = TRUE;
+ unsigned long fragment_spec = 0;
+
+ /* determine logarithm (log2) of the fragment size */
+ for (fragment_spec=0; (1 << fragment_spec) < fragment_size;
+ fragment_spec++);
+
+ /* use two fragments (play one fragment, prepare the other);
+ one fragment would result in interrupted audio output, more
+ than two fragments would raise audio output latency to much */
+ fragment_spec |= 0x00020000;
+
+ /* Example for fragment specification:
+ - 2 buffers / 512 bytes (giving 1/16 second resolution for 8 kHz)
+ - (with stereo the effective buffer size will shrink to 256)
+ => fragment_size = 0x00020009 */
+
+ if (ioctl(audio.device_fd, SNDCTL_DSP_SETFRAGMENT, &fragment_spec) < 0)
+ Error(ERR_EXIT_SOUND_SERVER,
+ "cannot set fragment size of /dev/dsp -- no sounds");
+
+ /* try if we can use stereo sound */
+ if (ioctl(audio.device_fd, SNDCTL_DSP_STEREO, &stereo) < 0)
+ {
+#ifdef DEBUG
+ static boolean reported = FALSE;
+
+ if (!reported)
+ {
+ Error(ERR_RETURN, "cannot get stereo sound on /dev/dsp");
+ reported = TRUE;
+ }
+#endif
+ stereo = FALSE;
+ }
+
+ if (ioctl(audio.device_fd, SNDCTL_DSP_SPEED, &sample_rate) < 0)
+ Error(ERR_EXIT_SOUND_SERVER,
+ "cannot set sample rate of /dev/dsp -- no sounds");
+
+ /* get the real fragmentation size; this should return 512 */
+ if (ioctl(audio.device_fd, SNDCTL_DSP_GETBLKSIZE, &fragment_size) < 0)
+ Error(ERR_EXIT_SOUND_SERVER,
+ "cannot get fragment size of /dev/dsp -- no sounds");
+
+ return (boolean)stereo;
+}
+#endif /* AUDIO_LINUX_IOCTL */
+
+#if defined(PLATFORM_NETBSD)
+static boolean InitAudioDevice_NetBSD(long fragment_size, int sample_rate)
+{
+ audio_info_t a_info;
+ boolean stereo = TRUE;
+
+ AUDIO_INITINFO(&a_info);
+ a_info.play.encoding = AUDIO_ENCODING_LINEAR8;
+ a_info.play.precision = 8;
+ a_info.play.channels = 2;
+ a_info.play.sample_rate = sample_rate;
+ a_info.blocksize = fragment_size;
+
+ if (ioctl(audio.device_fd, AUDIO_SETINFO, &a_info) < 0)
+ {
+ /* try to disable stereo */
+ a_info.play.channels = 1;
+ stereo = FALSE;
+
+ if (ioctl(audio.device_fd, AUDIO_SETINFO, &a_info) < 0)
+ Error(ERR_EXIT_SOUND_SERVER,
+ "cannot set sample rate of /dev/audio -- no sounds");
+ }
+
+ return stereo;
+}
+#endif /* PLATFORM_NETBSD */
+