#!/bin/bash
#
# Configure the PCSP-driver Version 0.9
#

cat <<END

Configuring the Alternate Sound-driver for Linux 0.9
====================================================

Since version 0.6 the driver automatically tests the speed of your
computer and configure the PCSP-driver at kernel-startup. If your
machine is too slow (cannot play with more than 12500 Hz) the driver
is disabled and you here a beep.
However, you can override this if you specify a 'pcsp=SAMPLERATE' at
kernel commandline or by disabling the automatic speed detection.

THIS IS NOT RECOMMENDED, your machine may HANG if you select a
samplerate, which is to high for your machine.
If the measurement switch the driver off but the version 0.5 was working
on your machine, please contact me.

END

cat <<END >local.h
/*
 * local.h
 *
 * /dev/pcsp implementation (dsp & audio for PC Speaker and DACs)
 *
 * Copyright (C) 1993, 1994, 1995  Michael Beck
 * 
 * ---> This file was generated by configure. Don't edit! <---
 */

END

echo -n "Disable automatic speed detection [y/N] "
read answer
if [ "$answer" = "y" ] ; then
	echo "#undef PCSP_TEST_SPEED" >>local.h
	echo "This is REALLY a bad idea!"
	while true
	do
		echo -n "Enter a samplerate for PCSP [12500-18356] :"
                read answer
		answer=${answer:-0}
		if [ $answer -le 18356 ] ; then
                        if [ $answer -ge 12500 ] ; then
                                break
                        fi
                fi
                echo "Must be in the range 12500 - 18356"
        done
        echo "#define SELECTED_SRATE	$answer" >>local.h
else
	echo "#define PCSP_TEST_SPEED" >>local.h
	echo "#undef SELECTED_SRATE" >>local.h
fi

cat <<END

Since version 0.8 the driver can emulate 16bit stereo audio data on any
output device. It cannot play this data at the high resolution and converts
them to 8bit (and mono for mono devices), but allows to run applications
that want 16bit samples (DOOM of course, what else :-), but you need at
least a 486DX and a DX-2 if you have only the PC-Speaker; it works great
on my 486DX-2 with a Stereo-on-1, really better than my SB 1.5 :-)

END

echo -ne "\nDo you want 16bit stereo emulation support [Y/n] "
read answer
if [ "$answer" = "n" ] ; then
	echo "#undef PCSP_16BIT_SUPPORT" >>local.h
else
	echo "#define PCSP_16BIT_SUPPORT" >>local.h
fi

if [ "$answer" = "n" ] ; then
cat <<END

Starting with version 0.4 the driver can simulate the /dev/mixer device.
This is only useful if you have Stereo-on-One or Stereo-DACs,
because Mono-devices will ignore the 2 volumes and use only the
left volume (PC-Speaker however use the mean value).
The /dev/mixer simulation supports only the Master-Volume device.
If you don't include /dev/mixer support, you can use pcsel to
change only the PC-Speaker volume, DACs will play at 100 %. 
Disabling /dev/mixer support don't speed up output thru PC-Speaker!

END

echo -ne "\nDo you want the /dev/mixer simulation [Y/n] "
read answer

else

cat <<END

You need the mixer support for the 16bit emulation, so it's enabled.

END
fi

if [ "$answer" = "n" ] ; then
	echo "#undef PCSP_MIXER" >>local.h
else
	echo "#define PCSP_MIXER" >>local.h
	while true
	do
		echo -n "Left volume at startup (0-100)  :" 
		read left
		left=${left:-100}
		if [ $left -le 100 ] ; then
			if [ $left -ge 0 ] ; then
				break 
			fi
		fi
		echo "Must be in the range 0 - 100"
	done
	echo "#define DEFAULT_LEFT	$left" >>local.h
	while true
	do
		echo -n "Right volume at startup (0-100) :"
		read right
		right=${right:-100}
		if [ $right -le 100 ] ; then
			if [ $right -ge 0 ] ; then
				break
			fi
		fi
		echo "Must be in the range 0 - 100"
	done
	echo "#define DEFAULT_RIGHT	$right" >>local.h
fi

cat <<END


Your PCSP-driver is now configured.

END
