Uncategorized

speaker test

4

I found that you could load the sound drivers and stuff on Raspbian with:

sudo modprobe snd_bcm2835 && sudo amixer cset numid=3 1

The first command loads the sound driver module, the second I think sets the sound output to the 3.5mm socket.

You can then use alsamixer to adjust the volume, and speaker-test -c2 -t sine to test the speakers

You can also use the speaker-test util to produce different sounds, using -c1 for mono, c2 to switch between each channel of stereo, and -f to do different frequencies of noise – speaker-test --help gives alot more options:

speaker-test 1.0.25

Usage: speaker-test [OPTION]... 
-h,--help   help
-D,--device playback device
-r,--rate   stream rate in Hz
-c,--channels   count of channels in stream
-f,--frequency  sine wave frequency in Hz
-F,--format sample format
-b,--buffer ring buffer size in us
-p,--period period size in us
-P,--nperiods   number of periods
-t,--test   pink=use pink noise, sine=use sine wave, wav=WAV file
-l,--nloops specify number of loops to test, 0 = infinite
-s,--speaker    single speaker test. Values 1=Left, 2=right, etc
-w,--wavfile    Use the given WAV file as a test sound
-W,--wavdir Specify the directory containing WAV files

Recognized sample formats are: S8 S16_LE S16_BE FLOAT_LE S32_LE S32_BE

So to generate a 2 second beep, this worked fine:

speaker-test -c1 -t sine -f 800 -P 2 -p 0.4 -l 1

For a better beep, I generated a 0.25 second beep file in Audacity (Created new audio track, generated 440 Hz tone, amplified it by 11), then copied it onto my Pi – I could then play it with aplay beep.wav. This I then copied to ~/.local, and created this bash script at ~/.local/bin/beep (I ran mkdir ~/.local/bin first):

#!/bin/bash
aplay -q $HOME/.local/beep.wav
exit

I then created these lines in ~/.bash_profile:

# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi

PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games:/usr/games:$HOME/.local/bin:$HOME/bin

export PATH

and then I ran the following

chmod +x ~/.local/bin/beep
source ~/.bash_profile

and then I could simply run beep to make a beep noise

  • +1 for the paste and go code sample for a 2 seconds beep with speaker-test speaker-test -c1 -t sine -f 800 -P 2 -p 0.4 -l 1 – domih Sep 11 ’17 at 18:45

Categories: Uncategorized

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s