Showing posts with label soundbox. Show all posts
Showing posts with label soundbox. Show all posts

Wednesday, 1 August 2012

The sound of Soundbox

So, at last I managed to take some video of the Soundbox device I have built. I have discussed this device in two earlier posts, notably the electronics and the case construction.


Here I first demo the two different voices, sine and noise, separately. After that, I try to build some nice sounding loop with both voices combined. The latter part is somewhat failure, though. On a previous try of recording the video I actually managed to build a loop that sounds mostly good, but some glitch messed up the audio on that.

This video had been sitting on my hard drive and Google's servers for quite a while, since at the time when I recorded it, I was unable to embed it into a post using the Blogger editor. But now, as I was writing an another post, I noticed that there were new options in the "Add image" dialog and I was able to post this video. Yay!

Wednesday, 4 January 2012

Soundbox — The construction

The Soundbox device I have built uses some construction techniques I want to share with you readers. I'm mainly talking about the enclosure and the texts on controls.


The enclosure itself is built from a simple box bought from a craft store. It was unfinished wooden box with two small hinges and a clasp to hold it closed. The lid and bottom parts were quite nicely suitable size for all the parts, I just needed to build the control panel inside this box.


The control panel is built from 4 mm plywood that I cut to the correct shape with a coping saw (not the best tool for the job, but that was what I happened to have at hand). Then I drilled the holes for the knobs and such. The speaker hole I cut with the coping saw. To keep the control panel in place, I glued some 9 × 9 mm wood bars to the inside of the box, 4 mm from the top of the bottom box so that the control panel will sit flush with the sides of the bottom part.

After constructing the box, I removed the hinges and the clasp and painted the box and control panel with several (maybe four) layers of white spray paint. What surprised me was how much that stuff stinks — I had to keep the parts outdoors for a couple days after painting so that my room would not smell of solvents. The finished box had a distinct solvent smell for like a month after it was done.


The two main knobs — pitch and arpeggio — are of my own design. They're seven-sided knobs with friction fit for the usual 6 mm potentiometer axle. I created the model in Blender and ordered them from a 3D printing company called Shapeways. The design didn't work quite as intended and I had to remove some material from underside of the knob so that the nut that holds the potentiometer in place fits under the knob. I also had to use 6 mm drill bit to widen the centre hole so that the potentiometer axle fits in there.


For the markings on the control panel and the two main knobs I used transfer lettering from Letraset. This is rub-down lettering, that is, you write by finding the required letter from the sheet, placing that to its intended place and rubbing down on the letter sheet so that the letter material is transferred from the sheet to your working piece. These are mainly intended to be used on paper, but they appear to work just fine on wood and plastic.


After writing all the texts I wanted, I coated the control panel, the two red knobs and the box with several (probably three) coats of clear spray lacquer. Before this it would have been possible to rub or scrape the lettering off, though it would have taken some effort. After the lacquer coat the lettering is there to stay. Even though the spray again had quite an amount of solvents, neither the lettering nor the plastic of the two red knobs was adversely affected.

After this, the rest is rather straightforward. I re-attached the hinges and the clasp I had removed before painting the box white. I installed the potentiometers, buttons, switches and the line jack to the control panel with their supplied nuts. The two LEDs and the speaker I attached with hot glue. Eventually I will have to figure out something more sturdy than hot glue for mounting the speaker, for it did come loose at the Alternative Party. The control panel is held in its place by the side walls of the box and the support bars inside the box, but there's nothing stopping you from lifting it upwards to reveal the electronics hidden inside.

Sunday, 20 November 2011

Soundbox — what makes it tick

I did have the soundbox device I have built with me at Alternative Party 2011. It did attract a fair amount of interest, though nowhere near what my 32×8 LED screen did. I think I'll have to write a post about that LED screen and how it works some time. For quick info, it's built around an ATmega328, can show 16 different shades of green with gamma ramp and shows some classical effects such as plasma and fire.

Neither one of my projects gained nowhere near the interest that the Chernobyl reactor simulator by Helsinki Hacklab did, but that is only to be expected. That simulator was awesome, even though they didn't quite manage to get it to a playable state during the event.


I'll first describe the high-level workings of the soundbox, then the hardware side and last the software used.

High-level view

The device is a looper: it plays a short loop of sounds over and over again and the sounds can be altered while the device is playing. It provides two channels, each with its own waveform and each separately programmable. The loop is 128 sounds long and the actual length of loop in seconds depends on the setting of tempo knob.


The first sound channel plays sine wave and the second channel plays pitched noise. One of the device controls is a pitch knob that can be used to select the frequency of sine wave of noise to be programmed.

For sine wave there's also second knob — arpeggio — which can be used to alternate between the base pitch and a higher pitch at a high rate. The rate is fixed depending on tempo and the setting of arpeggio knob defines how much higher is the higher pitch.

Also there's a beat LED that flashes four times during every loop through the sound loop — white at the beginning of loop and red the other three times. This is to help the user see how fast a tempo the device is using.

The front panel also features a built-in speaker which is mere 5 cm across but can produce surprisingly high volumes — even at the active party hall it was able to put out enough volume to be clearly audible at close quarters. I've tried some small commercial speaker devices intended to be attached to portable CD/MP3 players and found that they can't put out nearly enough volume in such situations, so I was somewhat surprised that this simple device could.

The hardware design

The  hearth of this device is Atmel ATmega88 microcontroller running at 16 MHz. Sporting 8 kB of flash memory and 8 kB of RAM, this microcontroller is the little brother of ATmega328 that is used in the popular Arduino prototyping board.

Early version of the hardware

With the built-in analog-to-digital converter in ATmega88 it is simple to read the positions of the three 10 kΩ linear potentiometers used for pitch, arpeggio and tempo. The potentiometers are connected across device ground and regulated 5 V lines, so turning a potentiometer changes the voltage at its middle pin linearly between these two voltages. This voltage is read with the ADC in the microcontroller and used to control the sound generation.

The microcontroller outputs the sound using Pulse-width modulation and uses a simple resistor-capacitor low-pass filter so that only frequencies below the Nyquist frequency of the output are passed to amplifier and eventually to speaker. Or at least this was the idea — I don't know quite exactly the frequency response of the filter I built, especially as I ended up swapping some of the capacitors to different value than the one originally planned, since I didn't have any with correct value and could not be bothered to visit the electronics store to get a couple capacitors. Anyhow, it sounds good and looking at the output with an oscilloscope doesn't show modulation frequency passed through, so I guess it's fine.

After the low-pass filter is the volume control: a 10 kΩ logarithmic potentiometer. After it there's a LM386 amplifier chip that drives the speaker or the device connected to the line out jack. One notable thing is that this amplifier chip is not connected to the regulated 5 V line that is being used to drive the ATmega88, but to the unregulated voltage straight from the batteries. This is done to maximize the voltage available to the amplifier chip — which means more volume — and to ease the load on the regulator, which is simple 7805 linear regulator that can generate considerable amounts of heat if heavily loaded or if the difference between its input and output voltages is large.

Speaking of batteries and voltage regulation, the power source for this device is six AA size NiMH cells. With nominal voltage of 1.2 V each, the total voltage is 7.2 V — high enough so that the 7805 can produce stable 5 V supply and well inside the operating voltage range for LM386.

The software

The software for the soundbox is written in C using the AVR libc library.

The sounds to be played are stored in two 128 bytes long arrays, one for each voice. Each byte in these arrays corresponds to one sound to be played, the value defining the pitch of the sound.

At the hearth of the sound generation is a numerically controlled oscillator (NCO). The oscillator for sine voice uses 256 samples long phase-to-amplitude converter array that is filled with sine values at device boot up. The noise channel uses similar table filled with random values with Gaussian distribution, creating a table that contains white noise. The oscillator for noise channel advances in its table 4096 times slower than sine oscillator of same frequency. This value has been chosen experimentally so that sine and noise with same pitch setting would sound like having somewhat similar pitch.

The sound generation itself is done inside the overflow interrupt of an pulse width modulation timer that's built-in in ATmega88. Each time the timer overflows — every 256 processor ticks in my configuration — a new sound amplitude is computed from the two NCOs and written in pulse width control register.

Reading inputs and setting the frequencies of the two NCOs is done in the main program loop. Each loop of the main program moves one step forward in sound arrays, reads inputs, writes new sound values to sound arrays if needed and sets the frequency controls of NCOs according to the values in sound arrays. After this it runs NOP command in a loop a suitable number of times to wait until new sound is to be played.

That's it for this time. I'm thinking of posting something about how I made the enclosure, especially the labels on the panel and buttons. Maybe some recording of the sounds I get from the device, too.

Thursday, 20 October 2011

Soundbox project and Alternative party

I've been building a digital instrument that has been inspired by the Luna Mod which was presented in the Make magazine some while ago. It is a two-voice software synthesizer implemented on an Atmel ATmega88, an eight-bit microcontroller. It plays a short loop of sounds which are programmable by selecting suitable pitch and amount of arpeggio and pressing a programming button.


I will present this device for the first time at Alternative party 2011 which starts in less than 24 hours. It's a festival for many sorts of digital art, especially demos (as in demoscene, not short versions of games) and there have been many electronics enthusiasts – such as KOELSE - Association of Experimental Electronics and Helsinki Hacklab – in the last years. I'm confident this project will fit right in there.

I'll write more about this project soon, at least something about the electronics and software design in this device and about how the control panel was made.

The source files and an electronics design drawing made in Fritzing are available at a GitHub repository.