#bash

# CDDOIT 1.3
# Written by Jose L. Diaz.
# February/2002
# Homepage: http://www.geocities.com/cddoit/index.html
# This software comes with NO warranty of any kind. Use at your own risk.
# Report bugs or suggestions to: cddoit@yahoo.com
# ===============================================================================




#******************************************************************************
# FUNCTIONS
#******************************************************************************


#******************************************************************************

PlayManyFormats () {
	while true;
	do
		clear ;
		echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
		echo "CDDOIT: Play many audio files [44.100 Hz, 16 bits, Stereo]" ;
		echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
		GoToDir;
		if [ "$?" = "1" ]
		then
			return 1;
		fi
		echo " " ;
		echo " " ;
		echo -n "Select file to play [*: All, 0: Exit]: " ;
		read archv;
		if [ "$archv" = "0" ] || [ "$archv" = "" ]
		then
			return;
		fi
		if [ "$archv" = "*" ]
		then
			for archv in *.wav;
			do
				clear;
				echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
				echo "CDDOIT: Playing audio files" ;
				echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
				echo " " ;
				echo " " ;
				echo -n "You are listening: ";
				echo "$archv";
				echo " " ;
				echo " " ;
				sox -t auto -r 44100 -c 2 -w -s "$archv"  -r 44100 -c 2 -t ossdsp -w -s /dev/dsp;
				read;
			done ;
			break;
		fi
		echo " " ;
		if [ -f "$archv" ]
		then
			clear;
			echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
			echo "CDDOIT: Playing audio files" ;
			echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
			echo " " ;
			echo " " ;
			echo -n "You are listening: ";
			echo "$archv";
			echo " " ;
			echo " " ;
			sox -t auto -r 44100 -c 2 -w -s "$archv"  -r 44100 -c 2 -t ossdsp -w -s /dev/dsp;
		else
			Beep;
			echo "ERROR: File not found.";
			PressAnyKey;
		fi
		echo " " ;
		echo " " ;
		echo -n "Play new file? y/n: " ;
		read opc;
		if [ "$opc" != "y" ]
		then
			break;
		fi		
	done
	return;
}	


#******************************************************************************

ConvertBetweenFormats ()
# Arguments:  1. Interactive audio conversion
#             2. audio conversion program
{
	clear;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "CDDOIT: Convert between audio file formats" ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo " " ;
	echo " " ;
	echo " WARNING:" ;
	echo "  *****   In big files this action is going to take a long time." ;
	echo " ** | **  Some audio formats are not compatible in some conversions." ;
	echo " ** 0 **  The final quality sound from poor quality formats maybe" ;
	echo "  *****   not good." ;
	GoToDir;
	if [ "$?" = "1" ]
	then
		return 1;
	fi
	echo " " ;
	echo " " ;
	echo -n "Select the audio file [0: Exit]: " ;
	read archv;
	if [ "$archv" = "0" ] || [ "$archv" = "" ]
	then
		return;
	fi
	if [ ! -f "$archv" ]
	then
		echo " " ;
		echo " " ;
		echo "ERROR: File not found!" ;
		Beep;
		PressAnyKey;
		return;
	fi
	echo " " ;
	echo " " ;
	echo "Now, you must enter the audio parameters about the original file." ;
	PressAnyKey;
	clear;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "CDDOIT: Convert between audio file formats" ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo " " ;
	echo " " ;
	echo "ENTER THE AUDIO PARAMETERS OF THE ORIGINAL AUDIO FILE:" ;
	echo "====================================================== " ;
	echo " " ;
	echo " " ;
	echo "\
1. Enter the audio format of the original audio file.

The formats supported are:

       8svx     Amiga 8SVX musical instrument description.
       aiff     AIFF  files  used  on  Apple  IIc/IIgs  and SGI.
       au       SUN Microsystems AU files.
       avr      Audio Visual Research
       cdr      CD-R.
       cvs      Continuously Variable Slope Delta modulation.
       dat      Text Data files.
       gsm      GSM 06.10 Lossy Speech Compression.
       hcom     Macintosh  HCOM  files.
       maud     An Amiga format.
       ossdsp   OSS /dev/dsp device driver.
       sf       IRCAM Sound Files.
       sph      SPHERE  (SPeech HEader Resources)
       smp      Turtle Beach SampleVision files.
       snd      Under DOS same as the sndt format
                Under all other platforms it is
                the same as the .au format.
       sndt     SoundTool files. Older DOS file format.
       sunau    Sun /dev/audio device driver.
       txw      Yamaha TX-16W sampler.
       vms      Used to compress speech audio such as voice mail.
       voc      Sound Blaster VOC files.
       wav      Microsoft .WAV RIFF files.
       wve      Psion 8-bit alaw.
       raw      Raw files (no header).
       ub, sb, uw, sw, ul, al, sl
                These  are  several  suffices  which  serve as a
                shorthand for raw files with a  given  size  and
                style.   Thus, ub, sb, uw, sw, and ul correspond
                to 'unsigned  byte',  'signed  byte', 'unsigned
                word',  'signed  word', 'ulaw' (byte),"alaw" (byte),
                and "signed  long".
       auto     This is a ``meta-type'' format.
";
	echo "-You can select & paste-";
	echo -n "Enter audio format [0: Exit]: " ;
	read format;
	if [ "$format" = "0" ] || [ "$format" = "" ]
	then
		return;
	fi
	clear;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "CDDOIT: Convert between audio file formats" ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo " " ;
	echo " " ;
	echo -n "2. Enter the original sample rate (E.g: 44101 or 8000) [0: Exit]: " ;
	read rate;
	if [ "$rate" = "0" ] || [ "$rate" = "" ]
	then
		return;
	fi
	clear;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "CDDOIT: Convert between audio file formats" ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo " " ;
	echo " " ;
	echo "\
3. Enter the bits resolution of the original audio file.

The bits resolution supported types are:

	b : 8-bit  bytes.
	w : 16-bit words.
	l : 32-bit long words.
	f : 32-bit floats.
	d : 64-bit double floats.
	D : 80-bit IEEE floats.
	    [Floats and double floats are in native machine format]

";
	echo "-You can select & paste-";
	echo -n "Bits resolution [0: Exit]: " ;
	read bits;
	if [ "$bits" = "0" ] || [ "$bits" = "" ]
	then
		return;
	fi
	clear;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "CDDOIT: Convert between audio file formats" ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo " " ;
	echo " " ;
	echo "\
4. Enter the audio channels of the original audio file.

The most common number of audio channels are:

	1: Mono.
	2: Stereo.
	4: Four audio channels.
";
	echo -n "Audio channels [0: Exit]: " ;
	read channel;
	if [ "$channel" = "0" ] || [ "$channel" = "" ]
	then
		return;
	fi
	echo "" ;
	echo "" ;
	echo "The audio parameters of the original audio file has been saved." ;
	echo "" ;
	echo "Now, you must enter the audio parameters about the target file." ;
	PressAnyKey;
	clear;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "CDDOIT: Convert between audio file formats" ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo " " ;
	echo " " ;
	echo "ENTER THE AUDIO PARAMETERS OF THE TARGET AUDIO FILE:" ;
	echo "=================================================== " ;
	echo " " ;
	echo " " ;
	echo "\
1. Enter the audio format of the target audio file.

The formats supported are:

       8svx     Amiga 8SVX musical instrument description.
       aiff     AIFF  files  used  on  Apple  IIc/IIgs  and SGI.
       au       SUN Microsystems AU files.
       avr      Audio Visual Research
       cdr      CD-R.
       cvs      Continuously Variable Slope Delta modulation.
       dat      Text Data files.
       gsm      GSM 06.10 Lossy Speech Compression.
       hcom     Macintosh  HCOM  files.
       maud     An Amiga format.
       ossdsp   OSS /dev/dsp device driver.
       sf       IRCAM Sound Files.
       sph      SPHERE  (SPeech HEader Resources)
       smp      Turtle Beach SampleVision files.
       snd      Under DOS same as the sndt format
                Under all other platforms it is
                the same as the .au format.
       sndt     SoundTool files. Older DOS file format.
       sunau    Sun /dev/audio device driver.
       txw      Yamaha TX-16W sampler.
       vms      Used to compress speech audio such as voice mail.
       voc      Sound Blaster VOC files.
       wav      Microsoft .WAV RIFF files.
       wve      Psion 8-bit alaw.
       raw      Raw files (no header).
       ub, sb, uw, sw, ul, al, sl
                These  are  several  suffices  which  serve as a
                shorthand for raw files with a  given  size  and
                style.   Thus, ub, sb, uw, sw, and ul correspond
                to 'unsigned  byte',  'signed  byte', 'unsigned
                word',  'signed  word', 'ulaw' (byte),"alaw" (byte),
                and "signed  long".
       auto     This is a ``meta-type'' format.
";
	echo "-You can select & paste-";
	echo -n "Enter audio format [0: Exit]: " ;
	read fformat;
	if [ "$fformat" = "0" ] || [ "$fformat" = "" ]
	then
		return;
	fi
	clear;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "CDDOIT: Convert between audio file formats" ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo " " ;
	echo " " ;
	echo -n "2. Enter the target sample rate (E.g: 44101 or 8000) [0: Exit]: " ;
	read frate;
	if [ "$frate" = "0" ] || [ "$frate" = "" ]
	then
		return;
	fi
	clear;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "CDDOIT: Convert between audio file formats" ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo " " ;
	echo " " ;
	echo "\
3. Enter the bits resolution of the target audio file.

The bits resolution supported types are:

	b : 8-bit  bytes.
	w : 16-bit words.
	l : 32-bit long words.
	f : 32-bit floats.
	d : 64-bit double floats.
	D : 80-bit IEEE floats.
	    [Floats and double floats are in native machine format]

";
	echo "-You can select & paste-";
	echo -n "Bits resolution [0: Exit]: " ;
	read fbits;
	if [ "$fbits" = "0" ] || [ "$fbits" = "" ]
	then
		return;
	fi
	clear;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "CDDOIT: Convert between audio file formats" ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo " " ;
	echo " " ;
	echo "\
4. Enter the audio channels of the target audio file.

The most common number of audio channels are:

	1: Mono.
	2: Stereo.
	4: Four audio channels.
";
	echo -n "Audio channels [0: Exit]: " ;
	read fchannel;
	if [ "$fchannel" = "0" ] || [ "$fchannel" = "" ]
	then
		return;
	fi
	if [ "${1}" = "2" ]   # audio conversion program
	then
		echo "";
		echo "";
		echo "OK, now you must enter the parameters of the conversion program.";
		PressAnyKey;
	fi
	clear;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "CDDOIT: Convert between audio file formats" ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "" ;
	echo "" ;
	if [ "${1}" = "2" ]   # audio conversion program
	then
		# programming parameters
		echo "PROGRAMMING OF AUDIO CONVERSION";
		echo "===============================";
		echo "";	
		echo "WARNING: Be carefull and check:";
		echo "         . Date & time is correct in your host!";
		echo "         . Others audio conversion or recording programs ";
		echo "           are NOT running at the same time!";
		echo "";	
		echo "";	
		echo -n "1. Enter the date and time to start audio conversion, now is ";	
		date +[%d/%m/%y][%H:%M];
		echo -n "        Year [YY]: ";
		read syear;
		echo -n "        Month [MM]: ";
		read smonth;
		echo -n "        Day [DD]: ";
		read sday;
		echo -n "        Hour [HH]: ";
		read shour;
		echo -n "        Minute [MM]: ";	
		read sminute;
		# creating the warning-file
		echo "CDDOIT Warning" > "NO REMOVE THIS DIRECTORY.README!";
		echo "**************" >> "NO REMOVE THIS DIRECTORY.README!";
		echo "" >> "NO REMOVE THIS DIRECTORY.README!";
		echo "No delete this directory!." >> "NO REMOVE THIS DIRECTORY.README!";
		echo "This directory was created for a CDDOIT audio conversion program." >> "NO REMOVE THIS DIRECTORY.README!";
		echo "If you delete the directory the audio program will be failed." >> "NO REMOVE THIS DIRECTORY.README!";
		echo "" >> "NO REMOVE THIS DIRECTORY.README!";
		echo "This warning-file will be removed automatically after audio program finished." >> "NO REMOVE THIS DIRECTORY.README!";
		echo "" >> "NO REMOVE THIS DIRECTORY.README!";
		echo "You can check the CDDOIT audio recording programs in the CDDOIT menu AUDIO." >> "NO REMOVE THIS DIRECTORY.README!";
		echo "" ;
		echo "" ;
		# running the AT command
		echo "Saving start conversion parameters...";
		echo "sox -t $format -r $rate -c $channel -$bits -s "$archv" -t $fformat -r $frate -c $fchannel -$fbits -s "$archv".$fformat" > "$archv.start.at";
		echo 'rm -f "NO REMOVE THIS DIRECTORY.README!"' >> "$archv.start.at";
		at -f "$archv.start.at" -m $shour:$sminute $sday.$smonth.$syear;
		rm -f "$archv.start.at";
		if [ "$?" = "1" ]   # AT command is not correct
		then
			echo "ERROR: the format of the start parameters is not correct.";
			PressAnyKey;
			return;
		fi
		echo "";	
		echo "";	
		echo "The start parameters were saved OK.";	
		echo "The audio conversion is scheduled OK.";
		echo "" ;
		echo "After the conversion, you can check the output messages in your mail!";
		echo -n "The audio conversion will be found in: " ;
		pwd ;
	else
		echo -n "Press ENTER to start the conversion." ;
		read;
		echo "" ;
		echo "" ;
		echo -n "Converting the file: " ;
		echo "$archv";
		echo " " ;
		echo "WARNING: In big files this action is going to take a long time. Be patient." ;
		echo "" ;
		sox -V -t $format -r $rate -c $channel -$bits -s "$archv" -t $fformat -r $frate -c $fchannel -$fbits -s "$archv".$fformat;
		Beep;
		echo "";
		echo -n "The file is found in: ";
		pwd;
		GetSizeInMB;
		echo "";
		echo "";
		echo -n "Do you wish to delete the original file? y/n: ";
		read opc;
		if [ "$opc" = "y" ]
		then
			echo "";
			rm -fv "$archv";
		fi
	fi
	PressAnyKey;
	return ;
}


#******************************************************************************

SleepTimerRecord ()
{
	while true;
	do
		clear ;
		echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
		echo "CDDOIT: Sleeptimer recording" ;
		echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
		echo " " ;
		echo " " ;
		echo "The recording start now and you choose when finish." ;
		echo "Recording is in WAV format, Stereo, 16 bits & 44.100 Hz." ;
		echo " " ;
		echo " " ;
		echo -n "Recording title [0: Exit]: " ;
		read file;
		export file;
		if [ "$file" = "0" ] || [ "$file" = "" ]
		then
			return;
		fi
		if [ ! -d "$HOME/cddoit/$file" ]
		then
			echo "" ;
			mkdir --verbose "$HOME/cddoit/$file" ;
			cd "$HOME/cddoit/$file";
			break ;
		else
			echo " " ;
			Beep;
			echo "WARNING: The file already exist. Enter a diferent name.";
			PressAnyKey;
		fi
	done	
	echo " " ;
	echo -n "Enter the recording duration [In minutes]: " ;
	read timerec;
	echo "" ;
	echo "" ;
	echo "NOTE: Press 'y' if your SOX version is older or the recording" ;
	echo "      quality is not good.";
	echo "      Default 'n'.";
	echo -n "Do you wish the audio recording in 44101 Hz [y/n(ENTER)]: ";
	read opc44101;
	if [ "$opc44101" = "y" ]
	then
		echo "" ;
		echo "" ;
		echo " WARNING: The sample rate in WAV files to CD-R copy is 44.100 Hz and" ;
		echo "  *****   this recording is in 44.101 Hz." ;
		echo " ** | **  You must convert to this sample rate before the CD-R copy." ;
		echo " ** 0 **  You can do it now or convert later in menu AUDIO, option n 10." ;
		echo "  *****   In big files this action is going to take a long time" ;
		echo "" ;
		echo -n "Do you like perform conversion to 44.100 Hz when recording finish? [y/n]: " ;
		read opcconv;
		if [ "$opcconv" = "y" ]
		then
			echo "" ;
			echo -n "Remove old audio 44.101 Hz file after the conversion? [y/n]: " ;
			read opcrem;
		fi
	fi
	echo "";
	echo "";	
	echo "Saving finish recording parameters...";
	echo 'numpid=`ps -u "$USER" | grep 'sox'`' > "$HOME/cddoit/$file/$file.sleeptimer.cddoit";
	echo 'kill $numpid' >> "$HOME/cddoit/$file/$file.sleeptimer.cddoit";
	if [ "$opc44101" = "y" ]
	then
		if [ "$opcconv" = "y" ]
		then
			echo 'sox -V -r 44101 -c 2 -t wav -w -s "$file".44101.wav -t wav -r 44100 -c 2 -w -s "$file".44100.wav' >> "$HOME/cddoit/$file/$file.sleeptimer.cddoit";
			if [ "$opcrem" = "y" ]
			then
				echo 'rm -vf "$file.44101.wav"' >> "$HOME/cddoit/$file/$file.sleeptimer.cddoit";
			fi
		fi
	fi
	at -f "$HOME/cddoit/$file/$file.sleeptimer.cddoit" -m now + $timerec minutes;
	rm -f "$HOME/cddoit/$file/$file.sleeptimer.cddoit";
	if [ "$?" = "1" ]   # AT command is not correct
	then
		echo "ERROR: the format of the finish parameters is not correct.";
		rm -fr "$HOME/cddoit/$file";
		PressAnyKey;
		return;
	fi
	echo "";	
	echo "The finish parameters were saved OK.";	
	echo "";	
	echo "";	
	echo "Press ENTER to start the recording." ;
	read;
	if [ "$opc44101" = "y" ]
	then
		echo 'sox -V -r 44101 -c 2 -t ossdsp -w -s /dev/dsp -t wav -r 44101 -c 2 -w -s "$file.44101.wav"' > "$HOME/cddoit/$file/$file.sleeptimer.cddoit";
	else
		echo 'sox -V -r 44100 -c 2 -t ossdsp -w -s /dev/dsp -t wav -r 44100 -c 2 -w -s "$file.44101.wav"' > "$HOME/cddoit/$file/$file.sleeptimer.cddoit";
	fi
	at -f "$HOME/cddoit/$file/$file.sleeptimer.cddoit" -m now;
	rm -f "$HOME/cddoit/$file/$file.sleeptimer.cddoit";
	echo "";	
	echo "RECORDING...";	
	echo "Now, the audio recording is active.";	
	if [ "$opc44101" = "y" ]
	then
		if [ "$opcconv" = "y" ]
		then
			echo "The audio conversion will be performed after the recording.";
		fi
	fi
	echo "" ;
	echo "" ;
	echo -n "The recording is found in: " ;
	echo "$HOME/cddoit/$file" ;
	PressAnyKey;
	return;
}



#******************************************************************************

ModulesManager ()
{
	while true;
	do
		clear ;
		echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
		echo "CDDOIT: Multimedia kernel modules manager" ;
		echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
		echo "";
		echo "";
		echo "::: Load/Unload dynamically kernel modules in your system ::::::::::::::::::";
		echo "";
		echo "    NOTE: Kernel modules provides funcionality for many devices.";
		echo "";
		echo "";
		echo "    1. Load a kernel module";
		echo "    2. Unload a kernel module";
		echo "    3. List of available multimedia modules";
		echo "";
		echo "    0. Back to main menu";
		echo "";
		echo -n "Choose option: ";
		read opc;
		clear ;
		echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
		echo "CDDOIT: Multimedia kernel modules manager" ;
		echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
		echo "";
		echo "";
		case $opc in
			"") break;;
			0) break;;
			1)  if [ -f "$HOME/cddoit/.last_module_load.cddoit" ]
			    then
					echo -n "The last module loaded was: ";
					cat "$HOME/cddoit/.last_module_load.cddoit";
					echo "";
					echo "";
					echo -n "Do you wish load this module again? [y(ENTER)/n]: ";
					read opc;
					if [ "$opc" = "y" ] || [ "$opc" = "" ]
					then
						last_mod=`cat "$HOME/cddoit/.last_module_load.cddoit"`;
						export last_mod;
						echo "";
						echo "This operation must be performed under ROOT. Enter the password.";
						su -c '/sbin/modprobe -v $last_mod';
					fi
				else
					echo "";
					echo -n "Enter the name of the module: ";
					read module;
					echo -n "Parameters of the module [Press ENTER for no parameters]: ";
					read modargs;
					export module;
					export modargs;
					echo "";
					echo "This operation must be performed under ROOT. Enter the password.";
					su -c '/sbin/modprobe -v $module $modargs';
					echo $module $modargs > "$HOME/cddoit/.last_module_load.cddoit";
				fi		
				PressAnyKey;;
			2)  if [ -f "$HOME/cddoit/.last_module_load.cddoit" ]
			    then
					echo -n "The last module loaded was: ";
					cat "$HOME/cddoit/.last_module_load.cddoit";
					echo "";
					echo "";
					echo -n "Do you wish unload this module? [y(ENTER)/n]: ";
					read opc;
					if [ "$opc" = "y" ] || [ "$opc" = "" ]
					then
						last_mod=`cat "$HOME/cddoit/.last_module_load.cddoit"`;
						export last_mod;
						echo "";
						echo "This operation must be performed under ROOT. Enter the password.";
						su -c '/sbin/modprobe -vr $last_mod';
					fi
				else
					echo "";
					echo -n "Enter the name of the module: ";
					read module;
					export module;
					echo "";
					echo "This operation must be performed under ROOT. Enter the password.";
					su -c '/sbin/modprobe -vr $module';
				fi
				PressAnyKey;;
			3)  echo "LIST OF AVAILABLE MULTIMEDIA MODULES";
				echo "============================================================================" ;
				echo "";
				echo "WARNING: This list show only 'misc' modules.";
				echo "         Many of them may be not multimedia modules.";
				echo "";
				echo "";
				echo "You can select with the mouse and paste the name of the module later.";
				echo "Select only the name of the module, e.g:";
				echo "         In  /lib/modules/X.X.XX-XX/misc/name-module.o";
				echo "         only select 'name-module' (without .o)";
				echo "";
				echo "Press 'q' to exit the list.";
				PressAnyKey;
				echo "";
				/sbin/modprobe -l -t misc | more;
				PressAnyKey;;
		esac;
	done
	return;
}	



#******************************************************************************

PlayAudioFormats () {
	while true;
	do
		clear ;
		echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
		echo "CDDOIT: Play audio files" ;
		echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
		GoToDir;
		if [ "$?" = "1" ]
		then
			return 1;
		fi
		echo " " ;
		echo " " ;
		echo -n "Select file to play [*: All, 0: Exit]: " ;
		read archv;
		if [ "$archv" = "0" ] || [ "$archv" = "" ]
		then
			return;
		fi
		if [ "$archv" = "*" ]
		then
			for archv in *.wav;
			do
				clear;
				echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
				echo "CDDOIT: Playing audio files" ;
				echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
				echo " " ;
				echo " " ;
				echo -n "You are listening: ";
				echo "$archv";
				echo " " ;
				echo " " ;
				echo " " ;
				echo " " ;
				sox -t wav -r 44100 -c 2 -w -s "$archv"  -r 44100 -c 2 -t ossdsp -w -s /dev/dsp ;
			done ;
			break;
		fi
		echo " " ;
		if [ -f "$archv" ]
		then
			clear;
			echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
			echo "CDDOIT: Playing WAV files" ;
			echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
			echo " " ;
			echo " " ;
			echo -n "You are listening: ";
			echo "$archv";
			echo " " ;
			sox -t wav -r 44100 -c 2 -w -s "$archv"  -r 44100 -c 2 -t ossdsp -w -s /dev/dsp;
		else
			Beep;
			echo "ERROR: File not found.";
			PressAnyKey;
		fi
		echo " " ;
		echo " " ;
		echo -n "Play new file? y/n: " ;
		read opc;
		if [ "$opc" != "y" ]
		then
			break;
		fi		
	done
	return;
}	


#******************************************************************************

AudioRecordSpecificFormat () {
	while true;
	do
		clear ;
		echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
		echo "CDDOIT: Record audio in specific format" ;
		echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
		echo " " ;
		echo " " ;
		echo -n "Recording title [0: Exit]: " ;
		read file;
		export file;
		if [ "$file" = "0" ] || [ "$file" = "" ]
		then
			return;
		fi
		if [ ! -d "$HOME/cddoit/$file" ]
		then
			echo "" ;
			mkdir --verbose "$HOME/cddoit/$file" ;
			cd "$HOME/cddoit/$file";
			break ;
		else
			echo " " ;
			Beep;
			echo "WARNING: The file already exist. Enter a diferent name.";
			PressAnyKey;
		fi
	done	
	PressAnyKey;
	clear;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "CDDOIT: Record audio in specific format" ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo " " ;
	echo " " ;
	echo "ENTER THE AUDIO PARAMETERS OF THE AUDIO RECORDING:" ;
	echo "==================================================" ;
	echo " " ;
	echo " " ;
	echo "\
1. Enter the audio format of the audio recording.

The formats supported are:

       8svx     Amiga 8SVX musical instrument description.
       aiff     AIFF  files  used  on  Apple  IIc/IIgs  and SGI.
       au       SUN Microsystems AU files.
       avr      Audio Visual Research
       cdr      CD-R.
       cvs      Continuously Variable Slope Delta modulation.
       dat      Text Data files.
       gsm      GSM 06.10 Lossy Speech Compression.
       hcom     Macintosh  HCOM  files.
       maud     An Amiga format.
       ossdsp   OSS /dev/dsp device driver.
       sf       IRCAM Sound Files.
       sph      SPHERE  (SPeech HEader Resources)
       smp      Turtle Beach SampleVision files.
       snd      Under DOS same as the sndt format
                Under all other platforms it is
                the same as the .au format.
       sndt     SoundTool files. Older DOS file format.
       sunau    Sun /dev/audio device driver.
       txw      Yamaha TX-16W sampler.
       vms      Used to compress speech audio such as voice mail.
       voc      Sound Blaster VOC files.
       wav      Microsoft .WAV RIFF files.
       wve      Psion 8-bit alaw.
       raw      Raw files (no header).
       ub, sb, uw, sw, ul, al, sl
                These  are  several  suffices  which  serve as a
                shorthand for raw files with a  given  size  and
                style.   Thus, ub, sb, uw, sw, and ul correspond
                to 'unsigned  byte',  'signed  byte', 'unsigned
                word',  'signed  word', 'ulaw' (byte),"alaw" (byte),
                and "signed  long".
       auto     This is a ``meta-type'' format.
";
	echo "-You can select & paste-";
	echo -n "Enter audio format [0: Exit]: " ;
	read format;
	if [ "$format" = "0" ] || [ "$format" = "" ]
	then
		return;
	fi
	clear;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "CDDOIT: Record audio in specific format" ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo " " ;
	echo " " ;
	echo -n "2. Enter the original sample rate (E.g: 44101 or 8000) [0: Exit]: " ;
	read rate;
	if [ "$rate" = "0" ] || [ "$rate" = "" ]
	then
		return;
	fi
	clear;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "CDDOIT: Record audio in specific format" ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "" ;
	echo "" ;
	echo "\
3. Enter the bits resolution of the audio recording.

The bits resolution supported types are:

	b : 8-bit  bytes.
	w : 16-bit words.
	l : 32-bit long words.
	f : 32-bit floats.
	d : 64-bit double floats.
	D : 80-bit IEEE floats.
	    [Floats and double floats are in native machine format]

";
	echo "-You can select & paste-";
	echo -n "Bits resolution [0: Exit]: " ;
	read bits;
	if [ "$bits" = "0" ] || [ "$bits" = "" ]
	then
		return;
	fi
	clear;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "CDDOIT: Record audio in specific format" ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo " " ;
	echo " " ;
	echo "\
4. Enter the audio channels of the audio recording.

The most common number of audio channels are:

	1: Mono.
	2: Stereo.
	4: Four audio channels.
";
	echo -n "Audio channels [0: Exit]: " ;
	read channel;
	if [ "$channel" = "0" ] || [ "$channel" = "" ]
	then
		return;
	fi
	clear;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "CDDOIT: Record audio in specific format" ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo " " ;
	echo " " ;
	echo -n "Do you like perform the recording under ROOT? [maximum priority] y/n: ";
	read opc;
	if [ "$opc" = "y" ]
	then
		echo "Enter the ROOT password." ;
		su -c '
		echo " " ;
		echo "Press ENTER to start the recording." ;
		read;
		echo " " ;
		echo " " ;
		echo "Enter CTRL+C to finish the recording." ;
		echo "RECORDING WITH MAXIMUM PRIORITY [ROOT]...";
		echo " " ;
		sox -V -r $rate -c $channel -t ossdsp -$bits -s /dev/dsp -t $format -r $rate -c $channel -$bits -s "$file.$format"';
		if [ "$?" = "1" ]   # if SU return bad code...
		then
			PressAnyKey;
			return;
		fi
	else
		echo " " ;
		echo "Press ENTER to start the recording." ;
		read;
		echo " " ;
		echo " " ;
		echo "Enter CTRL+C to finish the recording." ;
		echo "RECORDING...";
		echo " " ;
		sox -V -r $rate -c $channel -t ossdsp -$bits -s /dev/dsp -t $format -r $rate -c $channel -$bits -s "$file.$format";
	fi
	echo "" ;
	echo "" ;
	echo -n "The recording is found in: " ;
	echo "$HOME/cddoit/$file" ;
	GetSizeInMB;
	PressAnyKey;
	return;
}


#******************************************************************************

GetAIFFfromCD ()
{
	clear;	
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "CDDOIT: Get AIFF files from Audio-CD" ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	GetDirWavTracks;
	if [ "$?" = "1" ]
	then
		return 1;
	fi
	echo " " ;
	echo " " ;
	echo "Enter the AIFF type:" ;
	echo " " ;
	echo "    1. AIFF audio file" ;
	echo "    2. AIFF-C audio file" ;
	echo " " ;
	echo -n "Type: ";
	read aifftype;
	echo " " ;
	echo " " ;
	echo "Enter tracks to extract from audio CD:" ;
	echo " " ;
	echo " " ;
	echo "	Examples of audio track extracting:" ;
	echo " " ;
	echo "	1-   All CD tracks";
	echo "	2    Extract only track 2";
	echo "	-2   Extract from track 1 to 2";
	echo "	2-   Extract from track 2 to the last track of the CD";
	echo "	2-7  Extract tracks 2 to 7";
	echo "	1:[20.35]   Extract from second 20, sector 35 of track 1 to the end of track 1";
	echo "	1:[20.35]-  Extract from second 20, sector 35 of track 1 to the last track od CD";
	echo "" ;
	echo "" ;
	echo -n "Tracks (1-  All CD tracks): " ;
	read tracks;
	echo " " ;
	echo " " ;
	echo "Enter audio extraction type:" ;
	echo " " ;
	echo "	1. Maximum quality -Slow extraction-" ;
	echo "	2. Good quality, no errors -Quick extraction-" ;
	echo "	3. Regular quality, possible errors -Very quick extraction-" ;
	echo "" ;
	echo -n "Type: " ;
	read type;
	echo "" ;
	echo "" ;
	case $aifftype in
		1)  case $type in
				1) cdparanoia -B -f "$tracks";;
				2) cdparanoia -Y -B -f "$tracks";;
				3) cdparanoia -Z -B -f "$tracks";;
			esac;
			;;
		2)  case $type in
				1) cdparanoia -B -a "$tracks";;
				2) cdparanoia -Y -B -a "$tracks";;
				3) cdparanoia -Z -B -a "$tracks";;
			esac;
			;;
	esac;
	if [ "$?" = "1" ]
	then
		PressAnyKey;
		return 1;
	fi
	GetSizeInMB;
	PressAnyKey;
	return ;
}



#******************************************************************************

GetRAWfromCD ()
{
	clear;	
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "CDDOIT: Get RAW files from Audio-CD" ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	GetDirWavTracks;
	if [ "$?" = "1" ]
	then
		return 1;
	fi
	echo " " ;
	echo " " ;
	echo "Enter the RAW type:" ;
	echo " " ;
	echo "    1. Host byte order 16 bits PCM" ;
	echo "    2. Little-endian 16 bits PCM" ;
	echo "    3. Big-endian 16 bits PCM" ;
	echo " " ;
	echo -n "Type: ";
	read rawtype;
	echo " " ;
	echo " " ;
	echo "Enter tracks to extract from audio CD:" ;
	echo " " ;
	echo " " ;
	echo "	Examples of audio track extracting:" ;
	echo " " ;
	echo "	1-   All CD tracks";
	echo "	2    Extract only track 2";
	echo "	-2   Extract from track 1 to 2";
	echo "	2-   Extract from track 2 to the last track of the CD";
	echo "	2-7  Extract tracks 2 to 7";
	echo "	1:[20.35]   Extract from second 20, sector 35 of track 1 to the end of track 1";
	echo "	1:[20.35]-  Extract from second 20, sector 35 of track 1 to the last track od CD";
	echo "" ;
	echo "" ;
	echo -n "Tracks (1-  All CD tracks): " ;
	read tracks;
	echo " " ;
	echo " " ;
	echo "Enter audio extraction type:" ;
	echo " " ;
	echo "	1. Maximum quality -Slow extraction-" ;
	echo "	2. Good quality, no errors -Quick extraction-" ;
	echo "	3. Regular quality, possible errors -Very quick extraction-" ;
	echo "" ;
	echo -n "Type: " ;
	read type;
	echo "" ;
	echo "" ;
	case $rawtype in
		1)  case $type in
				1) cdparanoia -B -p "$tracks";;
				2) cdparanoia -Y -B -p "$tracks";;
				3) cdparanoia -Z -B -p "$tracks";;
			esac;
			;;
		2)  case $type in
				1) cdparanoia -B -r "$tracks";;
				2) cdparanoia -Y -B -r "$tracks";;
				3) cdparanoia -Z -B -r "$tracks";;
			esac;
			;;
		3)  case $type in
				1) cdparanoia -B -R "$tracks";;
				2) cdparanoia -Y -B -R "$tracks";;
				3) cdparanoia -Z -B -R "$tracks";;
			esac;
			;;
	esac;
	if [ "$?" = "1" ]
	then
		PressAnyKey;
		return 1;
	fi
	GetSizeInMB;
	PressAnyKey;
	return ;
}

#******************************************************************************

Convert44101to44100 ()
{
	clear ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "CDDOIT: Convert 44.101 Hz to 44.000 Hz rate in WAV files" ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	GoToDir;
	if [ "$?" = "1" ]
	then
		return 1;
	fi
	echo "";
	echo "";
	echo "NOTE: This option is special for CDDOIT recordings, so the original";
	echo "      44.101 Hz file must be in WAV format and stereo.";
	echo "      In big files this action is going to take a long time" ;
	echo "";
	echo "";
	echo -n "Enter the WAV file name: ";
	read file;
	echo "";
	echo "";
	echo -n "Remove old audio 44.101 Hz file after the conversion? [y/n]: " ;
	read opc;
	echo "";
	echo "";
	echo "Press ENTER to start the conversion.";
	read;
	echo "";
	echo "";
	echo "Converting 44.101 Hz to 44.100 Hz in WAV format...";
	echo "";
	sox -V -r 44101 -c 2 -t wav -w -s "$file" -t wav -r 44100 -c 2 -w -s "$file".44100.wav;
	if [ "$opc" = "y" ]
	then
		rm -f "$file";
	fi
	echo "";
	echo "";
	echo "Sample rate conversion finished.";
	Beep;
	PressAnyKey;
	return;
}


#******************************************************************************
GetWholeCDSingleFile ()
{
	clear ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "CDDOIT: Get the whole Audio-CD in a single audio file" ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	GetDirWavTracks;
	if [ "$?" = "1" ]
	then
		return 1;
	fi
	echo "";
	echo "";
	echo "Enter the audio type:" ;
	echo "" ;
	echo "    1. WAV audio file" ;
	echo "    2. RAW host byte order 16 bits PCM" ;
	echo "    3. RAW little-endian 16 bits PCM" ;
	echo "    4. RAW big-endian 16 bits PCM" ;
	echo "    5. AIFF audio file" ;
	echo "    6. AIFF-C audio file" ;
	echo " " ;
	echo -n "Type [0: Exit]: ";
	read audiotype;
	if [ "$audiotype" = "0" ] || [ "$audiotype" = "" ]
	then
		return;
	fi
	echo " " ;
	echo " " ;
	echo "Enter audio extraction type:" ;
	echo " " ;
	echo "	1. Maximum quality -Slow extraction-" ;
	echo "	2. Good quality, no errors -Quick extraction-" ;
	echo "	3. Regular quality, possible errors -Very quick extraction-" ;
	echo "" ;
	echo -n "Type: " ;
	read type;
	echo "";
	echo "";
	echo -n "Enter file name -without extension-: ";
	read audioname;
	echo "";
	case $audiotype in
		1)  echo "Extracting in WAV format...";
			echo "";
			case $type in
				1) cdparanoia 1- "$audioname".wav;;
				2) cdparanoia -Y 1- "$audioname".wav;;
				3) cdparanoia -Z 1- "$audioname".wav;;
			esac;
			;;
		2)  echo "Extracting in RAW host byte order 16 bits PCM format...";
			echo "";
			case $type in
				1) cdparanoia -p 1- "$audioname".raw;;
				2) cdparanoia -p -Y 1- "$audioname".raw;;
				3) cdparanoia -p -Z 1- "$audioname".raw;;
			esac;
			;;
		3)  echo "Extracting in RAW little-endian 16 bits PCM format...";
			echo "";
			case $type in
				1) cdparanoia -r 1- "$audioname".raw;;
				2) cdparanoia -r -Y 1- "$audioname".raw;;
				3) cdparanoia -r -Z 1- "$audioname".raw;;
			esac;
			;;
		4)  echo "Extracting in RAW big-endian 16 bits PCM format...";
			echo "";
			case $type in
				1) cdparanoia -R 1- "$audioname".raw;;
				2) cdparanoia -R -Y 1- "$audioname".raw;;
				3) cdparanoia -R -Z 1- "$audioname".raw;;
			esac;
			;;
		5)  echo "Extracting in AIFF format...";
			echo "";
			case $type in
				1) cdparanoia -f 1- "$audioname".aiff;;
				2) cdparanoia -f -Y 1- "$audioname".aiff;;
				3) cdparanoia -f -Z 1- "$audioname".aiff;;
			esac;
			;;
		6)  echo "Extracting in AIFF-C format...";
			echo "";
			case $type in
				1) cdparanoia -a 1- "$audioname".aifc;;
				2) cdparanoia -a -Y 1- "$audioname".aifc;;
				3) cdparanoia -a -Z 1- "$audioname".aifc;;
			esac;
			;;
	esac;
	Beep;
	GetSizeInMB;
	PressAnyKey;
	return;
}


#******************************************************************************
RenameMP3ListTracks () {
	clear ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "CDDOIT: Rename the MP3 file names in a directory" ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	GoToDir;
	if [ "$?" = "1" ]
	then
		return 1;
	fi
	for mp3file in *.mp3;
	do
		echo "";
		echo "____________________________________________________________________________";
		echo -n "File name: ";
		echo $mp3file;
		echo "Enter the new file name -without MP3 extension- [0: Exit, 1: Keep this file]";
		echo -n "New name: ";
		read newname;
		if [ "$newname" = "0" ] || [ "$newname" = "" ]
		then
			break;
		fi
		if [ "$newname" = "1" ]
		then
			continue;
		fi
		mv -fv "$mp3file" "$newname".mp3;
	done;
	PressAnyKey;
	return;
}


#******************************************************************************

CancelProgramRecordStarted () {
	clear ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "CDDOIT: Cancel an audio program already started" ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo " " ;
	echo "" ;
	echo "Active audio program:" ;
	echo " " ;
	ps -u "$USER" | grep 'sox';
	if [ "$?" = "1" ]
	then
		echo "" ;
		echo "Now, there is not CDDOIT program in execution.";
	else
		echo " " ;
		echo -n "Enter the first number of line above [0: Exit]: ";
		read numpid;
		if [ "$numpid" = "0" ] || [ "$numpid" = "" ]
		then
			return;
		fi
		kill $numpid;
		if [ "$?" = "1" ]
		then
			echo " " ;
			echo "ERROR. The number is invalid!".
			Beep;
		else
			echo " " ;
			echo "Audio program canceled." ;
		fi
	fi
	PressAnyKey;
	return;
}

#******************************************************************************

ViewAtJobs () {
	echo "WARNING: Maybe some program jobs are not from CDDOIT. " ;
	echo " " ;
	if [ "${1}" = "2" ] # is an audio conversion (only start job)
	then
		echo "An CDDOIT audio conversion recording program consist in one" ;
		echo "number. The start program job." ;
	else
		echo "An CDDOIT audio recording program consist in two numbers (in" ;
		echo "two consecutives lines), one for the start and the second" ;
		echo "for the finish program job." ;
	fi
	echo "" ;
	echo "Information:" ;
	echo "    a: The program job is not in execution yet." ;
	echo "    =: The program job is in execution now." ;
	echo "" ;
	echo "List of active program jobs:" ;
	echo " " ;
	atq;
	echo " " ;
	return;
}


#******************************************************************************

ViewProgramRecords () {
	clear ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "CDDOIT: View audio programs" ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo " " ;
	echo " " ;
	ViewAtJobs ${1};
	PressAnyKey;
	return;
}


#******************************************************************************

DelProgramRecord () {
	clear ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "CDDOIT: Delete an audio program" ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo " " ;
	echo " " ;
	ViewAtJobs;
	echo "CAUTION: Be carefull, check the correct CDDOIT program jobs (see" ;
	echo "         time period) before delete it" ;
	echo " " ;
	echo -n "Enter the number of the init program job [0: Exit]: " ;
	read numjobinit;
	if [ "$numjobinit" = "0" ] || [ "$numjobinit" = "" ]
	then
		return;
	fi
	if [ "${1}" != "2" ] # is not an audio conversion (only start job)
	then
		echo -n "Enter the number of the finish program job: " ;
		read numjobend;
	fi
	echo " " ;
	echo " " ;
	echo -n "Are you sure? [y/n]: ";
	read opc;
	if [ "$opc" = "y" ]
	then
		atrm $numjobinit;
		atrm $numjobend;
		echo " " ;
		echo "Program jobs: $numjobinit, $numjobend deleted.";
		echo "" ;
		echo "" ;
		echo "WARNING: Maybe this program has a CDDOIT directory asociated." ;
		echo "         If you wish in the next screen you can remove it." ;
		PressAnyKey;
		DelDir;	
	else
		PressAnyKey;
	fi
	return;
}


#******************************************************************************

ProgramRecord () {
	while true;
	do
		clear ;
		echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
		echo "CDDOIT: Program an audio recording" ;
		echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
		echo " " ;
		echo " " ;
		echo "Recording is in WAV format, Stereo, 16 bits & 44.100 Hz." ;
		echo " " ;
		echo " " ;
		echo -n "Recording title [0: Exit]: " ;
		read file;
		if [ "$file" = "0" ] || [ "$file" = "" ]
		then
			return;
		fi
		if [ ! -d "$HOME/cddoit/$file" ]
		then
			echo "" ;
			mkdir --verbose "$HOME/cddoit/$file" ;
			cd "$HOME/cddoit/$file";
			echo "CDDOIT Warning" > "NO REMOVE THIS DIRECTORY.README!";
			echo "**************" >> "NO REMOVE THIS DIRECTORY.README!";
			echo "" >> "NO REMOVE THIS DIRECTORY.README!";
			echo "No delete this directory!." >> "NO REMOVE THIS DIRECTORY.README!";
			echo "This directory was created for a CDDOIT audio recording program." >> "NO REMOVE THIS DIRECTORY.README!";
			echo "If you delete the directory the audio program will be failed." >> "NO REMOVE THIS DIRECTORY.README!";
			echo "" >> "NO REMOVE THIS DIRECTORY.README!";
			echo "This warning-file will be removed automatically after audio program finished." >> "NO REMOVE THIS DIRECTORY.README!";
			echo "" >> "NO REMOVE THIS DIRECTORY.README!";
			echo "You can check the CDDOIT audio recording programs in the CDDOIT menu AUDIO." >> "NO REMOVE THIS DIRECTORY.README!";
			break;
		else
			echo " " ;
			Beep;
			echo "WARNING: The file already exist. Enter a diferent name.";
			PressAnyKey;
		fi
	done
	echo "" ;
	echo "" ;
	echo "NOTE: Press 'y' if your SOX version is older or the recording" ;
	echo "      quality is not good.";
	echo "      Default 'n'.";
	echo -n "Do you wish the audio recording in 44101 Hz [y/n(ENTER)]: ";
	read opc44101;
	PressAnyKey;
	clear;
	echo "PROGRAMMING OF AUDIO RECORDING";
	echo "==============================";
	echo "";	
	echo "WARNING: Be carefull and check:";
	echo "         . Date & time is correct in your host!";
	echo "         . When program start, the audio source must be ON";
	echo "                and your user will be in logon!";
	echo "";	
	echo "";	
	echo -n "1. Enter the date and time to start audio recording, now is ";	
	date +[%d/%m/%y][%H:%M];
	echo -n "        Year [YY]: ";
	read syear;
	echo -n "        Month [MM]: ";
	read smonth;
	echo -n "        Day [DD]: ";
	read sday;
	echo -n "        Hour [HH]: ";
	read shour;
	echo -n "        Minute [MM]: ";	
	read sminute;
	echo "";	
	echo "";	
	echo -n "2. Enter the date and time to finish audio recording, now is ";
	date +[%d/%m/%y][%H:%M];
	echo -n "        Year [YY]: ";
	read fyear;
	echo -n "        Month [MM]: ";
	read fmonth;
	echo -n "        Day [DD]: ";
	read fday;
	echo -n "        Hour [HH]: ";
	read fhour;
	echo -n "        Minute [MM]: ";	
	read fminute;
	PressAnyKey;
	if [ "$opc44101" = "y" ]
	then
		echo "" ;
		echo "" ;
		echo " WARNING: The sample rate in WAV files to CD-R copy is 44.100 Hz and" ;
		echo "  *****   this recording is in 44.101 Hz." ;
		echo " ** | **  You must convert to this sample rate before the CD-R copy." ;
		echo " ** 0 **  You can do it now or convert later in menu AUDIO, option n 10." ;
		echo "  *****   In big files this action is going to take a long time" ;
		echo "" ;
		echo -n "Do you like perform conversion to 44.100 Hz after the recording? [y/n]: " ;
		read opcconv;
		if [ "$opcconv" = "y" ]
		then
			echo "";	
			echo -n "Remove old audio 44.101 Hz file after the conversion? [y/n]: " ;
			read opcrem;
		fi
	fi
	echo "";	
	echo "";	
	echo "Saving start recording parameters...";	
	if [ "$opc44101" = "y" ]
	then
		echo "sox -V -r 44101 -c 2 -t ossdsp -w -s /dev/dsp -t wav -r 44101 -c 2 -w -s \""$file.44101.wav"\"" > "$HOME/cddoit/$file/$file.start.at";
	else
		echo "sox -V -r 44100 -c 2 -t ossdsp -w -s /dev/dsp -t wav -r 44100 -c 2 -w -s \""$file.44100.wav"\"" > "$HOME/cddoit/$file/$file.start.at";
	fi
	at -f "$HOME/cddoit/$file/$file.start.at" -m $shour:$sminute $sday.$smonth.$syear;
	rm -f "$HOME/cddoit/$file/$file.start.at";
	if [ "$?" = "1" ]   # AT command is not correct
	then
		echo "ERROR: the format of the start parameters is not correct.";
		rm -fr "$HOME/cddoit/$file";
		PressAnyKey;
		return;
	fi
	echo "";
	echo "";	
	echo "Saving finish recording parameters...";
	echo 'numpid=`ps -u "$USER" | grep 'sox'`' > "$HOME/cddoit/$file/$file.finish.at";
	echo 'kill $numpid' >> "$HOME/cddoit/$file/$file.finish.at";
	if [ "$opc44101" = "y" ]
	then
		if [ "$opcconv" = "y" ]
		then
			echo "sox -V -r 44101 -c 2 -t wav -w -s \""$file.44101.wav"\" -t wav -r 44100 -c 2 -w -s \""$file.44100.wav"\"" >> "$HOME/cddoit/$file/$file.finish.at";
			if [ "$opcrem" = "y" ]
			then
				echo "rm -f \"$file.44101.wav\"" >> "$HOME/cddoit/$file/$file.finish.at";
			fi
		fi
	fi
	echo 'rm -f "NO REMOVE THIS DIRECTORY.README!"' >> "$HOME/cddoit/$file/$file.finish.at";
	at -f "$HOME/cddoit/$file/$file.finish.at" -m $fhour:$fminute $fday.$smonth.$syear;
	rm -f "$HOME/cddoit/$file/$file.finish.at";
	if [ "$?" = "1" ]   # AT command is not correct
	then
		echo "ERROR: the format of the finish parameters is not correct.";
		rm -fr "$HOME/cddoit/$file";
		PressAnyKey;
		return;
	fi
	echo "";	
	echo "";	
	if [ "$opc44101" = "y" ]
	then
		if [ "$opcconv" = "y" ]
		then
			echo "The conversion will be started after the recording finished.";
			echo "";	
		fi
	fi
	echo "The start and finish parameters were saved OK.";	
	echo "The audio recording is scheduled OK.";
	echo "" ;
	echo "After the recording, you can check the output messages in your mail!";
	echo -n "The audio recording will be found in: " ;
	echo "$HOME/cddoit/$file" ;
	PressAnyKey;
	return;
}



#******************************************************************************

GetMP3fromCD () {
	clear;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "CDDOIT: Get MP3 files from Audio-CD" ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	GetDirWavTracks;
	if [ "$?" = "1" ]
	then
		return 1;
	fi
	GetOriginalCD;
	while true;
	do
		echo "" ;
		echo "" ;
		echo "Enter the MP3 Kb/Seg quality :" ;
		echo "" ;
		echo "   1. 128 Kb/Seg, 44.1 KHz, 16 Bits, Stereo" ;
		echo "   2. 320 Kb/Seg, 44.1 KHz, 16 Bits, Stereo" ;
		echo "" ;
		echo -n "Value: " ;
		read value;
		echo "" ;
		if [ "$value" != "1" ] && [ "$value" != "2" ]
		then
			echo "Error. Incorrect value.";
		else
			break;
		fi
	done
	echo "" ;
	echo "" ;
	echo "Enter audio extraction type:" ;
	echo " " ;
	echo "	1. Maximum quality -Slow extraction-" ;
	echo "	2. Good quality, no errors -Quick extraction-" ;
	echo "	3. Regular quality, possible errors -Very quick extraction-" ;
	echo " " ;
	echo -n "Type: " ;
	read type;
	echo " " ;
	echo " " ;
	echo "Enter tracks to extract from audio CD:" ;
	echo " " ;
	echo " " ;
	echo "	Examples of audio tracks extracting:" ;
	echo " " ;
	echo "	1-   All CD tracks";
	echo "	2    Extract only track 2";
	echo "	-2   Extract from track 1 to 2";
	echo "	2-   Extract from track 2 to the last track of the CD";
	echo "	2-7  Extract tracks 2 to 7";
	echo "	1:[20.35]   Extract from second 20, sector 35 of track 1 to the end of track 1";
	echo "	1:[20.35]-  Extract from second 20, sector 35 of track 1 to the last track od CD";
	echo "" ;
	echo "" ;
	echo -n "Tracks (1-  All CD tracks): " ;
	read tracks;
	del="-del";
	empty="";
	if [ "$tracks" = "1-" ]
	then
		echo "" ;
		cdparanoia -Q;
		if [ "$?" = "1" ]
		then
			PressAnyKey;
			return 1;
		fi
		echo " " ;
		echo " " ;
		echo -n "Enter the number of tracks contained in the CD: " ;
		read numtracks;
		echo " " ;
		echo " " ;
		track=1;
		while [ "$track" -le "$numtracks" ];
		do
			case $type in
			1) cdparanoia -B "$track";;
			2) cdparanoia -Y -B "$track";;
			3) cdparanoia -Z -B "$track";;
			esac;
			if [ "$?" = "1" ]
			then
				PressAnyKey;
				return 1;
			fi
			track=`expr ${track} + 1`;
			WAV2MP3Conversion $value *.wav $empty $del;
		done
	else
		echo " " ;
		echo " " ;
		case $type in
			1) cdparanoia -B "$tracks";;
			2) cdparanoia -Y -B "$tracks";;
			3) cdparanoia -Z -B "$tracks";;
		esac;
		if [ "$?" = "1" ]
		then
			PressAnyKey;
			return 1;
		fi
		for wavfile in *.wav;
		do
			WAV2MP3Conversion $value "$wavfile" $empty $del;
		done;
	fi
	Beep;
	GetSizeInMB;
	echo "" ;
	echo "" ;
	echo -n "Do you like to rename the new MP3 file names? [y/n]: " ;
	read opc;
	if [ "$opc" = "y" ]
	then
		RenameMP3ListTracks;
	else
		PressAnyKey;
		return ;
	fi
}



#******************************************************************************
GetWAVfromCD () {
	clear;	
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "CDDOIT: Get WAV files from Audio-CD" ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	GetDirWavTracks;
	if [ "$?" = "1" ]
	then
		return 1;
	fi
	echo " " ;
	echo " " ;
	echo "Enter tracks to extract from audio CD:" ;
	echo " " ;
	echo " " ;
	echo "	Examples of audio tracks extracting:" ;
	echo " " ;
	echo "	1-   All CD tracks";
	echo "	2    Extract only track 2";
	echo "	-2   Extract from track 1 to 2";
	echo "	2-   Extract from track 2 to the last track of the CD";
	echo "	2-7  Extract tracks 2 to 7";
	echo "	1:[20.35]   Extract from second 20, sector 35 of track 1 to the end of track 1";
	echo "	1:[20.35]-  Extract from second 20, sector 35 of track 1 to the last track od CD";
	echo "" ;
	echo "" ;
	echo -n "Tracks (1-  All CD tracks): " ;
	read tracks;
	if [ "$tracks" = "1-" ]
	then
		GetWavTrackByTrack;
	else
		echo " " ;
		echo " " ;
		echo "Enter audio extraction type:" ;
		echo " " ;
		echo "	1. Maximum quality -Slow extraction-" ;
		echo "	2. Good quality, no errors -Quick extraction-" ;
		echo "	3. Regular quality, possible errors -Very quick extraction-" ;
		echo "" ;
		echo -n "Type: " ;
		read type;
		echo "" ;
		echo "" ;
		case $type in
			1) cdparanoia -B "$tracks";;
			2) cdparanoia -Y -B "$tracks";;
			3) cdparanoia -Z -B "$tracks";;
		esac;
		if [ "$?" = "1" ]
		then
			PressAnyKey;
			return 1;
		fi
	fi
	GetSizeInMB;
	PressAnyKey;
	return ;
}


#******************************************************************************

AudioRecord () {
# parameters:  1  CD copy format recording (44100)
#              2  recording to 44101 Hz 
	while true;
	do
		clear ;
		echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
		echo "CDDOIT: Record audio in WAV format" ;
		echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
		echo " " ;
		echo " " ;
		if [ "${1}" = "2" ]
		then
			echo "Recording is in WAV format, Stereo, 16 bits & 44.101 Hz." ;
			echo "";
			echo "NOTE: This option is only for compatibility with some soundcards";
			echo "      and old versions of SOX";
			echo "      Use this option only if you detect errors in the 44.100 Hz";
			echo "      audio recording";
		else
			echo "Recording is in WAV format, Stereo, 16 bits & 44.100 Hz.";
		fi
		echo " " ;
		echo " " ;
		echo -n "Recording title [0: Exit]: " ;
		read file;
		export file;
		if [ "$file" = "0" ] || [ "$file" = "" ]
		then
			return;
		fi
		if [ ! -d "$HOME/cddoit/$file" ]
		then
			echo "" ;
			mkdir --verbose "$HOME/cddoit/$file" ;
			cd "$HOME/cddoit/$file";
			break ;
		else
			echo " " ;
			Beep;
			echo "WARNING: The file already exist. Enter a diferent name.";
			PressAnyKey;
		fi
	done	
	echo " " ;
	echo " " ;
	echo -n "Do you like perform the recording under ROOT? [maximum priority] y/n: ";
	read opc;
	if [ "$opc" = "y" ]
	then
		cdformat=${1};
		export cdformat;
		echo "Enter the ROOT password." ;
		su -c '
		echo " " ;
		echo "Press ENTER to start the recording." ;
		read;
		echo " " ;
		echo " " ;
		echo "Enter CTRL+C to finish the recording." ;
		echo "RECORDING WITH MAXIMUM PRIORITY [ROOT]...";
		echo " " ;
		if [ "cdformat" = "2" ]
		then
			sox -V -r 44101 -c 2 -t ossdsp -w -s /dev/dsp -t wav -r 44101 -c 2 -w -s "$file.44101.wav"
		else
			sox -V -r 44100 -c 2 -t ossdsp -w -s /dev/dsp -t wav -r 44100 -c 2 -w -s "$file.44100.wav"
		fi';
		if [ "$?" = "1" ]   # if SU return bad code...
		then
			PressAnyKey;
			return;
		fi
	else
		echo " " ;
		echo "Press ENTER to start the recording." ;
		read;
		echo " " ;
		echo " " ;
		echo "Enter CTRL+C to finish the recording." ;
		echo "RECORDING...";
		echo " " ;
		if [ "${1}" = "2" ]
		then
			sox -V -r 44101 -c 2 -t ossdsp -w -s /dev/dsp -t wav -r 44101 -c 2 -w -s "$file.44101.wav";
		else
			sox -V -r 44100 -c 2 -t ossdsp -w -s /dev/dsp -t wav -r 44100 -c 2 -w -s "$file.44100.wav";
		fi
	fi
	if [ "${1}" = "2" ]
	then
		echo "" ;
		echo "" ;
		echo " WARNING: The sample rate in WAV files to CD-R copy is 44.100 Hz and" ;
		echo "  *****   this recording is in 44.101 Hz." ;
		echo " ** | **  You must convert to this sample rate before the CD-R copy." ;
		echo " ** 0 **  You can do it now or convert later in menu AUDIO, option n 10." ;
		echo "  *****   In big files this action is going to take a long time" ;
		echo "" ;
		echo -n "Do you like perform conversion to 44.100 Hz now? [y/n]: " ;
		read opc;
		if [ "$opc" = "y" ]
		then
			echo "";
			echo "";
			sox -V -r 44101 -c 2 -t wav -w -s "$file".44101.wav -t wav -r 44100 -c 2 -w -s "$file".44100.wav;
			echo "";
			echo "Sample rate conversion finished.";
			echo "";
			Beep;
			echo -n "Remove old audio 44.101 Hz file after the conversion? [y/n]: " ;
			read opc;
			if [ "$opc" = "y" ]
			then
				echo "";
				rm -vf "$file.44101.wav";
			fi
		fi
	fi
	echo "" ;
	echo "" ;
	echo -n "The recording is found in: " ;
	echo "$HOME/cddoit/$file" ;
	GetSizeInMB;
	PressAnyKey;
	return;
}

#******************************************************************************

DataDirectCopy () {
	cd "$HOME/cddoit/cddata";
	clear ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	if [ "${1}" = "1" ]	#copia real (no dummy)
	then
		echo "CDDOIT: Data-CD direct copy to CD-R (Get data image and copy)";
	else
		echo "CDDOIT: Data-CD direct dummy copy to CD-R (Get data image and dummy copy)";
	fi	
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "";
	echo "";
	echo "Insert the source and target CDs.";
	PressAnyKey;
	CleanDataTempDir;
	echo "";
	echo "";
	echo "The copy must be performed under ROOT. Enter the password." ;
	if [ "${1}" = "1" ]	# copia real
	then
		su -c 'mount /dev/cdrom /mnt/cdrom ; mkisofs -R -J -f -o image.raw /mnt/cdrom ; cdrecord -v -eject image.raw ; umount /dev/cdrom' ;
	else	# mode dummy
		su -c 'mount /dev/cdrom /mnt/cdrom ; mkisofs -R -J -f -o image.raw /mnt/cdrom ; cdrecord -v -dummy -eject image.raw ; umount /dev/cdrom' ;
	fi			
	echo "";
	PressAnyKey;
	return ;
}




#******************************************************************************

OntheflyDataCopy () {
#arguments: 1:  real copy, rest: dummy copy
	cd "$HOME/cddoit/cddata";
	clear;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	if [ "${1}" = "1" ]	# real copy (no dummy)
	then
		echo "CDDOIT: On-the-fly Data-CD copy to CD-R";
	else
		echo "CDDOIT: On-the-fly Data-CD dummy copy to CD-R";
	fi	
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "";
	echo "****************************************************************************";
	echo "CAUTION:";
	echo "" ;
	echo "Risk of buffer underrun on 'On-the-fly' data copy!";
	echo "" ;
	echo "First, make a dummy copy to check the buffer size is OK.";
	echo "If the current buffer size is not enough, increase the";
	echo "FIFO size in the CDRECORD configuration file.";
	echo "See menu OTHERS, option n 10." ;
	echo "Also you can low the copy speed." ;
	echo "****************************************************************************";
	echo "" ;
	echo "" ;
	echo "Insert the source and target CDs.";
	PressAnyKey;
	if [ "${1}" = "1" ]	#copia real (no dummy)
	then
		echo "" ;
		echo "" ;
		echo -n "Do you wish to perform On-the-fly data copy? y/n: " ;
		read opc;
		if [ "$opc" = "y" ]
		then
			CopyCD 8;
		fi
	else	# copia modo dummy
		CopyCD 9
	fi		
	PressAnyKey;
	return 0;
}



#******************************************************************************

Image2cd () {
	clear ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	if [ "${1}" = "1" ]	# real copy (no dummy)
	then
		echo "CDDOIT: Copy data image file to CD-R";
	else
		echo "CDDOIT: Dummy copy data image file to CD-R";
	fi	
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	while true;
	do
		GoToDir;
		if [ "$?" = "1" ]
		then
			return 1;
		fi
		if [ ! -f "image.raw" ]
		then
			echo "";
			echo "";
			echo "ERROR: Data image file [image.raw] not found!";
			echo "       Enter the correct path.";
			Beep;
			PressAnyKey;
		else
			break;
		fi
	done
	echo "" ;
	echo "WARNING:  MULTISESSION does not close recordable CD and allows copy" ;
	echo "  *****   of data to recordable CD on several ocasions." ;
	echo " ** | **  Remember: The first data image to CD-R for multisession" ;
	echo " ** 0 **  are different from second and followings data image files." ;
	echo "  *****   See menu DATA, option n 2" ;
	echo "" ;
	echo "" ;
	echo -n "Do you wish to select MULTISESSION option? y/n: ";
	read multi;
	GetCDRecordable;
	if [ "$multi" = "y" ]
	then
		if [ "${1}" = "1" ]
		then
			CopyCD 3; # multisesion copy
		else
			CopyCD 7; # multisession dummy copy
		fi		
	else
		if [ "${1}" = "1" ]
		then
			CopyCD 2; # copy
		else
			CopyCD 6; # dummy copy
		fi		
	fi
	if [ "$?" != "1" ] # No error on SU
	then
		echo "" ;
		echo "" ;
		echo "Data copy finished." ;
		echo "" ;
		echo -n "Do you like delete the Data Image file [image.raw]? [y/n]: ";
		read opc;
		if [ "$opc" = "y" ]
		then
			echo "" ;
			rm -fv image.raw;
		fi
	fi
	PressAnyKey;
	return ;
}

#******************************************************************************

GetImage () {
	cd "$HOME/cddoit/cddata";
	clear ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	if [ "${1}" = "1" ]	# real copy (no dummy)
	then
		echo "CDDOIT: Get data image file" ;
	else
		echo "CDDOIT: Get multisession data image file" ;
	fi	
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	GoToDir;
	if [ "$?" = "1" ]
	then
		return 1;
	fi
	DirOrg=$PWD;
	DirDest=$PWD;
	HomeUser=$HOME;
	echo " " ;
	echo "-By default data image file will be stored in the selected directory-" ;
	echo -n "Create new directory for image file? y/n: ";
	read opc;
	if [ "$opc" = "y" ]
	then
		CreateDirectory;
		if [ "$?" = "1" ]
		then
			return 1;
		fi
		DirDest=$PWD;
	fi
	CleanDataTempDir;
	echo " " ;
	echo " " ;
	if [ "${1}" = "2" ]  # multisession
	then
		echo "ATTENTION  IN MULTISESSION DATA IMAGE FILES:";
		echo "           If this is the first data image file to the CD-R (The CD-R";
		echo "  *****    is blank yet), you must enter 'y' in the next question.";
		echo " ** | **   In the second and followings data images files to multisession";
		echo " ** o **   CD-R (multisession CD-R not blank) must be created with";
		echo "  *****    special features so enter 'n' in next question.";
		mkdir "$HOME/cddoit/dirmulti";
		ln -s "$DirOrg" "$HOME/cddoit/dirmulti";
		echo "";
		echo -n "This is the first data image file to CD-R? [y/n]: ";
		read opc;
		if [ "$opc" = "y" ]
		then
			echo "";
			echo "";
			echo "Creating first multisession data image file...";
			echo "";
			mkisofs -R -J -f -o "$DirDest/image.raw" "$HOME/cddoit/dirmulti";
		else
			export DirOrg;
			export DirDest;
			export HomeUser;
			echo "";
			echo "";
			echo "To create a no-first multisession data image file,";
			echo "first, you must known some information under ROOT.";
			echo "";
			echo "Please, insert the multisession CD-R in the CD-Recorder (not CD-ROM).";
			PressAnyKey;
			echo "";
			echo "";
			echo "The operation must be performed under ROOT. Enter the password.";
			su -c '
echo "";
echo "1. Getting the MSINFO number of CD-R ...";
msinfo=`cdrecord -msinfo`;
echo "";
echo "2. Getting SCSI CD-Recorder devices for CDRECORD.";
echo "";
cdrecord -scanbus;
echo "";
echo -n "Enter the SCSI CD-Recorder device [X,Y,Z], e.g. 0,1,0: ";
read cdrdevice;
#create a temporary directory to move the data and create a data image file.
echo "";
echo "";
echo "Creating multisession data image file...";
echo "";
mkisofs -R -J -f -o "$DirDest/image.raw" -C $msinfo -M $cdrdevice "$HomeUser/cddoit/dirmulti";'
			if [ "$?" = "1" ]
			then
				PressAnyKey;
				return ;
			fi
		fi
		rm -fr "$HOME/cddoit/dirmulti";
	else    # no multisession
		echo "NOTE: If you wish, in the CD-R, the files inside the directory";
		echo "      then press 'Y' otherwise the files will be copied in the" ;
		echo "      first level." ;
		echo " " ;
		echo -n "Do you wish include the directory in the copy? [y/n]: " ;
		read opc;
		if [ "$opc" != "y" ]
		then
			cd "$DirOrg";
		fi
		echo " " ;
		echo " " ;
		echo "Creating data image file..." ;
		echo " " ;
		mkisofs -R -J -f -o "$DirDest/image.raw" "$DirOrg";
	fi
	cd "$DirDest";
	GetSizeInMB;
	echo -n "Data image file is found in: ";
	pwd;
	PressAnyKey;
	return ;
}


#******************************************************************************

MP3toCD () {
	CleanAudioTempDir;
	while true;
	do
		clear ;
		echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
		if [ "${1}" = "1" ]	# real copy (no dummy)
		then
			echo "CDDOIT: MP3 files to CD-R copy" ;
		else
			echo "CDDOIT: MP3 files to CD-R DUMMY copy" ;
		fi	
		echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
		GoToDir;
		if [ "$?" = "1" ]
		then
			return 1;
		fi
		echo " " ;
		echo " " ;
		echo -n "Select the file [*: All, f: Finish selection, 0: Exit]: " ;
		read archvmp3;
		echo " " ;
		echo " " ;
		if [ "$archvmp3" = "f" ]
		then
			break;
		fi
		if [ "$archvmp3" = "0" ] || [ "$archvmp3" = "" ]
		then
			return;
		fi
		if [ "$archvmp3" = "*" ]
		then
			for archv in *.mp3;
			do
				mpg123 -s -r 44100 "$archv" > "$HOME/cddoit/cdaudio/$archv.raw";
				sox -t raw -r 44100 -c 2 -w -s "$HOME/cddoit/cdaudio/$archv.raw"  -r 44100 -c 2 -t wav -w -s "$HOME/cddoit/cdaudio/$archv.wav" ;
				rm -f "$HOME/cddoit/cdaudio/$archv.raw" ;
			done ;
			GetSizeInMB;
			break;
		else
			if [ -f "$HOME/cddoit/cdaudio/$archvmp3.wav" ]
			then
				Beep;
				echo -n "WARNING: ";
				echo -n "$archvmp3";
				echo " was converted before.";
				PressAnyKey;
			else
				if [ ! -f "$archvmp3" ]
				then
					Beep;
					echo "ERROR: File not found.";
					PressAnyKey;
				else
					mpg123 -s -r 44100 "$archvmp3" > "$HOME/cddoit/cdaudio/$archvmp3.raw" ;
		  		  sox -t raw -r 44100 -c 2 -w -s "$HOME/cddoit/cdaudio/$archvmp3.raw"  -r 44100 -c 2 -t wav -w -s "$HOME/cddoit/cdaudio/$archvmp3.wav";
					rm -f "$HOME/cddoit/cdaudio/$archvmp3.raw" ;
					GetSizeInMB;
					PressAnyKey;
				fi
			fi
		fi
	done
	echo " " ;
	echo "WARNING:" ;
	echo "	74 minutes audio CD capacity (aprox.): 650 Mb." ;
	echo "	80 minutes audio CD capacity (aprox.): 700 Mb." ;
	GetCDRecordable;
	cd "$HOME/cddoit/cdaudio" ;
	while true;
	do
		CopyCD ${1};
		if [ "$?" = "1" ] # CopyCD error (possible SU error)
		then
			echo "";
			echo "ERROR. CD-Copy could not be started.";
			echo "       Possible incorrect ROOT password.";
			Beep;
			echo "";
			echo -n "Re-enter the password again? [y/n]: ";
			read opc;
			if [ "$opc" != "y" ]
			then
				break;
			fi
		else
			break;
		fi
	done
	CleanAudioTempDir;
	Beep;
	echo "";
	echo "";
	echo "Copy finished.";
	PressAnyKey;
	return 0;
}

#******************************************************************************

AudioCopy () {
	clear ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	if [ "${1}" = "1" ]	# real copy (no dummy)
	then
		echo "CDDOIT: WAV files to CD-R copy" ;
	else
		echo "CDDOIT: WAV files to CD-R DUMMY copy" ;
	fi	
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	GoToDir;
	if [ "$?" = "1" ]
	then
		return 1;
	fi
	echo " " ;
	echo " " ;
	echo -n "Enter speed of copy (INTRO, Default speed): " ;
	read speed;
	export speed;
	echo " " ;
	echo "DAO: The audio tracks are recorded without 4 seconds between us. (Default)";
	echo "     If your CD-Recorder can record in DAO mode (is very possible) press ENTER.";
	echo -n "Do you like a DAO recording? [y(ENTER)/n]: ";
	read dao;
	export dao;
	GetCDRecordable;
	while true;
	do
		CopyCD ${1};
		if [ "$?" = "1" ] # CopyCD error (possible SU error)
		then
			echo "";
			echo "ERROR. CD-Copy could not be started.";
			echo "       Possible incorrect ROOT password.";
			Beep;
			echo "";
			echo -n "Re-enter the password again? [y/n]: ";
			read opc;
			if [ "$opc" != "y" ]
			then
				break;
			fi
		else
			break;
		fi
	done
	PressAnyKey;
	return 0;
}

#******************************************************************************

AudioDirectCopy () {
	cd "$HOME/cddoit/cdaudio"
	clear ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	if [ "${1}" = "1" ]
	then
		echo "CDDOIT: Direct Audio CD copy to CD-R" ;
	else
		echo "CDDOIT: Direct Audio CD DUMMY copy to CD-R" ;
	fi
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	GetOriginalCD;
	GetCDRecordable;
	CleanAudioTempDir;
	while true;
	do
		if [ "${1}" = "1" ]
		then
			CopyCD 5;
		else
			CopyCD 14; # dummy copy
		fi
		if [ "$?" = "1" ] # CopyCD error (possible SU error)
		then
			echo "";
			echo "ERROR. CD-Copy could not be started.";
			echo "       Possible incorrect ROOT password.";
			Beep;
			echo "";
			echo -n "Re-enter the password again? [y/n]: ";
			read opc;
			if [ "$opc" != "y" ]
			then
				break;
			fi
		else
			break;
		fi
	done
	CleanAudioTempDir;
	PressAnyKey;
	return;
}


#******************************************************************************

CreateDirByDefault () {
# go to CDDOIT directory and if it is not found, create it
	if [ ! -d "$HOME/cddoit" ]
	then
		clear;
		echo "\

Welcome to CDDOIT 1.3!

Written by Jose L. Diaz.
February/2002

Homepage: http://www.geocities.com/cddoit/index.html

This is free software.
Only, I would like to know in many countries of the world CDDOIT is being
used, for that reason would be thankful to you that you sent me a mail
(cddoit@yahoo.com) indicating only your country and city.
Thanks in advance.

I am from Madrid, Spain.

Report bugs or suggestions to: cddoit@yahoo.com
This software comes with NO warranty of any kind. Use at your own risk.


--------------------------------------------------------------
WARNING: For a correct CDDOIT funcionality, you must
         configure properly the CDRECORD configuration file in
         menu OTHERS, option n 10.
--------------------------------------------------------------";
		PressAnyKey;
		mkdir "$HOME/cddoit";
	fi

	if [ ! -d "$HOME/cddoit/cdaudio" ]
	then
		mkdir "$HOME/cddoit/cdaudio";
	fi

	if [ ! -d "$HOME/cddoit/cddata" ]
	then
		mkdir "$HOME/cddoit/cddata";
	fi
}

#******************************************************************************

GetDirWavTracks () {
# show the existing directories
	echo "" ;
	echo "" ;
	echo "CDDOIT directories:" ;
	echo "____________________________________________________________________________" ;
	ls -Cm --color "$HOME/cddoit" ;
	echo "____________________________________________________________________________" ;
	echo "" ;
	echo "Enter directory name already exist or new" ;
	echo -n "where the audio files will be stored [0: Exit]: "
	read nomdir ;
	if [ "$nomdir" = "0" ] || [ "$nomdir" = "" ]
	then
		return 1;
	fi
	if [ ! -d "$HOME/cddoit/$nomdir" ]
	then
		echo "" ;
		mkdir --verbose "$HOME/cddoit/$nomdir" ;
		cd "$HOME/cddoit/$nomdir";
	else
		echo " " ;
		echo "WARNING: The directory already exist and may contain files.";
		echo " " ;
		cd "$HOME/cddoit/$nomdir";
		echo "Files in "$HOME/cddoit/$nomdir" :" ;
		echo "____________________________________________________________________________" ;
		ls -C;
		echo "____________________________________________________________________________" ;
	fi
}

#******************************************************************************

GetWavTrackByTrack () {
# extract tracks running cdparanoia once per track. Better quality
	clear;
	cdparanoia -Q;
	if [ "$?" = "1" ]
	then
		PressAnyKey;
		return 1;
	fi
	echo " " ;
	echo " " ;
	echo -n "Enter the number of tracks contained in the CD: " ;
	read numtracks;
	echo " " ;
	echo " " ;
	echo "Enter audio extraction type:" ;
	echo " " ;
	echo "	1. Maximum quality -Slow extraction-" ;
	echo "	2. Good quality, no errors -Quick extraction-" ;
	echo "	3. Regular quality, possible errors -Very quick extraction-" ;
	echo " " ;
	echo -n "Type: " ;
	read type;
	echo " " ;
	echo " " ;
	echo -n "Extracting CD tracks... ";
	echo " " ;
	echo " " ;
	track=1;
	while [ "$track" -le "$numtracks" ];
	do
		case $type in
			1) cdparanoia -B "$track";;
			2) cdparanoia -Y -B "$track";;
			3) cdparanoia -Z -B "$track";;
		esac;
		if [ "$?" = "1" ]
		then
			PressAnyKey;
			return 1;
		fi
		track=`expr ${track} + 1`;
	done
	Beep;
}

#******************************************************************************

GetSizeInMB () {
# argument:  ${1}  a directory
# if argument is not included, the actual directory size is view.

	echo " " ;
	echo " " ;
	echo -n "Size in MBytes: "
	if [ "${1}" != "" ]
	then
		du -h "${1}";
	else
		pwd | du -h;
	fi
}

#******************************************************************************

PressAnyKey () {
	echo "";
	echo "";
	echo -n "|= Press ENTER to continue ==>";
	read;
	return;
}

#******************************************************************************

GoToDir () {
	while true;
	do
		echo "" ;
		echo "" ;
		echo "CDDOIT directories:" ;
		echo "____________________________________________________________________________" ;
		ls -Cm --color "$HOME/cddoit" ;
		echo "____________________________________________________________________________" ;
		echo "-Select with mouse and paste the directory or enter the complete path-";
		echo " " ;
		echo -n "Enter the directory where the original files are [0: Exit]: " ;
		read nomdir;
		if [ "$nomdir" != "0" ] && [  "$nomdir" != "" ]
		then
			if [ -d "$HOME/cddoit/$nomdir" ]
			then
				cd "$HOME/cddoit/$nomdir" ;
				break;
			else
				if [ -d "$nomdir" ]
				then
					cd "$nomdir" ;
					break;
				else
					echo " " ;
					echo " " ;
					Beep;
					echo "ERROR: The directory is not found.";
					echo "       Write the complete path. E.g.: /usr/users1/audio";
					PressAnyKey;
					clear;
				fi
			fi
		else
			return 1
		fi
	done
	echo "";
	echo "Directory files:";
	echo "";
	ls -C *;
	GetSizeInMB;
	return 0;
}

#******************************************************************************

GetCDRecordable () {
	echo " " ;
	echo " " ;
	echo "Insert CD-R Recordable." ;
	echo "Press any key to continue." ;
	read ;
}
#******************************************************************************

GetOriginalCD() {
	echo " " ;
	echo " " ;
	echo "Insert Audio or Data CD." ;
	echo "Press any key to continue." ;
	read ;
}

#******************************************************************************

CopyCD () {
	echo " " ;
	echo " " ;
	echo "The copy must be performed under ROOT. Enter the password." ;
	case ${1} in
		1) su -c '
if [ "$speed" = "" ]
then
	if [ "$dao" = "n" ]
	then
		cdrecord -eject -pad -audio *.wav;
	else
		cdrecord -dao -eject -shorttrack -pad -audio *.wav;
	fi
else
	if [ "$dao" = "n" ]
	then
		cdrecord -eject speed=$speed -pad -audio *.wav;
	else
		cdrecord -dao -eject speed=$speed -shorttrack -pad -audio *.wav;
	fi
fi';;
		2) su -c 'cdrecord -v -eject image.raw' ;;     # data copy
		3) su -c 'cdrecord -v -eject -multi image.raw' ;;  # multisession copy data
		4) su -c '
if [ "$speed" = "" ]
then
	cdrecord -dummy -dao -eject -shorttrack -pad -audio *.wav;
else
	cdrecord -dummy -dao -eject speed=$speed -shorttrack -pad -audio *.wav;
fi';;
		5) su -c '
clear;
cdparanoia -Q;
if [ "$?" = "1" ]
then
	PressAnyKey;
	return 1;
fi
echo " " ;
echo " " ;
echo -n "Enter the number of tracks contained in the CD: " ;
read numtracks;
echo " " ;
echo "Enter audio extraction type:" ;
echo " " ;
echo "	1. Maximum quality -Slow extraction-" ;
echo "	2. Good quality, no errors -Quick extraction-" ;
echo "	3. Regular quality, possible errors -Very quick extraction-" ;
echo " " ;
echo -n "Type: " ;
read type;
echo " " ;
echo -n "Enter speed of copy (INTRO, Default speed): " ;
read speed;
echo " " ;
echo "DAO: The audio tracks are recorded without 4 seconds between us. (Default)";
echo "     If your CD-Recorder can record in DAO mode (is very possible) press ENTER.";
echo -n "Do you like a DAO recording? [y(ENTER)/n]: ";
read dao;
echo " " ;
echo " " ;
echo -n "Extracting CD tracks... ";
echo " " ;
echo " " ;
track=1;
while [ "$track" -le "$numtracks" ];
do
	case $type in
		1) cdparanoia -B "$track";;
		2) cdparanoia -Y -B "$track";;
		3) cdparanoia -Z -B "$track";;
	esac;
	if [ "$?" = "1" ]
	then
		PressAnyKey;
		return 1;
	fi
	track=`expr ${track} + 1`;
done
if [ "$speed" = "" ]
then
	if [ "$dao" = "n" ]
	then
		cdrecord -eject -pad -audio *.wav;
	else
		cdrecord -dao -eject -shorttrack -pad -audio *.wav;
	fi
else
	if [ "$dao" = "n" ]
	then
		cdrecord -eject speed=$speed -pad -audio *.wav;
	else
		cdrecord -dao -eject speed=$speed -shorttrack -pad -audio *.wav;
	fi
fi';;
		6) su -c 'cdrecord -v -dummy -eject image.raw' ;;     # dummy audio copy
		7) su -c 'cdrecord -v -dummy -eject -multi image.raw' ;;  # dummy multisession copy data
		8) su -c 'mount /dev/cdrom /mnt/cdrom; mkisofs -R -J -f /mnt/cdrom | cdrecord -v - ; umount /dev/cdrom';;  # onthefly copy
		9) su -c 'mount /dev/cdrom /mnt/cdrom; mkisofs -R -J -f /mnt/cdrom | cdrecord -v -dummy - ; umount /dev/cdrom';;   # onthefly dummy copy
		10) su -c 'cdrecord -v -dao -eject -shorttrack -pad image.raw -audio *.wav';;  # audio + data copy
		11) su -c 'cdrecord -v -dummy -dao -eject -shorttrack -pad image.raw -audio *.wav';; # audio + data  dummy copy
		12) su -c '
if [ "$speed" = "" ]
then
	cdrecord -v -eject -nofix -pad -audio "$archwav";
else
	cdrecord -v -eject speed=$speed -nofix -pad -audio "$archwav";
fi';;
		13) su -c '
if [ "$speed" = "" ]
then
	cdrecord -v -eject -nofix -pad -dummy -audio "$archwav";
else
	cdrecord -v -eject speed=$speed -nofix -pad -dummy -audio "$archwav";
fi';;
		14) su -c '
clear;
cdparanoia -Q;
if [ "$?" = "1" ]
then
	PressAnyKey;
	return 1;
fi
echo " " ;
echo " " ;
echo -n "Enter the number of tracks contained in the CD: " ;
read numtracks;
echo " " ;
echo "Enter audio extraction type:" ;
echo " " ;
echo "	1. Maximum quality -Slow extraction-" ;
echo "	2. Good quality, no errors -Quick extraction-" ;
echo "	3. Regular quality, possible errors -Very quick extraction-" ;
echo " " ;
echo -n "Type: " ;
read type;
echo " " ;
echo -n "Enter speed of copy (INTRO, Default speed): " ;
read speed;
echo " " ;
echo "DAO: The audio tracks are recorded without 4 seconds between us. (Default)";
echo "     If your CD-Recorder can record in DAO mode (is very possible) press ENTER.";
echo -n "Do you like a DAO recording? [y(ENTER)/n]: ";
read dao;
echo " " ;
echo -n "Extracting CD tracks... ";
echo " " ;
echo " " ;
track=1;
while [ "$track" -le "$numtracks" ];
do
	case $type in
		1) cdparanoia -B "$track";;
		2) cdparanoia -Y -B "$track";;
		3) cdparanoia -Z -B "$track";;
	esac;
	if [ "$?" = "1" ]
	then
		PressAnyKey;
		return 1;
	fi
	track=`expr ${track} + 1`;
done
if [ "$speed" = "" ]
then
	if [ "$dao" = "n" ]
	then
		cdrecord -eject -dummy -pad -audio *.wav;
	else
		cdrecord -dao -eject -dummy -shorttrack -pad -audio *.wav;
	fi	
else
	if [ "$dao" = "n" ]
	then
		cdrecord -eject -dummy speed=$speed -pad -audio *.wav;
	else
		cdrecord -dao -eject -dummy speed=$speed -shorttrack -pad -audio *.wav;
	fi
fi';;
	esac;
	if [ "$?" = "1" ]   # if SU return an error code, CopyCD return 1
	then
		return 1;
	fi
}


#******************************************************************************

CleanAudioTempDir () {
	echo " " ;
	echo "Cleaning CDDOIT temporary directories..." ;
	rm -f "$HOME"/cddoit/cdaudio/* ;
}

#******************************************************************************

CleanDataTempDir () {
	echo " " ;
	echo "Cleaning CDDOIT temporary directories..." ;
	rm -f "$HOME"/cddoit/cddata/* ;
}

#******************************************************************************

CreateDirectory () {
	while true;
	do
		echo " " ;
		echo " " ;
		echo "Directory creation:" ;
		echo "Enter directory name" ;
		echo -n "where the files will be stored [0: Exit]: "
		read nomdir;
		if [ "$nomdir" = "0" ] || [ "$nomdir" = "" ]
		then
			return 1;
		fi
		if [ ! -d "$HOME/cddoit/$nomdir" ]
		then
			echo "" ;
			mkdir --verbose "$HOME/cddoit/$nomdir" ;
			cd "$HOME/cddoit/$nomdir";
			break ;
		else
			echo " " ;
			Beep;
			echo "WARNING: The directory already exist. Enter a diferent name.";
			PressAnyKey;
		fi
	done
}

#******************************************************************************

Beep () { echo -e "\a"; }    # a beep sound

#******************************************************************************

WAV2MP3Conversion () {
# MP3 creation with error check.
# After the conversion the original WAV files are deleted
# arguments:
#	${1} MP3 quality -Kb/seg-
#	${2} the original file to convert
#    ${3} the output file (optional)
#    ${4} flag: the original WAV file will be removed after the conversion

	echo "Init MP3 conversion..." ;
	case ${1} in
		1) bladeenc ${4} -br 128 -crc "${2}" "${3}";;
		2) bladeenc ${4} -br 320 -crc "${2}" "${3}";;
	esac;
	echo "" ;
	echo "MP3 conversion finished." ;
}


#******************************************************************************

DelAll () {
	clear;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "CDDOIT: Delete ALL CDDOIT directories" ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "";
	echo "";
	echo "CDDOIT directories:" ;
	echo "______________________________________________________________________" ;
	ls -Cm --color "$HOME/cddoit" ;
	echo "______________________________________________________________________" ;
	echo "";
	echo "WARNING: CDDOIT audio and data files will be lost!.";
	echo "";
	echo -n "Are you sure? y/n: ";
	read opc;
	if [ "$opc" = "y" ]
	then
		echo "";
		rm -rvf "$HOME"/cddoit/*;
		# creating CDDOIT standard temporary files
		mkdir "$HOME"/cddoit/cdaudio;
		mkdir "$HOME"/cddoit/cddata;
		PressAnyKey;
	fi
	return;
}

#******************************************************************************

GetWAVfromSeveralCD () {
	clear ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "CDDOIT: Get WAV files from several Audio-CD" ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	GetDirWavTracks;
	if [ "$?" = "1" ]
	then
		return 1;
	fi
	echo "" ;
	echo "" ;
	echo "Insert Audio CD";
	echo -n "and enter the CD track number [0: Exit]: ";
	read track;
	if [ "$track" = "0" ] || [ "$track" = "" ]
	then
		break;
	fi
	numtrack=1;
	while true ;
	do
		echo " " ;
		echo -n "Enter a title for the CD track: ";
		read nametrack;
		echo " " ;
		echo "Extracting CD track to audio CD quality..." ;
		echo " " ;
		cdparanoia -B "$track" "$nametrack".wav;
		if [ "$?" = "1" ]
		then
			PressAnyKey;
			return 1;
		fi
		if [ "$numtrack" -lt "10" ]
		then
			mv track*."$nametrack".wav 0$numtrack-"$nametrack".wav;
		else
			mv track*."$nametrack".wav $numtrack-"$nametrack".wav;
		fi
		numtrack=`expr $numtrack + 1`;
		clear ;
		echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
		echo "CDDOIT: Get WAV files from several Audio-CD" ;
		echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
		GetSizeInMB;
		echo " " ;
		echo "Enter a new CD track number or";
		echo -n "insert new Audio CD and enter the CD track number [0: Exit]: ";
		read track;
		if [ "$track" = "0" ] || [ "$track" = "" ]
		then
			break;
		fi
	done
	echo "";
	echo -n "WAV files from Audio-CD are found in: " ;
	pwd;
	echo "";
	echo "";
	echo -n "Do you like perform the WAV to CD copy now? [y/n]: ";
	read opc;
	if [ "$opc" = "y" ]
	then
		while true;
		do
			CopyCD 1;
			if [ "$?" = "1" ] # CopyCD error (possible SU error)
			then
				echo "";
				echo "ERROR. CD-Copy could not be started.";
				echo "       Possible incorrect ROOT password.";
				Beep;
				echo "";
				echo -n "Re-enter the password again? [y/n]: ";
				read opc;
				if [ "$opc" != "y" ]
				then
					break;
				fi
			else
				break;
			fi
		done
	fi
	return 0;
}

#******************************************************************************

GetMP3fromSeveralCD () {

	del="-del";
	empty="";

	clear ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "CDDOIT: Get MP3 files from several Audio-CD" ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	GetDirWavTracks;
	if [ "$?" = "1" ]
	then
		return 1;
	fi
	echo "" ;
	echo "" ;
	echo "Insert Audio CD";
	echo -n "and enter the CD track number [0: Exit]: ";
	read track;
	if [ "$track" = "0" ] || [ "$track" = "" ]
	then
		break;
	fi
	numtrack=1;
	while true ;
	do
		echo " " ;
		echo -n "Enter a title for the CD track: ";
		read nametrack;
		echo " " ;
		echo "Extracting CD track..." ;
		echo " " ;
		cdparanoia -B "$track" "$nametrack".wav;
		if [ "$?" = "1" ]
		then
			PressAnyKey;
			return 1;
		fi
		if [ "$numtrack" -lt "10" ]
		then
			mv track*."$nametrack".wav 0$numtrack-"$nametrack".wav;
		else
			mv track*."$nametrack".wav $numtrack-"$nametrack".wav;
		fi
		numtrack=`expr $numtrack + 1`;
		Beep;
		clear ;
		echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
		echo "CDDOIT: Get MP3 files from several Audio-CD" ;
		echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
		GetSizeInMB;
		echo " " ;
		echo "Enter a new CD track number or";
		echo -n "insert new Audio CD and enter the CD track number [0: Exit]: ";
		read track;
		if [ "$track" = "0" ] || [ "$track" = "" ]
		then
			break;
		fi
	done
	Beep;
	echo "Tracks selection finished." ;
	while true;
	do
		echo "" ;
		echo "" ;
		echo "Enter the MP3 Kb/Seg quality :" ;
		echo "" ;
		echo "   1. 128 Kb/Seg, 44.1 KHz, 16 Bits, Stereo" ;
		echo "   2. 320 Kb/Seg, 44.1 KHz, 16 Bits, Stereo" ;
		echo "" ;
		echo -n "Value: " ;
		read value;
		echo "" ;
		if [ "$value" != "1" ] && [ "$value" != "2" ]
		then
			echo "Error. Incorrect value.";
		else
			break;
		fi
	done
	echo "MP3 conversion..." ;
	echo "";
	for wavfile in *.wav;
	do
		WAV2MP3Conversion $value "$wavfile" $empty $del;
	done;
	echo " " ;
	echo -n "MP3 files from Audio-CD are found in: " ;
	pwd;
	PressAnyKey;
	return ;
}

#******************************************************************************

DelDir () {
	clear;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "CDDOIT: Delete a CDDOIT directory" ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	GoToDir;
	if [ "$?" = "1" ]
	then
		return 1;
	fi
	echo "";
	echo "WARNING: Audio or data files will be lost!.";
	echo "";
	echo -n "Are you sure? y/n: ";
	read opc;
	if [ "$opc" = "y" ]
	then
		echo "";
		rm -rvf "$PWD";
		# creating CDDOIT standard temporary files
		if [ ! -d "$HOME/cddoit/cdaudio" ]
		then
			mkdir "$HOME/cddoit/cdaudio";
		fi
		if [ ! -d "$HOME/cddoit/cddata" ]
		then
			mkdir "$HOME/cddoit/cddata";
		fi
		PressAnyKey;
	fi
	return;
}


#******************************************************************************

DelTemp () {
	clear;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "CDDOIT: Delete files of CDDOIT temporary directories [AUDIOCD & DATACD]" ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "";
	echo "";
	echo "WARNING: CDDOIT temporary audio and data files will be lost!.";
	echo "";
	echo -n "Are you sure? y/n: ";
	read opc;
	if [ "$opc" = "y" ]
	then
		echo "";
		rm -fv "$HOME"/cddoit/cdaudio/*;
		echo "";
		echo "";
		rm -fv "$HOME"/cddoit/cddata/*;
		PressAnyKey;
	fi
	return;
}

#******************************************************************************

PlayWAV () {
	while true;
	do
		clear ;
		echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
		echo "CDDOIT: Play WAV files [WAV, 44.100 Hz, 16 bits, Stereo]" ;
		echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
		GoToDir;
		if [ "$?" = "1" ]
		then
			return 1;
		fi
		echo " " ;
		echo " " ;
		echo -n "Select file to play [*: All, 0: Exit]: " ;
		read archv;
		if [ "$archv" = "0" ] || [ "$archv" = "" ]
		then
			return;
		fi
		if [ "$archv" = "*" ]
		then
			for archv in *.wav;
			do
				clear;
				echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
				echo "CDDOIT: Playing WAV files" ;
				echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
				echo " " ;
				echo " " ;
				echo -n "You are listening: ";
				echo "$archv";
				echo " " ;
				echo " " ;
				echo " " ;
				echo " " ;
				sox -t wav -r 44100 -c 2 -w -s "$archv"  -r 44100 -c 2 -t ossdsp -w -s /dev/dsp ;
			done ;
			break;
		fi
		echo " " ;
		if [ -f "$archv" ]
		then
			clear;
			echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
			echo "CDDOIT: Playing WAV files" ;
			echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
			echo " " ;
			echo " " ;
			echo -n "You are listening: ";
			echo "$archv";
			echo " " ;
			sox -t wav -r 44100 -c 2 -w -s "$archv"  -r 44100 -c 2 -t ossdsp -w -s /dev/dsp;
		else
			Beep;
			echo "ERROR: File not found.";
			PressAnyKey;
		fi
		echo " " ;
		echo " " ;
		echo -n "Play new file? y/n: " ;
		read opc;
		if [ "$opc" != "y" ]
		then
			break;
		fi		
	done
	return;
}	

#******************************************************************************

PlayMP3 () {
	while true;
	do
		clear ;
		echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
		echo "CDDOIT: Play MP3 files" ;
		echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
		GoToDir;
		if [ "$?" = "1" ]
		then
			return 1;
		fi
		echo " " ;
		echo " " ;
		echo -n "Select the file to play [*: All, 0: Exit]: " ;
		read archv;
		if [ "$archv" = "0" ] || [ "$archv" = "" ]
		then
			return;
		fi
		if [ "$archv" = "*" ]
		then
			for archv in *.mp3;
			do
				clear;
				echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
				echo "CDDOIT: Play MP3 files" ;
				echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
				echo " " ;
				echo " " ;
				echo " " ;
				echo -n "You are listening: ";
				echo "$archv";
				echo " " ;
				echo " " ;
				echo " " ;
				echo " " ;
				mpg123 "$archv";
			done ;
			break;
		fi
		echo " " ;
		if [ -f "$archv" ]
		then
			echo -n "You are listening: ";
			echo "$archv";
			echo " " ;
			mpg123 "$archv";
		else
			Beep;
			echo "ERROR: File not found.";
			PressAnyKey;
		fi
		echo " " ;
		echo " " ;
		echo -n "Play new file? y/n: " ;
		read opc;
		if [ "$opc" != "y" ]
		then
			break;
		fi		
	done
	return;
}	

#******************************************************************************

WAVtoMP3 () {
	while true;
	do
		clear ;
		echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
		echo "CDDOIT: Convert WAV files to MP3 format" ;
		echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
		GetDirWavTracks;
		if [ "$?" = "1" ]
		then
			return 1;
		fi
		DirDest=$PWD;
		GoToDir;
		if [ "$?" = "1" ]
		then
			return 1;
		fi
		DirOrg=$PWD;
		echo " " ;
		echo " " ;
		echo -n "Select the file [*: All, 0: Exit]: " ;
		read archvwav;
		if [ "$archvwav" = "0" ] || [ "$archvwav" = "" ]
		then
			return;
		fi
		echo "" ;
		echo "" ;
		echo -n "Do you wish to remove the original WAV files after the conversion? [y/n]: ";
		read opc;
		if [ "$opc" = "y" ]
		then
			DelWav="-del";
		else
			DelWav="";
		fi
		while true;
		do
			echo "" ;
			echo "" ;
			echo "Enter the MP3 Kb/Seg quality :" ;
			echo "" ;
			echo "   1. 128 Kb/Seg, 44.1 KHz, 16 Bits, Stereo" ;
			echo "   2. 320 Kb/Seg, 44.1 KHz, 16 Bits, Stereo" ;
			echo "" ;
			echo -n "Value: " ;
			read value;
			echo "" ;
			if [ "$value" != "1" ] && [ "$value" != "2" ] 
			then
				echo "Error. Incorrect value.";
			else
				break;
			fi
		done
		cd "$DirDest";
		echo " " ;
		echo " " ;
		if [ "$archvwav" = "*" ]
		then
			cd "$DirOrg";
			for archv in *.wav;
			do
				WAV2MP3Conversion $value "$DirOrg/$archv" "$DirDest/$archv.mp3" "$DelWav";
			done ;
			break;
		else
			if [ -f "$DirDest/$archvwav.mp3" ]
			then
				Beep;
				echo -n "WARNING: ";
				echo -n "$archvwav";
				echo "  was converted before.";
				PressAnyKey;
			else
				if [ ! -f "$DirOrg/$archvwav" ]
				then
					Beep;
					echo "ERROR: File not found.";
					PressAnyKey;
				else
					WAV2MP3Conversion $value "$DirOrg/$archvwav" "$DirDest/$archvwav.mp3" "$DelWav";
					break;
				fi
			fi
		fi
	done
	echo " " ;
	echo " " ;
	echo -n "The MP3 files are found in: " ;
	echo "$DirDest";
	echo "" ;
	echo "" ;
	echo -n "Do you wish to rename the MP3 tracks? [y/n]: ";
	read opc;
	if [ "$opc" = "y" ]
	then
		RenameMP3ListTracks;
	fi
	PressAnyKey;
	return;
}


#******************************************************************************

MP3toWAV () {
	while true;
	do
		clear ;
		echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
		echo "CDDOIT: Convert MP3 files to WAV format" ;
		echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
		GetDirWavTracks;
		if [ "$?" = "1" ]
		then
			return 1;
		fi
		DirDest=$PWD;
		GoToDir;
		if [ "$?" = "1" ]
		then
			return 1;
		fi
		while true;
		do
			echo " " ;
			echo " " ;
			echo -n "Select the file [*: All, 0: Exit]: " ;
			read archvmp3;
			if [ "$archvmp3" = "0" ] || [ "$archvmp3" = "" ]
			then
				return;
			fi
			echo "" ;
			echo "" ;
			echo -n "Do you wish to remove the original MP3 files after the conversion? [y/n]: ";
			read opc;
			echo " " ;
			echo " " ;
			if [ "$archvmp3" = "*" ]
			then
				for archv in *.mp3;
				do
					mpg123 -s -r 44100 "$archv" > "$DirDest/$archv.raw" ;
					sox -t raw -r 44100 -c 2 -w -s "$DirDest/$archv.raw"  -r 44100 -c 2 -t wav -w -s "$DirDest/$archv.wav" ;
					rm -f "$DirDest/$archv.raw" ;
					if [ "$opc" = "y" ]
					then
						rm -f "$archv" ; # delete the MP3 file
					fi
				done ;
			else
				if [ -f "$archvmp3.wav" ]
				then
					Beep;
					echo -n "WARNING: ";
					echo -n "$archvmp3";
					echo " was converted before.";
					PressAnyKey;
				else
					if [ ! -f "$archvmp3" ]
					then
						Beep;
						echo "ERROR: File not found.";
						PressAnyKey;
					else
						mpg123 -s -r 44100 "$archvmp3" > "$DirDest/$archvmp3.raw" ;
						sox -t raw -r 44100 -c 2 -w -s "$DirDest/$archvmp3.raw"  -r 44100 -c 2 -t wav -w -s "$DirDest/$archvmp3.wav" ;
						rm -f "$DirDest/$archvmp3.raw" ;
						if [ "$opc" = "y" ]
						then
							rm -f "$archvmp3" ; # delete the MP3 file
						fi
					fi
				fi
			fi
			echo " " ;
			echo " " ;
			echo "Conversin finished." ;
			GetSizeInMB "$DirDest";
			Beep;
			PressAnyKey;
			clear ;
			echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
			echo "CDDOIT: Convert MP3 files to WAV format" ;
			echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
			echo " " ;
			echo " " ;
			echo "Select again? -The source and target directories will not changed-" ;
			echo " " ;
			ls -Cm --color;
		done
	done
	echo " " ;
	echo " " ;
	echo -n "The WAV files are found in: " ;
	echo "$DirDest";
	PressAnyKey;
	return;
}

#******************************************************************************

ConvertCdrCopyFormat () {
	clear;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "CDDOIT: Convert audio file formats to CD-R copy file format" ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo " " ;
	echo " " ;
	echo "The CD-R copy format is:" ;
	echo "WAV format, 16 bits, Stereo & 44.100 Hz" ;
	echo " " ;
	echo " WARNING:" ;
	echo "  *****   In big files this action is going to take a long time." ;
	echo " ** | **  Some audio formats are not compatible in some conversions." ;
	echo " ** 0 **  The final quality sound from poor quality formats maybe" ;
	echo "  *****   not good." ;
	GoToDir;
	if [ "$?" = "1" ]
	then
		return 1;
	fi
	echo " " ;
	echo " " ;
	echo -n "Select the file [0: Exit]: " ;
	read archv;
	if [ "$archv" = "0" ] || [ "$archv" = "" ]
	then
		return;
	fi
	clear;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "CDDOIT: Convert audio file formats to CD-R copy file format" ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo " " ;
	echo " " ;
	echo "ENTER THE AUDIO PARAMETERS OF THE ORIGINAL AUDIO FILE:" ;
	echo "====================================================== " ;
	echo " " ;
	echo " " ;
	echo "\
1. Enter the audio format of the original audio file.

The formats supported are:

       8svx     Amiga 8SVX musical instrument description.
       aiff     AIFF  files  used  on  Apple  IIc/IIgs  and SGI.
       au       SUN Microsystems AU files.
       avr      Audio Visual Research
       cdr      CD-R.
       cvs      Continuously Variable Slope Delta modulation.
       dat      Text Data files.
       gsm      GSM 06.10 Lossy Speech Compression.
       hcom     Macintosh  HCOM  files.
       maud     An Amiga format.
       ossdsp   OSS /dev/dsp device driver.
       sf       IRCAM Sound Files.
       sph      SPHERE  (SPeech HEader Resources)
       smp      Turtle Beach SampleVision files.
       snd      Under DOS same as the sndt format
                Under all other platforms it is
                the same as the .au format.
       sndt     SoundTool files. Older DOS file format.
       sunau    Sun /dev/audio device driver.
       txw      Yamaha TX-16W sampler.
       vms      Used to compress speech audio such as voice mail.
       voc      Sound Blaster VOC files.
       wav      Microsoft .WAV RIFF files.
       wve      Psion 8-bit alaw.
       raw      Raw files (no header).
       ub, sb, uw, sw, ul, al, sl
                These  are  several  suffices  which  serve as a
                shorthand for raw files with a  given  size  and
                style.   Thus, ub, sb, uw, sw, and ul correspond
                to 'unsigned  byte',  'signed  byte', 'unsigned
                word',  'signed  word', 'ulaw' (byte),"alaw" (byte),
                and "signed  long".
       auto     This is a ``meta-type'' format.
";
	echo "-You can select & paste-";
	echo -n "Enter audio format [0: Exit]: " ;
	read format;
	if [ "$format" = "0" ] || [ "$format" = "" ]
	then
		return;
	fi
	clear;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "CDDOIT: Convert audio file formats to CD-R copy file format" ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo " " ;
	echo " " ;
	echo -n "2. Enter the original sample rate (E.g: 44101 or 8000) [0: Exit]: " ;
	read rate;
	if [ "$rate" = "0" ] || [ "$rate" = "" ]
	then
		return;
	fi
	clear;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "CDDOIT: Convert audio file formats to CD-R copy file format" ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo " " ;
	echo " " ;
	echo "\
3. Enter the bits resolution of the original audio file.

The bits resolution supported types are:

	b : 8-bit  bytes.
	w : 16-bit words.
	l : 32-bit long words.
	f : 32-bit floats.
	d : 64-bit double floats.
	D : 80-bit IEEE floats.
	    [Floats and double floats are in native machine format]

";
	echo "-You can select & paste-";
	echo -n "Bits resolution [0: Exit]: " ;
	read bits;
	if [ "$bits" = "0" ] || [ "$bits" = "" ]
	then
		return;
	fi
	clear;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "CDDOIT: Convert audio file formats to CD-R copy file format" ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo " " ;
	echo " " ;
	echo "\
4. Enter the audio channels of the original audio file.

The most common number of audio channels are:

	1: Mono.
	2: Stereo.
	4: Four audio channels.
";
	echo -n "Audio channels [0: Exit]: " ;
	read channel;
	if [ "$channel" = "0" ] || [ "$channel" = "" ]
	then
		return;
	fi
	clear;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "CDDOIT: Convert audio file formats to CD-R copy file format" ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "" ;
	echo "" ;
	echo -n "Press ENTER to convert to WAV format, 16 bits, Stereo & 44.100 Hz." ;
	read;
	echo "" ;
	echo "" ;
	echo -n "Converting the file: " ;
	echo "$archv";
	echo " " ;
	echo "WARNING: In big files this action is going to take a long time." ;
	echo "" ;
	sox -V -t $format -r $rate -c $channel -$bits -s "$archv" -t wav -r 44100 -c 2 -w -s "$archv".cdformat.wav;
	Beep;
	echo "";
	echo -n "The file is found in: " ;
	pwd;
	GetSizeInMB;
	echo "";
	echo "";
	echo -n "Do you wish to delete the original file? y/n: ";
	read opc;
	if [ "$opc" = "y" ]
	then
		echo "";
		rm -fv "$archv";
	fi
	PressAnyKey;
	return ;
}

#******************************************************************************

Scanbus () {
	clear;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "CDDOIT: View SCSI devices for CDRECORD" ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "" ;
	echo "" ;
	echo "The operation must be performed under ROOT. Enter the password.";
	su -c 'cdrecord -scanbus' root;
	PressAnyKey;
	return;
}

#******************************************************************************

ViewAllDir () {
	cd "$HOME/cddoit";
	clear;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "CDDOIT: View contents of all CDDOIT directories" ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "" ;
	echo "" ;
	echo "Press 'q' to stop." ;
	echo "" ;
	echo "____________________________________________________________________________" ;
	pwd;
	echo "" ;
	ls -Rhlm |more;
	PressAnyKey;
	return ;
}

#******************************************************************************

FreeSizeHD () {
	clear;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "CDDOIT: View free space in Hard Disks" ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "" ;
	echo "" ;
	echo "Free space:" ;
	echo " " ;
	df -hT;
	PressAnyKey;
	return ;
}

#******************************************************************************

InfoAudioCd () {
	clear;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "CDDOIT: View Audio-CD information" ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	GetOriginalCD;
	cdparanoia -Q;
	echo "" ;
	echo "" ;
	echo -n "Do you wish save this information in a file? [y/n]: " ;
	read save;
	if [ "$save" = "y" ]
	then
		echo "" ;
		echo -n "Enter file name: " ;
		read file;
		cdparanoia -Q 2> "$file"-cdinfo.txt;
		echo "" ;
		echo "" ;
		echo -n "$file-cdinfo.txt was saved in ";
		pwd;
	fi
	PressAnyKey;
	return ;
}

#******************************************************************************

ViewSizeDir () {
	clear;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "CDDOIT: View size of a directory [in MB]" ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "" ;
	echo "       |-----------------------------------------|" ;
	echo "       | WAV size <===> audio time relationship: |" ;
	echo "       |                                         |" ;
	echo "       |    8.75 MB  <===>  1 Minute             |" ;
	echo "       |    650 MB   <===>  74 Minutes           |" ;
	echo "       |    700 MB   <===>  80 Minutes           |" ;
	echo "       |-----------------------------------------|" ;
	GoToDir;
	if [ "$?" = "1" ]
	then
		return 1;
	fi
	PressAnyKey;
	return ;
}

#******************************************************************************

AudioDataCD () {
	clear ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	if [ "${1}" = "1" ]	# real copy (no dummy)
	then
		echo "CDDOIT: Audio+Data CD copy" ;
	else
		echo "CDDOIT: Audio+Data CD DUMMY copy" ;
	fi	
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "";
	echo "";
	echo "WARNING: In Audio+Data CD, the data will be stored in the first track";
	echo "         of the CD-R and the next tracks will be the audio tracks.";
	echo "         You can't hear the track n 1, is silence.";
	GoToDir;
	if [ "$?" = "1" ]
	then
		return 1;
	fi
	if [ ! -f image.raw ]
	then
		Beep;
		echo "";
		echo "";
		echo "ERROR: Data image file (image.raw) not found!";
		echo "       Create it before! (see main menu, option 5)";
	else
		GetCDRecordable;
		while true;
		do
			if [ "${1}" = "1" ]	# real copy (no dummy)
			then
				CopyCD 10;
			else
				CopyCD 11;
			fi	
			if [ "$?" = "1" ] # CopyCD error (possible SU error)
			then
				echo "";
				echo "ERROR. CD-Copy could not be started.";
				echo "       Possible incorrect ROOT password.";
				Beep;
				echo "";
				echo -n "Re-enter the password again? [y/n]: ";
				read opc;
				if [ "$opc" != "y" ]
				then
					break;
				fi
			else
				break;
			fi
		done
	fi
	PressAnyKey;
	return 0;
}

#******************************************************************************

AboutCDDOIT () {
clear;
echo "\
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
About CDDOIT
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

Version 1.3
Written by Jose L. Diaz.
February/2002

Homepage: http://www.geocities.com/cddoit/index.html

This is free software.
Only, I would like to know in many countries of the world CDDOIT is being
used, for that reason would be thankful to you that you sent me a mail
(cddoit@yahoo.com) indicating only your country and city.
Thanks in advance.

I am from Madrid, Spain.

Report bugs or suggestions to: cddoit@yahoo.com
This software comes with NO warranty of any kind. Use at your own risk.";

PressAnyKey;
return;
}

#******************************************************************************

MountDataImage () {
	clear;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "CDDOIT: View data image content" ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	if [ -b /dev/loop0 ]
	then
		GoToDir;
		if [ "$?" = "1" ]
		then
			return 1;
		fi
		echo "" ;
		echo "" ;
		if [ ! -f image.raw ]
		then
			echo "WARNING: Data image file 'image.raw' not found!";
			Beep;
		else
			echo "WARNING: You can view ONLY no-multisession data image files." ;
			echo "         In multisession data images this option fail." ;
			echo "         In this case press ENTER to exit." ;
			echo "" ;
			echo "This operation must be performed under ROOT. Enter the password.";
			su -c 'mount image.raw -r -v -t iso9660 -o loop /mnt ; ls -lChR /mnt | more ; umount /mnt';
		fi
	else
		Beep;
		echo "ERROR: The LOOP device [/dev/loop0] not exist.";
		echo "       To create it go to menu OTHERS, option n 9.";
	fi
	PressAnyKey;
	return;
}

#******************************************************************************

CreateLoopDev () {
	clear;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "CDDOIT: Create a LOOP device" ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "" ;
	echo "" ;
	if [ -b /dev/loop0 ]
	then
		Beep;
		echo "WARNING: The LOOP device [/dev/loop0] is already created!";
	else
		echo -n "Create the /dev/loop0 device? y/n : ";
		read opc;
		if [ "$opc" = "y" ]
		then
			echo "" ;
			echo "This operation must be performed under ROOT. Enter the password.";
			su -c 'mknod /dev/loop0 b 7 0';
		fi
	fi
	PressAnyKey;
	return;
}

#******************************************************************************

ConfCdrecord () {
	clear;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "CDDOIT: Modify CDRECORD configuration file [/etc/cdrecord.conf]" ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "" ;
	echo "" ;
	if [ ! -f /etc/cdrecord.conf ]
	then
		if [ ! -f /usr/bin/cdrecord ]
		then
			Beep;
			echo "WARNING: CDRECORD is not installed in your system!";
			echo "         Please, install it.";
			PressAnyKey;
			return;
		fi
	fi
	echo "You must enter the values of your CR-R Recorder, maximum speed," ;
	echo "recording and buffer, if you know it. Otherwise enter e.g. values." ;
	echo "" ;
	echo "This operation must be performed under ROOT. Enter the password.";
	su -c '
echo "" ;
echo "Getting SCSI CD-Recorder devices for CDRECORD...";
echo "" ;
cdrecord -scanbus;
echo "" ;
echo -n "Enter the CD-R Recorder device view above [X,Y,Z], e.g. 0,1,0: ";
read device;
echo "" ;
echo -n "Enter the default speed copy, e.g. 2: ";
read speed;
echo "" ;
echo -n "Enter the fifo size [Default enter 4m]: ";
read fifosize;
echo "" ;
echo "" ;
echo -e "\a";
echo -n "Modify the /etc/cdrecord.conf file. Are you sure? y/n : ";
read opc;
if [ "$opc" = "y" ]
then
	mv /etc/cdrecord.conf /etc/cdrecord.conf.old ;
	echo "\
#ident @(#)cdrecord.dfl	Copyr. J. Schilling
#
# This file is /etc/cdrecord.conf
# It contains defaults that are used if no command line option
# or environment is present.
# 
# The default device, if not specified elswhere
#
CDR_DEVICE=$device
# 
# The default speed, if not specified elswhere
#
CDR_SPEED=$speed

# 
# The default FIFO size if, not specified elswhere
#
CDR_FIFOSIZE=$fifosize

#
# The following definitions allow abstract device names.
# They are used if the device name does not contain the
# the characters ',', ':', '/' and '@'
#
# drive name	device	speed	fifosize driveropts
#
# teac=		1,3,0	-1	-1	""
# panasonic=	1,4,0	-1	-1	""
# plextor=	1,4,0	12	-1	""
# sanyo=	1,4,0	12	-1	burnproof
# yamaha=	1,5,0	-1	-1	""
# cdrom=	0,6,0	2	1m	""
#
#***********************************
# This file was created by CDDOIT
#***********************************
" > /etc/cdrecord.conf ;
		echo "" ;
		echo "/etc/cdrecord.conf was changed.";
		echo "The original file was saved to /etc/cdrecord.conf.old";
else
	echo "" ;
	echo "/etc/cdrecord.conf NOT changed.";
	
fi';
	PressAnyKey;
	return;
}

#******************************************************************************
	
MultiAudio () {
	clear;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	if [ "${1}" = "12" ]	# real copy (no dummy)
	then
		echo "CDDOIT: Multisession audio CD-R copy" ;
	else
		echo "CDDOIT: Multisession audio CD-R DUMMY copy" ;
	fi	
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	GoToDir;
	if [ "$?" = "1" ]
	then
		return 1;
	fi
	track=1;
	while true;
	do
		echo " " ;
		echo -n "Select the file [0: Exit]: " ;
		read archwav;
		if [ "$archwav" = "0" ] || [ "$archwav" = "" ]
		then
			return;
		fi
		export archwav;
		echo " " ;
		echo -n "Enter speed of copy (INTRO, Default speed): " ;
		read speed;
		export speed;
		while true;
		do
			CopyCD ${1};
			if [ "$?" = "1" ] # CopyCD error (possible SU error)
			then
				echo "";
				echo "ERROR. CD-Copy could not be started.";
				echo "       Possible incorrect ROOT password.";
				Beep;
				echo "";
				echo -n "Re-enter the password again? [y/n]: ";
				read opc;
				if [ "$opc" != "y" ]
				then
					break;
				fi
			else
				break;
			fi
		done
		Beep;
		echo " " ;
		echo " " ;
		echo -n "Select new file? [y/n]: ";
		read opc;
		if [ "$opc" = "y" ]
		then
			if [ -f "$PWD"/cdtracklist.txt ]
			then
				rm -f "$PWD"/cdtracklist.txt;
			fi
			echo $track."$archwav" >> "$PWD"/cdtracklist.txt;
			track=`expr ${track} + 1`;
			echo "";
			echo "The audio files:";
			echo "";
			ls -Cm --color *;
			echo "";
			echo "Insert again the CD-R and select the audio file.";
		else
			track=`expr ${track} + 1`;
			echo $track."$archwav" >> "$PWD"/cdtracklist.txt;
			echo "The tracks written to CD-R in this last session are:";
			echo "";
			cat "$PWD"/cdtracklist.txt;
			echo "";
			echo "";
			echo -n "Also, the track list are in the file: ";
			echo "$PWD"/cdtracklist.txt;
			break;
		fi
	done
	echo "";
	echo "REMEMBER: Before listen your CD-R you must to close it.";
	echo "          See menu AUDIO CD-R, option n 9.";
	PressAnyKey;
	return;
}

#******************************************************************************

CloseMultiAudio () {
	clear;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "CDDOIT: Close multisession audio CD-R" ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	GetOriginalCD;
	echo "";
	echo "";
	echo "This operation must be performed under ROOT. Enter the password.";
	su -c 'cdrecord -v -eject -fix; echo ""; echo "The audio CD is closed."';
	Beep;
	PressAnyKey;
	return;
}




#******************************************************************************
# MAIN MENU FUNCTIONS ---------------------------------
#******************************************************************************

menuaudiocd () {
while true;
do
	clear;
	echo "========================================================================";
	echo "::: CDDOIT :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "========================================================================";
	echo "";
	echo "::: AUDIO CD-R :::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "";
	echo "    1. Direct Audio CD copy to CD-R (Get WAV files and copy)";
	echo "    2. Direct Audio CD DUMMY copy to CD-R";
	echo "    3. WAV files to CD-R copy";
	echo "    4. MP3 files to CD-R copy";
	echo "    5. WAV files to CD-R DUMMY copy";
	echo "    6. MP3 files to CD-R DUMMY copy";
	echo "    7. Multisession audio CD-R copy";
	echo "    8. Multisession audio CD-R DUMMY copy";
	echo "    9. Close a multisession audio CD-R";
	echo "";
	echo "    0. Back to main menu";
	echo "";
	echo -n "Choose option: ";
	read opc;
	case $opc in
		"") break;;
		0) break;;
		1) AudioDirectCopy 1;;
		2) AudioDirectCopy 2;; # dummy
		3) AudioCopy 1;;
		4) MP3toCD 1;;
		5) AudioCopy 4;;	# dummy
		6) MP3toCD 4;;	# dummy
		7) MultiAudio 12;;
		8) MultiAudio 13;; #dummy
		9) CloseMultiAudio;;
	esac;
done
}

#******************************************************************************

menudatacd () {
while true;
do
	clear;
	echo "========================================================================";
	echo "::: CDDOIT :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "========================================================================";
	echo "";
	echo "::: DATA CD-R ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "";
	echo "    1. Data-CD direct copy to CD-R (Get data image file and copy)";
	echo "    2. Data-CD direct dummy copy to CD-R";
	echo "    3. On-the-fly Data-CD copy to CD-R";
	echo "    4. On-the-fly Data-CD dummy copy to CD-R";
	echo "    5. Copy data image file to CD-R";
	echo "    6. Dummy copy data image file to CD-R";
	echo "";
	echo "    0. Back to main menu";
	echo "";
	echo -n "Choose option: ";
	read opc;
	case $opc in
		"") break;;
		0) break;;
		1) DataDirectCopy 1;;
		2) DataDirectCopy 2;;  # dummy
		3) OntheflyDataCopy 1;;
		4) OntheflyDataCopy 2;;  # dummy
		5) Image2cd 1;;
		6) Image2cd 2;;  # dummy
	esac;
done
}

#******************************************************************************

menumixcd () {
while true;
do
	clear;
	echo "========================================================================";
	echo "::: CDDOIT :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "========================================================================";
	echo "";
	echo "::: AUDIO + DATA CD-R ::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "";
	echo "    1. Audio+Data CD copy";
	echo "    2. Audio+Data CD DUMMY copy";
	echo "";
	echo "    0. Back to main menu";
	echo "";
	echo -n "Choose option: ";
	read opc;
	case $opc in
		"") break;;
		0) break;;
		1) AudioDataCD 1;;
		2) AudioDataCD 2;;
	esac;
done
}

#******************************************************************************

menuaudioconversionprog () {
while true;
do
	clear;
	echo "========================================================================";
	echo "::: CDDOIT :: AUDIO ::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "========================================================================";
	echo "";
	echo "::: Audio conversion programs :::::::::::::::::::::::::::::::::::::::::::";
	echo "";
	echo "    1. Program an audio conversion";
	echo "    2. Delete an audio conversion program";
	echo "    3. View audio conversion programs";
	echo "    4. Cancel an audio conversion program already started";
	echo "";
	echo "    0. Back to main menu";
	echo "";
	echo -n "Choose option: ";
	read opc;
	case $opc in
		"") break;;
		0) break;;
		1) ConvertBetweenFormats 2;;
		2) DelProgramRecord 2;;
		3) ViewProgramRecords 2;;
		4) CancelProgramRecordStarted;;
	esac;
done
}


#******************************************************************************

menuaudio5 () {
while true;
do
	clear;
	echo "========================================================================";
	echo "::: CDDOIT :: AUDIO ::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "========================================================================";
	echo "";
	echo "::: Audio recording programs :::::::::::::::::::::::::::::::::::::::::::";
	echo "";
	echo "    1. Program an audio recording";
	echo "    2. Delete an audio recording program";
	echo "    3. View audio recording programs";
	echo "    4. Cancel an audio recording program already started";
	echo "    5. Sleeptimer recording";
	echo "";
	echo "    0. Back to main menu";
	echo "";
	echo -n "Choose option: ";
	read opc;
	case $opc in
		"") break;;
		0) break;;
		1) ProgramRecord;;
		2) DelProgramRecord;;
		3) ViewProgramRecords;;
		4) CancelProgramRecordStarted;;
		5) SleepTimerRecord;;
	esac;
done
}


#******************************************************************************

menuaudio4 () {
while true;
do
	clear;
	echo "========================================================================";
	echo "::: CDDOIT :: AUDIO ::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "========================================================================";
	echo "";
	echo "::: Audio conversions ::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "";
	echo "    1. Convert MP3 files to WAV format";
	echo "    2. Convert WAV files to MP3 format";
	echo "    3. Convert 44.101 Hz to 44.000 Hz rate in WAV files";
	echo "    4. Convert audio file formats to CD-R copy file format";
	echo "    5. Convert between audio file formats";
	echo "    6. Audio conversion programs";
	echo "";
	echo "    0. Back to main menu";
	echo "";
	echo -n "Choose option: ";
	read opc;
	case $opc in
		"") break;;
		0) break;;
		1) MP3toWAV;;
		2) WAVtoMP3;;
		3) Convert44101to44100;;
		4) ConvertCdrCopyFormat;;
		5) ConvertBetweenFormats 1;;
		6) menuaudioconversionprog;;
	esac;
done
}


#******************************************************************************

menuaudio3 () {
while true;
do
	clear;
	echo "========================================================================";
	echo "::: CDDOIT :: AUDIO ::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "========================================================================";
	echo "";
	echo "::: Play audio files :::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "";
	echo "    1. Play WAV files";
	echo "    2. Play MP3 files";
	echo "    3. Play many audio files";
	echo "";
	echo "    0. Back to main menu";
	echo "";
	echo -n "Choose option: ";
	read opc;
	case $opc in
		"") break;;
		0) break;;
		1) PlayWAV;;
		2) PlayMP3;;
		3) PlayManyFormats;;
	esac;
done
}


#******************************************************************************

menuaudio2 () {
while true;
do
	clear;
	echo "========================================================================";
	echo "::: CDDOIT :: AUDIO ::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "========================================================================";
	echo "";
	echo "::: Record audio :::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "";
	echo "    1. Record audio in WAV format [CD copy format]";
	echo "    2. Record audio in WAV format [44.101 Hz]";
	echo "    3. Record audio in specific formats";
	echo "    4. Audio recording programs";
	echo "";
	echo "    0. Back to main menu";
	echo "";
	echo -n "Choose option: ";
	read opc;
	case $opc in
		"") break;;
		0) break;;
		1) AudioRecord 1;;
		2) AudioRecord 2;;
		3) AudioRecordSpecificFormat;;
		4) menuaudio5;;
	esac;
done
}


#******************************************************************************

menuaudio1 () {
while true;
do
	clear;
	echo "========================================================================";
	echo "::: CDDOIT :: AUDIO ::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "========================================================================";
	echo "";
	echo "::: Get audio files from Audio-CD ::::::::::::::::::::::::::::::::::::::";
	echo "";
	echo "    1. Get WAV files from Audio-CD";
	echo "    2. Get MP3 files from Audio-CD";
	echo "    3. Get WAV files from several Audio-CD";
	echo "    4. Get MP3 files from several Audio-CD";
	echo "    5. Get the whole Audio-CD in a single audio file";
	echo "    6. Get RAW files from Audio-CD";
	echo "    7. Get AIFF files from Audio-CD";
	echo "";
	echo "    0. Back to main menu";
	echo "";
	echo -n "Choose option: ";
	read opc;
	case $opc in
		"") break;;
		0) break;;
		1) GetWAVfromCD;;
		2) GetMP3fromCD;;
		3) GetWAVfromSeveralCD;;
		4) GetMP3fromSeveralCD;;
		5) GetWholeCDSingleFile;;
		6) GetRAWfromCD;;
		7) GetAIFFfromCD;;
	esac;
done
}

#******************************************************************************

menuaudio () {
while true;
do
	clear;
	echo "========================================================================";
	echo "::: CDDOIT :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "========================================================================";
	echo "";
	echo "::: AUDIO ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "";
	echo "    1. Get audio files from Audio-CD";
	echo "    2. Record audio";
	echo "    3. Play audio files";
	echo "    4. Audio conversions";
	echo "";
	echo "    0. Back to main menu";
	echo "";
	echo -n "Choose option: ";
	read opc;
	case $opc in
		"") break;;
		0) break;;
		1) menuaudio1;;
		2) menuaudio2;;
		3) menuaudio3;;
		4) menuaudio4;;
	esac;
done
}

#******************************************************************************

menuothers () {
while true;
do
	clear;
	echo "========================================================================";
	echo "::: CDDOIT :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "========================================================================";
	echo "";
	echo "::: OTHERS :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "";
	echo "    1. View contents of all CDDOIT directories";
	echo "    2. View size of a directory in MB";
	echo "    3. View SCSI devices for CDRECORD";
	echo "    4. Delete a CDDOIT directory";
	echo "    5. Delete files of CDDOIT temporary directories [AUDIOCD & DATACD]";
	echo "    6. Delete ALL CDDOIT directories";
	echo "    7. View free space in Hard Disks";
	echo "    8. View Audio-CD information";
	echo "    9. Create a LOOP device";
	echo "   10. Modify CDRECORD configuration file [cdrecord.conf]";
	echo "   11. Rename the MP3 file names in a directory";
	echo "   12. Multimedia kernel modules manager";
	echo "";
	echo "    0. Back to main menu";
	echo "";
	echo -n "Choose option: ";
	read opc;
	case $opc in
		"") break;;
		0) break;;
		1) ViewAllDir;;
		2) ViewSizeDir;;
		3) Scanbus;;
		4) DelDir;;
		5) DelTemp;;
		6) DelAll;;
		7) FreeSizeHD;;
		8) InfoAudioCd;;
		9) CreateLoopDev;;
		10) ConfCdrecord;;
		11) RenameMP3ListTracks;;
		12) ModulesManager;;
	esac;
done
}

#******************************************************************************

menudata () {
while true;
do
	clear;
	echo "========================================================================";
	echo "::: CDDOIT :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "========================================================================";
	echo "";
	echo "::: DATA :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "";
	echo "    1. Get data image file";
	echo "    2. Get data image for Multisession copy";
	echo "    3. Mount/View data image";
	echo "";
	echo "    0. Back to main menu";
	echo "";
	echo -n "Choose option: ";
	read opc;
	case $opc in
		"") break;;
		0) break;;
		1) GetImage 1;;
		2) GetImage 2;;
		3) MountDataImage;;
	esac;
done
}


#******************************************************************************
# MAIN MENU ------------------------------
#******************************************************************************

CreateDirByDefault;
while true;
do
	clear;
	echo "=======================================================================";
	echo "::: CDDOIT :::::::::::::::::::::::::::::::::::::::::::: By Jose L. Diaz";
	echo "=======================================================================";
	echo "    CD Creation & Sound                                    Version: 1.3";
	echo "";
	echo "";
	echo "";
	echo "    1. Audio CD-R";
	echo "    2. Data CD-R";
	echo "    3. Audio+Data CD-R";
	echo "    4. Audio";
	echo "    5. Data" ;
	echo "    6. Others";
	echo "    7. About CDDOIT" ;
	echo "" ;
	echo "    0. Exit CDDOIT" ;
	echo "" ;
	echo "" ;
	echo -n "Choose option: ";
	read opc;
	case $opc in
		0) clear; exit 0;;
		1) menuaudiocd;;
		2) menudatacd;;
		3) menumixcd;;
		4) menuaudio;;
		5) menudata;;
		6) menuothers;;
		7) AboutCDDOIT;;
	esac;
done