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

cat <<END

Configuring the Alternate Sound-driver for Linux

Since version 0.6 ithe driver automaticly 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 a version 0.5 was working
on your machine, please contact me.

END

echo -e "/*  Generated by configure. Don't edit! */\n" >local.h

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

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
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
