Music downloads
Scene productions
Chip music
Hardware projects

Power Ninja Action Challenge

Here's another ATmega88-based hardware chiptune, this time composed for Little Computer People 2009. It was my contribution to the "other music" compo, and won the 1st place.

Link love to virt whose incredible chip tunes never cease to amaze and inspire.

The microcontroller runs at 8 MHz and emits a 44.1 kHz mono signal. This means that each new sample has to be generated in at most 181 clock cycles, which is tight but quite possible. As you can hear, there's enough processing power for five channels (triangle, two pulses, noise and DPCM samples, just like on the NES).

The binary image occupies 5480 bytes of flash. Output appears on PORTD, where you simply attach an R-2R ladder and a DC-blocking capacitor.

Posted Sunday 19-Jul-2009 17:47

Discuss this page

Disclaimer: I am not responsible for what people (other than myself) write in the forums. Please report any abuse, such as insults, slander, spam and illegal material, and I will take appropriate actions. Don't feed the trolls.

Jag tar inget ansvar för det som skrivs i forumet, förutom mina egna inlägg. Vänligen rapportera alla inlägg som bryter mot reglerna, så ska jag se vad jag kan göra. Som regelbrott räknas till exempel förolämpningar, förtal, spam och olagligt material. Mata inte trålarna.

Anonymous
Tue 18-Aug-2009 23:13
Hello Linus,
Are you planning to release your source code (even without music)?
lft
Linus Åkesson
Thu 20-Aug-2009 08:43
Hello Linus,
Are you planning to release your source code (even without music)?

Hi!

This time I don't have plans to release the source code, because there's nothing particularly new compared to the playroutine in Craft. There's the drum samples, of course, but that's just 1-bit DPCM. Also, getting 44.1 kHz sound from a chip running at 8 MHz was a challenge, but nothing extreme. So the code is a mess, and I feel like I'd have to tidy it up a bit if I were to release it.
Anonymous
Thu 10-Sep-2009 18:36
You still can use 1 of ATmega's PWM channels instead of R-2R ladder which requies 8 uC pins.
lft
Linus Åkesson
Fri 11-Sep-2009 16:00
You still can use 1 of ATmega's PWM channels instead of R-2R ladder which requies 8 uC pins.

Hi!

Sure, PWM is a good and simple method for rendering an audio signal. I used it in the Turbulence demo, for example.

However, in this particular case it wouldn't work. The microcontroller is running at 8 MHz, and in order to get 8-bit resolution the PWM timer would have to be counting from 0 to 255. The timer can't be clocked faster than the ATmega88. This means we get a nasty carrier wave at about 31 kHz (with lots of overtones), which has to be filtered out. But the audio is generated at 44100 samples per second, so frequencies up to about 22 kHz should be left alone by the filter. Such a steep low-pass filter (almost no attenuation at 22 kHz, almost complete attenuation at 31 kHz) can't be realized with passive components.

In a situation where the system operates at a higher frequency and pins are scarce I would go for the PWM method.
Anonymous
Sun 20-Sep-2009 21:32
Hi Linus!
Again, why didn't you use any cheap DAC and communicate via SPI with it? It's pretty simple method, additionally we get good sound quality. Don't say that we won't have processing power for this, because we would have only to activate 1 peipheral.
PS. I like your music, it looks nice between my chiptunes collection :) Could you tell where did you get all that knowledge?
lft
Linus Åkesson
Sat 26-Sep-2009 18:55
Again, why didn't you use any cheap DAC and communicate via SPI with it?

First, it would be an external IC. Why use two chips when one is enough? Second, I think some lo-fi artifacts are desirable in chiptunes, e.g. any non-linearities (but probably not regular noise and hum). If we want a perfect digital representation, we shouldn't bother with a DAC at all, right? Just sample the pins digitally or run everything in a simulator. But I think we'd lose some of the lo-fi character of the sound.

PS. I like your music, it looks nice between my chiptunes collection :) Could you tell where did you get all that knowledge?

Thank you! I'm trained in classical piano, and I've listened to a lot of music. I've been composing chiptunes and other tracked music for many years, and improved along the way; some of my earlier tunes are really bad. =)
Anonymous
Wed 25-Nov-2009 10:16
i'm confused so do you actually compose your own chiptunes from scratch or just the hardware? i'm no techy but the music is great.

-paul
ppmeyer@gmail.com
lft
Linus Åkesson
Thu 26-Nov-2009 15:55
i'm confused so do you actually compose your own chiptunes from scratch or just the hardware? i'm no techy but the music is great.

Thanks! Yes, I compose the music as well.
Anonymous
Mon 15-Mar-2010 01:40

lft wrote:

This means we get a nasty carrier wave at about 31 kHz (with lots of overtones), which has to be filtered out. But the audio is generated at 44100 samples per second, so frequencies up to about 22 kHz should be left alone by the filter. Such a steep low-pass filter (almost no attenuation at 22 kHz, almost complete attenuation at 31 kHz) can't be realized with passive components.

But 31 kHz isn't audiable by human ears, is it? :)
lft
Linus Åkesson
Thu 18-Mar-2010 20:35

lft wrote:

This means we get a nasty carrier wave at about 31 kHz (with lots of overtones), which has to be filtered out. But the audio is generated at 44100 samples per second, so frequencies up to about 22 kHz should be left alone by the filter. Such a steep low-pass filter (almost no attenuation at 22 kHz, almost complete attenuation at 31 kHz) can't be realized with passive components.

But 31 kHz isn't audiable by human ears, is it? :)

Correct. But it would still interfere with the other sound. Suppose you play two sine waves through a loudspeaker, one at 31 kHz and one at 5 kHz. You would hear it as a single sine wave at 18 kHz, which would beat (grow stronger and fainter) at 26 kHz (which wouldn't sound like beating but rather like a timbral change, since it's such a high frequency... but you get the point). Furthermore, if you had a 31 kHz wave present in a signal, and that signal were sampled at 44 kHz because you routed the audio into a digital soundcard, then the 31 kHz would get reflected at the Nyquist frequency and appear as 9 kHz in the recorded audio. While a soundcard would filter its input, the filtering would be inaccurate for the same reason I gave above; it's difficult to filter out 31 kHz completely and retain 22 kHz unattenuated.
kingofthespill
Sun 25-Jul-2010 00:23
Very cool! BTW I love your website, many excellent projects.

I was wondering if you did anything special to keep the noise low. I think the audio is significantly clearer than on some of your other projects, like the "Swan".

I've experimented with sound using several different AVRs PWM, R2R, and an 8-bit DAC and have found it difficult to get beyond telephone quality. I noticed they all generate noise on the power line, and the distortion varies a little from chip to chip. For what it's worth the Attiny45 does have high frequency PWM via an internal PLL, but it makes a distorted square wave (to my ears at least).
Anonymous
Tue 17-Jan-2012 00:58
Hello Linus,
Your work is very impressive *and* inspiring!
I'm trying to reproduce your work, but without copying your code. I want to "reinvent the wheel" and learn some stuff along the way :D I understand the physics of sound, but I'm no musician! My first implementation on an AT90S2313 @ 8MHz (I know it's old but I like challenges --just like you do ;) has two pulse waves, a 4bit triangle and noise. I guess this sounds good for a first attempt, but the sound is... "flat" and boring. I thought of implementing some simple effects (vibrato and pitch bend), but when I did, the sound become noisy! My code is too slow...

Does your code apply a certain effect on each channel, or I'ts capable of changing the effects from note to note?

Is your code capable of playing music on all channels simultaneously?

I hope my questions are making sense and I thank you in advance for any answer (and your time of course)!

Panagiotis :)
Anonymous
Fri 13-Feb-2015 00:29

lft wrote:

Thanks! Yes, I compose the music as well.
Impressive.