Using Roman Black's Btc Sound encoder with arduion; CODE

Hi

I am not a programmer but I do have a little experience with code. I have more experience with soldering and circuits.

My goal is to sew a lilypad into a stuffed animal and have it tell a story that I recorded. The story would start once a push button in its paw is depressed.

I am very interested in getting started with making a lilypad arduino play audio; more audio than 10-20 seconds. I came across Roman Blacks Btc Sound encoder, BTc Sound Encoder v3.0 - free sound software and I am wondering how I would use this to program full audio in a 1-bit format to achieve playback from the arduino that would be a couple of minutes long.

Any help would be greatly appreciated or alternative suggestions.

It'd be a lot easier to make a smaller version of something like the adafruit "Wave Shield"; there is probably no way to fit several minutes worth of audio in the ATmega's internal flash no matter how clever your algorithm, and yet it is trivial to fit much higher quality audio in $5 of consumer flash card. (IIRC, Black's one-bit audio scheme is said to produce recognizable audio, but not of very good quality.)

If your stuffed toy is big enough, you would probably be better using a full size Arduino Uno and a wave shield. You can power it all with a small 9V battery (PP3) or the like.

Having said that, if you care more about the end result than the fun of playing with Arduino, then I bet you could find a self contained voice recording / playback module on the Internet for a few dollars. You could hack its 'play' button to give you the paw squeezing feature.

I wonder what would it take to have good quality audio using the 1 bit scheme? I was hoping to make a 12 or 16 bit drum-machine, but using multiple arduino-chips. Each chip would use the 1 bit output for the audio. But from the tests I did with the encoder software, audio quality sucks, unless there's a way to increase it with a faster bit-rate. (1Mhz?)

Wk

In the old days there was software for the IBM PC that enabled "real" sound output on the internal speaker (which is connected to a single IO port bit, just like a speaker connected to Arduino pin.) You can think of it like this:
If you output a high-frequency signal to the speaker, well beyond what it is capable of converting to sound, it will essentially average the signal into a physical position. Output a square wave and the speaker cone will sit in the middle of its range. Vary the duty cycle of the square wave plus or minus the 50% mark and you move the cone to one side or the other of center. Do that fast enough, and it will start making noise again. There were some impressive demos (N-part polyphonic music, speech), in the sense of "it is impressive that the bear dances it all."
I haven't looked at the 1-bit sound code, but I would imagine that it is essentially pre-computing the bitstream that results. I think theory says that speeding up the bitstream gets you better audio, probably pretty much exactly as much as adding more bits to the encoding would (because that's what it is really doing.) By the time you get better quality sound, you're probably using as much memory as a more conventional storage scheme.

There are several audio compression schemes that were developed for telecommunications that transmit "understandable voice" at relatively low bitrates (8kbps was "easy", IIRC.) They might require special hardware. But even at 8kbps, all of the internal memory of the ATmega328 put together is going to be "not many" seconds of audio.

And in the end it's pretty silly. Memory has obeyed Moore's law and is extremely cheap these days. Spend $5 on a flash card and get a couple hour's worth of CD-quality sound...

By the time you get better quality sound, you're probably using as much memory as a more conventional storage scheme.

A bit more actually. I did PhD on this topic in the mid 70s.
I worked on sound compression in the days when if you wanted to investigate a compression / expansion algorithm you had to build it as processors were not as powerful as the atmega. Westfw's advice is good.

This showed up. It uses one or two pins for the sound output: ATtiny861 sound generator – Dangerous Prototypes

Here is a video of an Arduino Mega 2560 decoding a BTC file.

I used a gameduino to buffer the sound output to allow for simultaneous screen effects. The BTC audio code was tested to work on a plain Arduino Uno without the gameduino using port writes to get sound. jack up the timer1 frequency to 8k and write to a pin using the "nextPwm" variable in fillSampleBuffer().

source code:
http://luis.net/projects/gameduino/source/btc/

you mostly want the BTC() and V() functions. The rest was hacked together to bypass the >64K flash space access limit and use gameduino buffer sound output. its a mess but it works.

full two minute sound recording (1.1MB Save-as):

Based on BTc Sound Compression Algorithm

the link to the main project which used the sound for ending credits (also with full source):