Thread Tools
Feb 13, 2013, 09:07 AM
---o-O-o---
blutoh's Avatar
Thread OP
Build Log

Making noise with the Raspberry Pi: custom boat sound effects system


EDIT: For a quick synopsis and the latest installation package, go directly to this post.

Making some noise.
Using Raspberry Pi for Sound Effects

Like some of you have mentioned, one of the features that I would like to have in my remote operations system is sound effects. I have used sound in model railroad applications and the realism it adds is simply astounding. I think starting with sound effects makes sense because making sound on the R Pi is relatively easy, it's it's low hanging fruit! So I started testing a foundation for a model sound effects system. I am utilizing Pygame, a Python language based open sourced game development framework. I am not using the entire framework, however. Within Pygame is a sound library that includes an 8 channel polyphonic mixer that will allow you to mix and play 8 sounds simultaneously and control volumes, fading, etc, and that's the piece I am using. If all this sounds complex, it's not. In fact, it is as easy as pie, or easy as Raspberry Pi to be specific. My goal is to make this a community project, which means anyone can participate in some way. We can all help in improving and enhancing the product, deciding the direction of the project, testing the product, etc., etc. In other words, we as a community develop the requirements and then develop the application. This is community development, better known as Open Source.

So don't be bashful, (yeah, like you guys have EVER been bashful!) jump right in, speak up and be heard.

What you need to participate in this project:
  • A sound mind (which leaves some of you out, sorry, but you know who you are )
  • A good idea of what you want the sound effects system to accomplish
  • A good idea of how it should be implemented (the user interface, more on this later)

What you need to develop code and test (details to follow):
  • A working Raspberry Pi with the Raspbian Wheezy Linux OS installed -OR- some other computer with both Python and Pygame installed
  • Knowledge of coding in the Python language (very straightforward)
  • A speaker or headphones. I use some old computer speakers
  • A text editor or IDE (not necessary for testing, only for code development)
Current project status:
A basic system that creates and mixes sound objects from sound files and allows you to play them from a menu. The initial purpose is to test the sound capabilities of the R Pi and the Pygame mixer library for fitness for use. I feel fitness for use is already established in the current program, so speak up if you don't agree.

Possible Future goals:
  • Find or make some better sound files, including crew chatter
  • Add sounds for other boat features (winches, cranes, etc)
  • Replace the menu to control sound effects remotely, e.g. smart-phone, auxiliary switches, radio transmitter, or some other method TBD
  • Have the engine start, stop, and run from the throttle stick position?? Will require I/O interface board (simple I/O board or Arduino, etc.)
  • Create an interface to a small audio amplifier for more volume from the vessel
  • Integrate this as a module into a larger remote operations system?

ABOUT THE SOUND FILES:
The mixer will play '.wav' and/or '.ogg' audio files. The .ogg files are the open source audio format Ogg Vorbis. There are many free sound file sites on the web, or you can create your recordings. The sound files I have included are all from free sound sites. I have made some small mods to the files, using the Audacity sound editor, a great open source (i.e. free) sound editor. Audacity will also let you convert one sound format to another.

Currently the sound files in the project are as follows:
  • ambient.ogg - Ambient sounds: lapping water, ropes flexing, traffic, etc
  • engRun.ogg - Running diesel engine fx
  • engShutdown.ogg -Engine shutting down fx
  • engStart.ogg - Engine starting up fx
  • fogblast.ogg - Engine starting up fx
  • horn.ogg - Modern horn fx
  • whistle.ogg - Whistle fx

ABOUT THE Pygame mixer and sound features (documentation):
http://www.pygame.org/docs/ref/mixer.html


Total investment to date, U$D:
Raspberry Pi microcomputer - $35.00
Case for Raspberry Pi - 8.99
Power supply, I used an old cell phone charger - 0.00
Speakers, I used old computer speakers - 0.00
Software, all Open Source - 0.00
Network cable, had one laying around - 0.00
Total: $43.99

Note: In the boat, the Raspberry Pi will be powered from our battery system. We will need to add a small audio amp if the output is not loud enough (about $20) and a speaker(s).


Pete
Last edited by blutoh; Feb 09, 2014 at 10:27 AM. Reason: update link to version 2
Sign up now
to remove ads between posts
Feb 13, 2013, 10:02 AM
---o-O-o---
blutoh's Avatar
Thread OP

Setting up the Raspberry Pi for sound


Setting up the Raspberry Pi for sound
I am using the Advanced Linux Sound Architecture (ALSA) driver because it is widely supported. Here's how I did it, your mileage may vary.

1. Log in to the Raspberry Pi

2. Install the sound card drivers and test (BTW, depending on your terminal software, you should be able to simply copy and paste these commands into you terminal window, if so, do it one line at a time and don't copy the bullet at the beginning of the line)
Open a terminal, and at the $ prompt:
  • sudo apt-get install alsa-utils
  • sudo modprobe snd_bcm2835

snd_bcm2835 is only loaded for this session, so to have it at every boot, add it to the /etc/modules file. To do so, at the $ prompt:
  • sudo nano /etc/modules

This will load the file into the nano text editor. At the bottom of the file add, on a line by itself:
  • snd-bcm2835

Now save and exit the nano editor
  • Ctrl W to write out the changes
  • Ctrl X to exit the nano editor
  • sudo reboot

We are rebooting to test that snd_bcm2835 gets loaded on each boot. After R Pi has finished booting, we test the soundcard. Open a terminal, and at the $ prompt:
  • sudo aplay /usr/share/sounds/alsa/Front_Center.wav

you should hear a female voice say "front, center" (I think it's Umi !)
If you don't hear the voice, recheck all of your steps.

3. Enabling Audio Output
The RPi audio output is set to automatically select the digital HDMI interface if its being used, otherwise it uses the analog audio output. If you are using HDMI to work on your R Pi, you need to force R Pi to use the analog audio, because there won't be any HDMI set up in your boat.
Open a terminal and at the $ prompt:
  • amixer cset numid=3 1

IF you nned to go back to using HDMI audio as the default, reset the value TO 2:
  • amixer cset numid=3 2


4. OPTIONAL: only if you are NOT running as user 'pi', then you will need to add the user name to groups audio and video (user pi belongs to these groups by default).
Open a terminal, and at the $ prompt (substitute your user name for blutoh below):
  • sudo adduser blutoh audio
  • sudo adduser blutoh video
Last edited by blutoh; Feb 13, 2013 at 01:25 PM.
Feb 13, 2013, 10:19 AM
---o-O-o---
blutoh's Avatar
Thread OP

Installing the sound effects program


Installing the sound effects program

EDIT: See post #48 in this thread for an easier install script you can donwload and run.

1. Make directories (aka folders) for the sound system:
Open a terminal, and at the $ prompt (in the lines below, the ~ is short hand for the home directory, it is usually located to the left of the number 1 key, and is shifted):
  • mkdir ~/soundfx

Change the permissions, at the $ prompt:
  • chmod 755 ~/soundfx
Change to the new directory, at the $ prompt:
  • cd ~/soundfx
Make the subdirectory for data, at the $ prompt:
  • mkdir data

2. Copy the files to the appropriate directories
Open a terminal and change to the directory you downloaded the files to.
Copy the program to the soundfx directory, at the $ prompt:
  • cp soundfx.py ~/soundfx

Copy the data to the soundfx/data subdirectory, at the $ prompt:
  • mv ./data ~/soundfx
Check permissions, on soundfx.py, should be rwxr_xr_x :
  • cd ~/soundfx
    ls -l
You should see something similar to this:

total 8
drwxr-xr-x 2 pi pi 4096 Feb 10 14:01 data
-rwxr-xr-x 1 pi pi 4079 Feb 10 15:03 soundfx.py


IF your permissions are not the same, change them. At the $ prompt:
  • chmod 755 ./*

EDIT: For a quick synopsis and the latest installation package, go directly to this post.
Last edited by blutoh; Apr 10, 2013 at 02:13 PM. Reason: Added link, see edit at top
Feb 13, 2013, 10:20 AM
---o-O-o---
blutoh's Avatar
Thread OP

Running the soundfx program


Running the soundfx program:

1. Connect a speaker to the audio out jack on your R Pi, I used
some old computer speakers for testing purposes, you can also use headphones.
Open a terminal, at the $ prompt:
  • cd soundfx
  • ./soundfx.py OR sudo ./soundfx.py

2. Follow the on screen prompts:

The program menu:

please press a key then ENTER to play sound:
  • [a] start engine
  • [b] stop engine
  • [c] toggle ambient effects on/off
  • [f] sound foghorn
  • [h] sound horn
  • [w] whistle effect
  • [q] quit this program
press a key then ENTER: q

The ambient sounds will begin playing automatically after the program starts (wait for the menu to appear). It contains sounds of lapping water, ropes flexing, passing traffic and few other sounds. The ambient sounds will loop continuously, and can be toggled on / off with the key sequence 'c' <enter>. The running engine is also automatic, it starts during the start engine key sequence ('a' <enter>), and stops with the stop engine key sequence ('b' <enter>). It cannot be toggled on / off. All other sounds are play at will, just enter the key sequence for the sound you want to play.

NEXT STEPS:
  • We need some of you to download the files and test the instructions by performing the installation and running the program
  • Start posting your ideas and comments

Thanks,
Pete
Last edited by blutoh; Feb 20, 2013 at 12:41 PM.
Feb 15, 2013, 05:10 PM
Registered User
Has anyone tried this? I would like to see the code before I install it in my rapsberry pi.

HD
Feb 15, 2013, 05:51 PM
---o-O-o---
blutoh's Avatar
Thread OP
Hi HD,

You can download the zip, and just look in the file the file soundfx.py. But I will try to post it here, hope it doens;t get mangled.

EDIT: OK, the code tags work well, see code below. Has anyone downloaded this and tried it? I am looking for feedback.

Thanks,
Pete


EDIT: For a quick synopsis and the latest installation package, go directly to this post.
Last edited by blutoh; Apr 10, 2013 at 02:14 PM.
Feb 15, 2013, 07:34 PM
Registered User
Blutoh,

I will try this next week when my R Pi arrives. I want to use this in a tank. So I can just change the sound files to what I need for a tan, correct?

HD
Feb 16, 2013, 04:52 PM
Registered User
Dutchraptor's Avatar
Pete,
I know a little Arduino, not starting RaspPi yet (I wanted to, but haven't had any time to figure out how it works). Looks very interesting. Is it als possible to read an anolog in or i/o pin (switched with a relais) on a RaspPi? Else I can use a digipot to send a engine setting to de RaspPi and play the corresponding sound with the speed. I like the mixer option. Or is it possible to send serial info to the RaspPi from an arduino (that would really be nice).

grtz.

Danny

PS: Yes I'm new to this section and finally meeting people just as crazy as I am.
Feb 16, 2013, 05:20 PM
---o-O-o---
blutoh's Avatar
Thread OP
Quote:
Originally Posted by Dutchraptor
....... Is it als possible to read an anolog in or i/o pin (switched with a relais) on a RaspPi? Else I can use a digipot to send a engine setting to de RaspPi and play the corresponding sound with the speed. I like the mixer option. Or is it possible to send serial info to the RaspPi from an arduino (that would really be nice)......
Danny,

Yes on all counts. The RaspPi has 8 general purpose IO pins (GPIO) that can be configured for input or output. You can expand this too, I use this board to get 32 GPIO pins. You can also use SPI, I2C, serial, usb and other communication protocols. Currently I am using a menu to test the sounds, but I plan on capturing the the throttle stick position and use it to set the appropriate throttle sound just as you have mentioned. I just haven't gotte that far yet. The other sounds will be activated remotely, somehow, maybe using the radio modules you are using in your system. Also, there are some good servo boards, like this one, which can be chained using SPI I2C for up tu 992 PWM outputs.

Pete
Last edited by blutoh; Feb 17, 2013 at 05:38 PM. Reason: correction
Feb 16, 2013, 08:50 PM
---o-O-o---
blutoh's Avatar
Thread OP
Quote:
Originally Posted by Heavy_Duty
Blutoh,

I will try this next week when my R Pi arrives. I want to use this in a tank. So I can just change the sound files to what I need for a tan, correct?

HD
HD,

Exactly. You can change the sounds simply by substituting new sound files fir the ones here. So the whistle can be , for example, machine gun fire, the foghorn can be cannon sound, etc. Do a google search on 'free sound effects', there are a lot out there, or you can record your own, too.

Pete
Feb 17, 2013, 03:17 PM
Registered User
Dutchraptor's Avatar
I'm gonna order one monday so I can join the RaspPi fun. Nice new learning curve, right next to the arduino. Is a class10/16 GB SDHC with wheezy enough? Or are there better/faster cards. The first reviews I saw was that booting took about 2 minutes. I'm not one of the most patient persons (my arduinos take a few seconds to boot) if t comes to starting computers. Any recommendations? I've read somewhere that starting is possible under 15 seconds. Any idea how, or is that standard nowadays?

grtz.

Danny
Feb 17, 2013, 03:37 PM
---o-O-o---
blutoh's Avatar
Thread OP
Class 10 is great, they recommend class 6 or better. I am using a SanDisk Extreme class 10 16GB card and boot time is around 20 seconds., running standard clock speed. If you overclock it would be faster, but it's really not necessary. Booting is slower than the arduino because you have to load the OS kernel and modules.
Last edited by blutoh; Feb 17, 2013 at 04:15 PM.
Feb 20, 2013, 08:48 AM
Registered User
Dutchraptor's Avatar
Hi Pete.
I received my Raspberry today and tried the program. I can't seem te get it working from th command-prompt. But in desktopmode I can open it in python-shell (IDLE) and run it (run module / F5). I'm not very familiar with linux, it been awhile since I had my basic training around the OS. What do I do wrong?

I've been able to run it. But how do I get it to run in a command prompt?

Thanks,
Danny
Feb 20, 2013, 12:40 PM
---o-O-o---
blutoh's Avatar
Thread OP
Hi Danny,

(check my edit below before you go thru all these steps)

Let's check a few things to see if we can find the problem:
Are you logged in as user 'pi'
Did you install to folder 'soundfx' ? full path: /home/pi/soundfx
Change directory to soundfx folder: cd ~/soundfx
Check permissions: ls -l

You should see something similar to this:

total 8
drwxr-xr-x 2 pi pi 4096 Feb 10 14:01 data
-rwxr-xr-x 1 pi pi 4079 Feb 10 15:03 soundfx.py

If everything looks ok, type: sudo python ./soundfx.py or sudo ./soundfx.py

and wait about 10 secs for python and the program to load. At that point you should see a menu. Let me know if you see it or if you get any error message.

Pete

EDIT: I just found an error in my instructions in post #4:
./soundfx. OR sudo ./soundfx. SHOULD BE ./soundfx.py OR sudo ./soundfx.py

I corrected it in post #4 as well
Last edited by blutoh; Feb 20, 2013 at 03:05 PM. Reason: correction
Feb 21, 2013, 04:13 PM
Registered User
Dutchraptor's Avatar
Found it, and it works PERFECT Let's see what we can do with it. Don't you just love OpenSource? There must be a way to couple my system to yours. I've doing arduino's with wav-shields from adafruit for sound. But I cannot mix with those like you do with the Raspi. Easiest way will be with relays or opto's. But serial should also be possible.

Danny


Quick Reply
Message:

Thread Tools