Arduino Forum

Using Arduino => Audio => Topic started by: cHubbz on Apr 17, 2015, 03:38 am

Title: Playing converted soundfile through squawk
Post by: cHubbz on Apr 17, 2015, 03:38 am
Hello Arduino community!

I'm currently working on a little aid for a board game. The idea is for a player to slap a box, triggering a program through a piezo speaker acting as an analog input.

The program causes red and green LEDs to flash back and forth, until grinding at a halt at either one. At this point, I want a sound to play, depending on whether the result was green or red. Red being a demonic laughter, and green being an angelic choir (in all their 8-bit glory).
I'm on track for all of the code, apart from the sound.

Now, I know that playing audio through an arduino board is very restrictive. Recreating these two sounds using tone() just seems way too finicky, though.

It seems to me that the easiest way to do this would be to use squawk, and convert an existing audio file to raw data to be used by squawk. This is as far as I've gotten though.

I have two issues that need solving -

This is my setup
Arduino: 1.6.3 (Windows 7), Board: "Arduino Uno", Processor: ATmega 328P

1.
I've tried to copy over the squawker code available here (https://github.com/stg/Squawk/blob/master/sketches/Squawk_player/Squawk_player.ino) along with the song "TheOriginalSquawk". Upon attempting to compile it, though, I get these errors -
--------------------------------------------------------------------------------------------------------------
C:\Program Files (x86)\Arduino\libraries\Robot_Control\src\ArduinoRobot.cpp:3:18: fatal error: Wire.h: No such file or directory

 #include "Wire.h"

                  ^

compilation terminated.
--------------------------------------------------------------------------------------------------------------

I've chosen the correct pin etc., as told in the comments of the host code. As far as I've understood it, the issue is with the library squawker is attempting to get data from, but I've been unable to find a solution.
I only started working with Arduino two days ago (started programming about a month ago), and I wasn't able to figure out what is wrong through the minimal guidance available at the squawk github/google.


2.
The second issue is converting the .wav file I've found into data. After looking around for a bit, I found a good .wav file of an evil laugh (http://www.planetarypinball.com/mm5/Williams/games/arabian/Sounds/laugh_8k.wav), which I've converted to a .it file in OpenMPT, and opened in the squawk2mod.exe converter (https://github.com/stg/Squawk/blob/master/convert/bin-win/squawk2mod.exe). Upon doing so, a prompt tells me my selected file is too small. The file is 42,6kb.

--------------------------------------------------------------------------------------------------

Any help with these issues would be forever appreciated!
I'm sorry for the wall of text. I just wanted to make sure I've left you with all necessary information.
If there's something I've missed, please ask and I'll do my best to supply it!

Cheers!
cHubbz
Title: Re: Playing converted soundfile through squawk
Post by: Grumpy_Mike on Apr 19, 2015, 07:15 am
It sounds like you have not installed the libraries.
Go here:-
https://github.com/stg/Squawk (https://github.com/stg/Squawk)
Down load and uncompress.
Open the folder and open the libraries folder to see four libraries . Quit the Arduino IDE.

Locate the Arduino's libraries folder and drag the four files into it.

Restart the Arduino IDE and the example will compile. 
Title: Re: Playing converted soundfile through squawk
Post by: Grumpy_Mike on Apr 19, 2015, 07:18 am
Quote
I found a good .wav file of an evil laugh,
Yes but it is 43K long. The Arduino only has 32K of memory so It won't fit will it.
Title: Re: Playing converted soundfile through squawk
Post by: cHubbz on Apr 19, 2015, 12:39 pm
Thanks for the replies, Mike!

Will take a look at installing the libraries ASAP.

As for the audio file, I have no idea about how much data one can store, but i'm trying to convert this 2 second clip into raw code. It seems strange to me that the converter tells me the file is too small. Other songs that have been converted over (see this (https://www.youtube.com/watch?v=0bJ-MDg2SJc) for instance) must have been much larger than what I'm working with?
Of course, it might be that the clip I've chosen has a much higher bitrate. In that case, is it possible to reduce the quality of the clip down to a level where it will work (assume this will have to be done in MPT)?

Cheers!
Title: Re: Playing converted soundfile through squawk
Post by: Grumpy_Mike on Apr 19, 2015, 12:53 pm
Quote
Other songs that have been converted over (see this for instance) must have been much larger than what I'm working with?
No that is not just a pure sample. That is using the Squawk as a synthesiser to generate the note but the actual notes are sequenced by a list of data from the program.

In an Arduino UNO you have 32K of flash memory for all your code and sample data. So depending on the byte rate of the sound you will only get a small time. For a pure sample running at a sample rate of 8K then you can not exceed 4 seconds, remember you need space for the code as well as the sample. With such a rate the maximum harmonic of any wave is 4KHz, so telephone quality only.
Title: Re: Playing converted soundfile through squawk
Post by: cHubbz on Apr 19, 2015, 01:22 pm
Quote
No that is not just a pure sample. That is using the Squawk as a synthesiser to generate the note but the actual notes are sequenced by a list of data from the program.
That's what I'm trying to do. I understand that putting pure sound files onto the board isn't going to be feasible, but what if I use squawk's converter to convert my sound file into a data list in the program?

I'm sorry if I'm misunderstanding you and going round in circles!

Cheers!
Title: Re: Playing converted soundfile through squawk
Post by: cHubbz on Apr 19, 2015, 01:47 pm
Well, at least the squawk player works now. Had to revert to version 1.0.5 of the IDE.
Title: Re: Playing converted soundfile through squawk
Post by: Grumpy_Mike on Apr 19, 2015, 01:54 pm
Quote
but what if I use squawk's converter to convert my sound file into a data list in the program?
I haven't used squawk so I don't know what its converter does, but I would be very surprised if it could do that.
Title: Re: Playing converted soundfile through squawk
Post by: cHubbz on Apr 19, 2015, 02:16 pm
Quote
Squawk requires your ProTracker files to be converted into Squawk melodies.

Melodies come in two flavors:

As data you put in your sketch to download with your code.
sketches/Squawk_player
As a file on an SD card connected to your Arduino.
sketches/SquawkSD_player
Both formats can be generated by converter in the convert/ directory.
That's what I assumed this said at least :o

Now I just have to get my head wrapped around how I work things in OpenMPT, as it seems that's where things go wrong.

Thanks so much for all the help!