GRUB

From ThorxWiki
(Difference between revisions)
Jump to: navigation, search
m (.)
m (updated script)
Line 31: Line 31:
   
 
<pre>
 
<pre>
#!/bin/bash
+
#!/bin/bash
   
if [ $# -lt 3 ]; then
+
if [ $# -lt 3 ]; then
echo "Usage: $0 tempo freq dur [freq dur freq dur...]" >&2
+
echo "Usage: $0 tempo freq dur [freq dur freq dur...]" >&2
exit 1
+
exit 1
fi
+
fi
   
tempo=$1; shift
+
tempo=$1; shift
   
while [ -n "$*" ]; do
+
while [ -n "$*" ]; do
freq=$1; shift
+
freq=$1; shift
[ $freq -eq 0 ] && freq=1 # beep will fail if $freq is 0
+
[ $freq -eq 0 ] && freq=1 # beep will fail if $freq is 0
dur=$1; shift
+
dur=$1; shift
dur=$((120000*$dur/$tempo))
+
dur=$((60000*$dur/$tempo))
# ie, 2 * 60 (bpm) * 1000 (for milliseconds) * duration / tempo
+
# ie, 60 (bpm) * 1000 (for milliseconds) * duration / tempo
# No, I don't know why that 2* has to be there initially, but it makes it sound right to beep on my laptop at least :)
+
# Note: on one of my systems, i had to double it (ie, 12000*). I don't
BEEPOPTS="$BEEPOPTS $NEXT -f $freq -l $dur"
+
# know why, but it makes some of the tunes I've collected sound right.
NEXT="-n"
+
# (note: I have not tested all tunes in GRUB)
done
+
#
  +
# You can generate a single beep command here, but I prefer to step it
  +
# out since [a] sounds slightly closer to GRUB implementation
  +
# and [b] easier to debug an off-note
  +
# BEEPOPTS="$BEEPOPTS $NEXT -f
  +
# $freq -l $dur"
  +
# NEXT="-n"
  +
echo "beep -f $freq -l $dur"
  +
beep -f $freq -l $dur
  +
done
   
beep $BEEPOPTS
+
#echo "playing beep $BEEPOPTS"
  +
  +
#beep $BEEPOPTS
 
</pre>
 
</pre>

Revision as of 12:39, 22 May 2012

Some GRUB_INIT_TUNE themes I've found online in various places... this is a fragment from my debian:/etc/default/grub file

# Uncomment to get a beep at grub start
# The format unless a file is named is: "tempo [pitch1 duration1] [pitch2 duration2] ..."
# Warning: The menu will not be displayed until the tone is finished

#GRUB_INIT_TUNE="480 440 1"

# Close Encounters/5 Tone:
#GRUB_INIT_TUNE="480 900 2 1000 2 800 2 400 2 600 3"

# Fur Elise (note long):
#GRUB_INIT_TUNE="480 420 1 400 1 420 1 400 1 420 1 315 1 370 1 335 1 282 3 180 1 215 1 282 1 315 3 213 1 262 1 315 1 335 3 213 1 420 1 400 1 420 1 400 1 420 1 315 1 370 1 335 1 282 3 180 1 215 1 282 1 315 3 213 1 330 1 315 1 282 3"

# Super Mario
#GRUB_INIT_TUNE="1000 334 1 334 1 0 1 334 1 0 1 261 1 334 1 0 1 392 2 0 4 196 2"

# Star Wars Imperial Death March:
#GRUB_INIT_TUNE="480 440 4 440 4 440 4 349 3 523 1 440 4 349 3 523 1 440 8 659 4 659 4 659 4 698 3 523 1 415 4 349 3 523 1 440 8"

# Wolfenstein 3D
GRUB_INIT_TUNE="300 131 1 196 1 196 1 196 1 294 1 196 1 294 1 196 1 131 1"


This tip which converts a GRUB_INIT_TUNE to a audio file which sox will play through the soundcard... http://ubuntuforums.org/showthread.php?t=1739495

Based on this script, I've concoted the following, which converts a GRUB_INIT_TUNE into a beep(1) command, to play it through the PC speaker - as grub intended.

 #!/bin/bash

 if [ $# -lt 3 ]; then
     echo "Usage: $0 tempo freq dur [freq dur freq dur...]" >&2
     exit 1
 fi

 tempo=$1; shift

 while [ -n "$*" ]; do
     freq=$1; shift
     [ $freq -eq 0 ] && freq=1  # beep will fail if $freq is 0
     dur=$1;  shift
     dur=$((60000*$dur/$tempo))
     # ie, 60 (bpm) * 1000 (for milliseconds) * duration / tempo
     # Note: on one of my systems, i had to double it (ie, 12000*). I don't
     # know why, but it makes some of the tunes I've collected sound right.
     # (note: I have not tested all tunes in GRUB)
     #
     # You can generate a single beep command here, but I prefer to step it
     # out since [a] sounds slightly closer to GRUB implementation
     # and [b] easier to debug an off-note
     # BEEPOPTS="$BEEPOPTS $NEXT -f
     # $freq -l $dur"
#     NEXT="-n"
     echo "beep -f $freq -l $dur"
     beep -f $freq -l $dur
 done

#echo "playing beep $BEEPOPTS"

#beep $BEEPOPTS
Personal tools
Namespaces

Variants
Actions
Navigation
meta navigation
More thorx
Tools