Added support for ALSA on suggestion from user jobbautista9

This commit is contained in:
Daniel Suni 2020-10-24 16:34:08 +03:00
parent 6d685d9c4c
commit 4c563a1db0
2 changed files with 27 additions and 12 deletions

View File

@ -1,7 +1,7 @@
#!/bin/bash
# Bashtris v1.0 (July 26, 2012), a puzzle game for the command line.
# Copyright (C) 2012 Daniel Suni
# Bashtris v1.1 (October 24, 2020), a puzzle game for the command line.
# Copyright (C) 2012, 2020 Daniel Suni
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@ -735,17 +735,23 @@ fi
# Start the music if possible
music=""
if [ ! -c /dev/dsp ] ; then
echo "WARNING: The device /dev/dsp does not exist, or is not a valid character device." >&2
echo " Music will be disabled. Press any key to continue." >&2
read -s n1
elif [ ! -x ./$MUSIC ] ; then
if [ ! -x ./$MUSIC ] ; then
echo "WARNING: Music file not found, or has insufficient permissions. Music will be disabled." >&2
echo " Press any key to continue." >&2
read -s n1
else
elif which aplay &>/dev/null ; then
( ./$MUSIC ) &
music=$!
elif [ -c /dev/dsp ] ; then
( ./$MUSIC /dev/dsp ) &
music=$!
elif [ -c /dev/dsp1 ] ; then
( ./$MUSIC /dev/dsp1 ) &
music=$!
else
echo "WARNING: Neither OSS nor ALSA is installed on your system. Music will be disabled." >&2
echo " Press any key to continue." >&2
read -s n1
fi
if [ ! -r ./$GRAPHICS ] ; then

View File

@ -1,7 +1,7 @@
#!/bin/bash
# Korobeiniki v1.0 (July 26, 2012), music for the bastris game.
# Copyright (C) 2012 Daniel Suni
# Korobeiniki v1.1 (October 24, 2020), music for the bashtris game.
# Copyright (C) 2012, 2020 Daniel Suni
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@ -16,6 +16,11 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# Playback method should be /dev/dsp -type OSS device. If no playback method
# is provided ALSA (aplay) is assumed.
# Thanks to Github user jobbautista9 for ALSA code suggestion
PLAYBACK_METHOD=$1
# /dev/dsp default = 8000 frames per second, 1 byte per frame
declare -r FPS=8000
declare -r VOLUME=$'\xc0' # Max volume = \xff
@ -107,7 +112,11 @@ cr_tune_b=`tune "$tune_b"`
trap 'exit 0' SIGUSR2
while true ; do
# Run echo command in a subshell to prevent the sound from going berserk when script exits.
# (This will cause the tune to play until finished, then stop even if script is killed.)
( echo -n "$cr_tune_a$cr_tune_a$cr_tune_b" > /dev/dsp ) &>/dev/null &
# (This may cause the tune to play until finished, then stop even if script is killed.)
if [ -z $PLAYBACK_METHOD ] ; then
( echo -n "$cr_tune_a$cr_tune_a$cr_tune_b" | aplay ) &>/dev/null &
else
( echo -n "$cr_tune_a$cr_tune_a$cr_tune_b" > $PLAYBACK_METHOD ) &>/dev/null &
fi
wait
done