cedricmoers
Posts: 1
Joined: Mon Dec 16, 2013 5:18 pm

Sounds Music and GPIO together

Mon Feb 24, 2014 11:08 pm

Hi all,


I'm completely new to rasberry, but for my new project I needed a board which could process audio.
My project is a scalemodel of uss constitution in an interactive diorama. Light, sounds, etc.
Using light-conducting fibers I managed to light up the cannon's as if they were shooting.
What I want to use the Raspberry for is

1. Play music (drunken sailor,...)
2. Play ocean Sound
3. Play voice sound effects (like Fire!.., Lower Main Sails, Captain speeches)
4. Play cannon sound effects (A big boom)

5. GPIO synchronous with several sound effects (While the sound for the cannonshot is playing, flicker or blink the lights inside the cannon. Another example : when lightning is simulated, flash a light and play a thundersound.
6. GPIO controlling servo's, there are 2 servo's under the ship, which will simulate waves

So basically I want to control both GPIO and Soundfiles at the same time, is this possible? and how?

For the cannons I was thinking about using some basic electronic circuits, I only need one channel (right) of audio, so I could use the left channel as signal for the lights. Using a low-pass filter and some opamps varying the intensity of the lights.

Orange
Posts: 44
Joined: Tue Jan 24, 2012 6:41 am

Re: Sounds Music and GPIO together

Tue Feb 25, 2014 11:30 am

Hi,

I am a software developer by profession and dabble with Raspberry Pi's in my spare time. I would be happy to help you with your project. I have already completed a small project where my Pi controlled two servos simultaneously using software PCM, and with a little research I can write you some software for the audio output and any other GPIO control you require.

Probably the best solution would be some software where you can create your own simple control script to determine what actions happen and when, either timer controlled or triggered by GPIO inputs such as push-switches, or a mixture of both.

Am I right in thinking you just want to use mono audio samples and want to direct them to either the left or right audio channel and you want to play multiple audio samples at the same time? This shouldn't be a problem, I can start working on some prototype software in my spare time.

You can Private Message me if you like, and good luck with the project,
Scott.

Orange
Posts: 44
Joined: Tue Jan 24, 2012 6:41 am

Re: Sounds Music and GPIO together

Tue Feb 25, 2014 2:32 pm

An alternative if you want to do your own coding is to use Scratch which is already included in the standard Raspian install image. I believe this has full support for RasPi GPIO and also has full audio sample support.

Orange
Posts: 44
Joined: Tue Jan 24, 2012 6:41 am

Re: Sounds Music and GPIO together

Tue Mar 11, 2014 11:23 am

I went ahead and developed a scripting language for Cédric and he is currently testing it. When we've ironed out the last few bugs I will be happy to release the program as open source. In the meantime, if anybody else wants to test it please pm me.

There is more info on what I have developed here:

http://www.raspberrypi.org/forum/viewto ... 63&t=71665

Thanks

Kerry_
Posts: 2
Joined: Fri May 02, 2014 4:46 am

Re: Sounds Music and GPIO together

Fri May 02, 2014 4:54 am

Hi Orange, I want to do something similar what you are talking about here. My idea is connect a microphone to the Raspberry Pi, and when it detects sound I want to move a servo and play a song at the same time, while the microphone is detecting sound, I am new as well in RPI so I don't know whether that is possible or not, can you help me? Thanks!

Orange
Posts: 44
Joined: Tue Jan 24, 2012 6:41 am

Re: Sounds Music and GPIO together

Fri May 02, 2014 5:42 am

Hi Kerry,

I have now renamed my program pioscript and you can download it from here:

https://github.com/scott-vincent/pioscript

It will do the sound and servo part of your project but doesn't support microphone input although that sounds like a great idea for an enhancement. I was already about to try connecting up a microphone to my Pi so I will see how easy it is to incorporate a sound detector into pioscript.

Orange
Posts: 44
Joined: Tue Jan 24, 2012 6:41 am

Re: Sounds Music and GPIO together

Sun May 04, 2014 12:59 pm

I've done some tests with an old webcam (with built-in mic) plugged into a USB port on the Pi and I've got portaudio working with it fine. I can now record a 44.1 KHz mono sample using the portaudio library and can play it back in stereo using the sdl_mixer library. This is all from a C++ program. Now I've proved the concept I will add it into pioscript. I included some processing so it removes background noise and only starts recording when there is no silence. It also removes the silence from the end of the sample and it writes a WAV file once complete.

I was thinking of adding the following commands to pioscript:

record_sound <secs> - Will record for the specified number of seconds and return once done.
start_recording <secs> - Will start recording and return immediately. This is useful for something like push-to-talk where you want to record for as long as a switch is being pressed. Stops recording after either the specified number of seconds or stop_recording is called.
stop_recording - Will stop the recording, e.g. you can call this when a switch is released.
start_recording_wait <secs> - Will wait until there is some sound, then starts recording and returns immediately. This can be used as a trigger as it returns as soon as the sound starts (ignoring background noise which is filtered out).
trim_recording - Will remove the silence from the start and end of a recording.
play_recording - Will playback the recording (from memory).
play_recording_wait - Will playback the recording and wait for it to complete.
save_recording <filename> - Saves the recording to a WAV file. You can then use all the Play commands built into pioscript.

Orange
Posts: 44
Joined: Tue Jan 24, 2012 6:41 am

Re: Sounds Music and GPIO together

Wed May 07, 2014 9:25 pm

Recording, playing back recordings and saving them to wav files is now all incorporated into pioscript. I just need to add the triggering and then I'll upload a new version of pioscript to github.

Return to “General discussion”