Merge upstream commit 4c563a1db0

Original message:
Added support for ALSA on suggestion from user jobbautista9
This commit is contained in:
Job Bautista 2020-10-25 17:18:50 +08:00
commit 515a75be6a
2 changed files with 21 additions and 9 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
@ -739,9 +739,16 @@ 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
elif [ -e /dev/dsp ] || [ -e /usr/bin/aplay ] ; then
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

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,11 +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.)
if [ -e /dev/dsp ] ; then
( 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" | aplay ) &>/dev/null &
( echo -n "$cr_tune_a$cr_tune_a$cr_tune_b" > $PLAYBACK_METHOD ) &>/dev/null &
fi
wait
done