Musical AVR - Melodies and 'stylophone' synth

Go To Last Post
22 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello All,

this is something I knocked up as I had a little bit of spare time, and I thought I'd share it as it amused me.

It plays tunes that come out on the PWM pin (portB2 - pin 5 on the ATtiny24v), you just need to filter it (a simple RC filter will do) + an amp or speaker, etc

The tunes are easily edited, so you can program you own melodies.

If you do give it a go then post them and I'll look forward to listening.

All the best

Dren

NB : There's an improved version 2 of the software (a few posts below)

Attachment(s): 

<º))))><

I am only one lab accident away from becoming a super villain.

Last Edited: Fri. Feb 20, 2009 - 01:15 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

This works pretty well :

const char Tune3[ ] PROGMEM =
{	// note / duration - resolution is 4 ticks per beat, crotchet=4, quaver=2, semi-quaver=1
	E3,  2, 
	G3,  4, A3, 2,  B3, 3, C3, 1,  B3, 2, 
	A3,  4, Fs3, 2, D3, 3, E3, 1,  Fs3, 2,
	G3,  4, E3, 2,  E3, 3, Ds3, 1, E3, 2, 
	Fs3, 4, Ds3, 2, B2, 4, E3, 2,
   G3,  4, A3, 2,  B3, 3, C4, 1,  B3, 2,
	A3,  4, Fs3, 2, D3, 3, E3, 1,  Fs3, 2,
   G3,  2, Fs3, 2, E3, 2, Ds3, 3, Cs3, 1, Ds3, 2,
   E3,  4, E3, 2,  E3, 6,
	D4,  6, D4, 3,  C3, 1, B3, 2,
	A3,  4, Fs3, 2, D3, 3, E3, 1,  Fs3, 2,
	G3,  4, E3, 2,  E3, 3, Ds3, 1, E3, 2,
	Fs3, 4, Ds3, 2, B2, 4, Rest, 2,
   D4,  6, D4,  3, C4, 1, B3, 2,
	A3,  4, Fs3, 2, D3, 3, E3, 1,  Fs3, 2,
	G3,  2, Fs3, 2, E3, 2, Ds3, 3, Cs3, 1, Ds3, 2,
	E3,  6, E4,  2, Rest, 8,
	EOD
};

And if you replace the envelope with a gradual rise, something like :

unsigned char Envelope_Audio(unsigned char Audio_Data)
{
	unsigned char Envelope_Data = 0x00;

	Envelope_Data = (Multiply8x8(Audio_Data, (NOTE_time >>6) ))>>8; 
	
	//Envelope_Data = (Multiply8x8(Audio_Data, pgm_read_byte(Exp_Table + (NOTE_time >>8) )))>>8; 


	return Envelope_Data;
}

It even sounds a little like a flute... well with imagination :)

<º))))><

I am only one lab accident away from becoming a super villain.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Here's an electric lute :

	Envelope_Data = ((Audio_Data>>1) + ((~NOTE_time>>8)>>1)); 

and this is some sort of crump horn ?

	Envelope_Data = ((Audio_Data>>1) + ((NOTE_time>>8)>>1)); 

<º))))><

I am only one lab accident away from becoming a super villain.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi, as it turned out the 'fast' multiply wasn't that fast :( so it's best to delete the multiply routine and Multi_Table look up table and just use :

unsigned char Envelope_Audio(unsigned char Audio_Data)
{
	unsigned char Envelope_Data = 0x00;

	Envelope_Data = (pgm_read_byte(Exp_Table + (NOTE_time >>8)) * Audio_Data)>>8;

	return Envelope_Data;
}

(It doesn't even need to be a seperate Fn)

It plays an user defined waveshape, in a user defined envelope... how does it sound ? Just like a 1980s casiotone keyboard... pretty ghastly !

<º))))><

I am only one lab accident away from becoming a super villain.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

Just like a 1980s casiotone keyboard

Nothing wrong with those - I used to love my Casio VL-tone 1:

http://en.wikipedia.org/wiki/Cas...

(sadly the zebra strip to the LCD broke so it became displayless)

It was possibly most famously used as the rhythm track on "Da da da" in the early 80's:

http://en.wikipedia.org/wiki/Trio_(band)

When I get access to the hardware bits I'm very tempted to try your code here - probably in a mega16 or a mega168 in fact.

Cliff

PS I wonder if anyone is old enough to remember a "stylophone-like" synthesiser project that appeared in (I think!) Electronics Today International in the mid to late 70s? I built one, it was brilliant, I'd love to build one again or make a digital emulation but I need to know where to find the original article/schematic

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I still own a stylophone ! I used it to play the lead synth part on 'The Walk - The Cure' in a band I was in. It's a neat little circuit, just built around 2 transistors (I seem to remember). It's a voltage controlled Osc AND also the 'power' amp ! The 'delux' version also had vibrato.

It's a great idea though, it would be really easy to use a few resistors and an ADC input to play the note and bingo you have a stylophone !

Virtually any AVR would do to run the code, and as it stuffs out data at 31250Hz a simple RC filter works fine. You might even be able to get away without even that, of course it would no longer be 'hi-fi' quality... ahem :)

<º))))><

I am only one lab accident away from becoming a super villain.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

I still own a stylophone !

Me too. Admittedly I only got mine for Christmas a couple of years ago after they relaunched the design. My sister had one back when they were first available so it was great to be able to get hold of one these days. In fact I was so convinced that every kid needs to have a Stylophone at some point in their development that I also bought one for each of my nieces and nephews - my brother must love me at this stage because of this!

Oh wow - I just found this online emulator:

http://www.firebox.com/product/1...

(it sounds remarkably authentic! shame the vibrato button isn't active though)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
every kid needs to have a Stylophone at some point in their development
The world would be a much better place :)

Quote:
I also bought one for each of my nieces and nephews - my brother must love me at this stage because of this
In much the same way my brother loves me after I bought my nephew a drum kit - LOL, I must buy my niece a violin next ?

<º))))><

I am only one lab accident away from becoming a super villain.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Here's mark 2 - it's more tuneful :)

The waveshape and envelope are stored in look up tables so they can be changed to give it different sounds. It's plays three defined tunes (which can be easily edited), it then becomes a 'stylophone' emulator. Just connect a 'stylus' onto the ADC input (PA0) then you can then play it with a resistor ladder (or pot). I did this for fun, so have a play and hack it about and I'd like to hear what you do with it.

Attachment(s): 

<º))))><

I am only one lab accident away from becoming a super villain.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Now can we make it read midi files?

Imagecraft compiler user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Oddly enough I was thinking about that :S ! Before you know it a bit of playing about evolves into a full blown casiotone... it justs needs a drum section (boom ching boom boom ching) DAH DAH DAH !

<º))))><

I am only one lab accident away from becoming a super villain.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Actually, it COULD have a MIDI port :)

MIDI is an opto-coupled serial link @ 31K250Hz, which is the frequency of the PWM. So it should be possible to sample the MIDI input pin on the timer0 interrupt, and reconstruct the 8 bit data. OK, it's not going to be a 100% reliable interface (for that you'd need to sample the pin 3 times the baud rate) but it should work... maybe that's next week's fun bit of programming if I can get the annoying distraction of real work out of the way.... err does anyone want a MIDI controlled 'stylophone' emulator, by the way ?

<º))))><

I am only one lab accident away from becoming a super villain.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

you can use uasrt to read midi data.
but how about playing them using mega devices?

I love Digital
and you who involved in it!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I meant read midi data from a file and play it, but using it as a midi sound module is cool too. Way cool actually. Maybe even commercial product quality.

Imagecraft compiler user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
Maybe even commercial product quality
Have you listened to it yet ? :shock: LOL. It's doing it's best, bless it, @ 8 bits and with a noisy DAC, but on the plus side it's very cheap and could find a use in a few products, musical toys etc.

It's possible to make it an '80s quality' MIDI sound module by working at 16 bits, overlaying waveshapes in different envelopes and adding a decent DAC. There's spare CPU waiting to be burnt up, (and this is just done on the tiny) :) How about an early MOOG emulator ?

By the way if anyone does make a commercial product from the basis of this, or you have something you want me to add to it. I am very amenable to ideas and to having royalty payments in the form a decent single malt scotch :wink:

<º))))><

I am only one lab accident away from becoming a super villain.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

if you can convert midi files into something that we can hear it would be very nice. i have a melody that i always wanted to paly it with my avr.
here i will attach it.

Attachment(s): 

I love Digital
and you who involved in it!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'll see what I can do next week :)

<º))))><

I am only one lab accident away from becoming a super villain.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Well that MIDI file is still in the in box, sorry.

In the meantime here's a picture of the stylophone (there's a SM resistor between each strip). 3+ octaves is enough to play on. I could add switches to select the starting octave, waveform sound and vibrato, but you get the idea...

Attachment(s): 

<º))))><

I am only one lab accident away from becoming a super villain.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If you take an example how FM synthesizers did the multiply, they used logarithmic values, so where in linear space you multiply and divide things, in log space you add and subtract things.

http://docs.google.com/Doc?id=dd8kqn9f_13cqjkf4gp

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Could you upload a video or mp3, I wonder how it's sound ?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Where is the code i just see main.c?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

nas11116 wrote:
Where is the code i just see main.c?
It probably got mangled when the legacy site was upgraded 4 years ago.  That was a major fustercluck.

 

What's more, the legacy site has been offline for quite a while now.  I tried the Wayback Machine, but no luck.

 

 

 

 

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"We see a lot of arses on handlebars around here." - [J Ekdahl]