Close
0%
0%

Blues Generator

12-Bar Blues generator in less than 1kB

Similar projects worth following
This little circuit generates a 12-Bar Blues. The chords are played by switching between tonic and subdominant to achieve a retro chord sound. These chords are accompanied by a walking bass and a pentatonic improvisation. The musical key is initialized using a linear congruential generator which is initialized by the temperature sensor. The random number generator also supplies the improvisation with random numbers.
This project is licensed under the GNU GENERAL PUBLIC LICENSE version 3.

Video demonstration


1kB?!

So why even program a tiny sound generator in assembly?
The inspiration for this was the 1kB contest. Also I wanted to see if I could really do it. This resulted in a lot of thinking about minimal implementations of algorithms and also in my first assembler project. It turned out to be a lot of fun, too!

So how do I know that it is smaller than 1kB?

First of all, otherwise it wouldn't even fit onto the chip. Secondly AVR Studio (which was used to assemble this project) told me, that only about 760 Bytes are taken.

Still don't trust me?

After disassembling the hex file again with

avr-objdump -m avr -D blues_generator.hex
the last instruction was on the address 0x2F6 which is 758 in decimal. It was a 'ret' instruction which is 2 bytes long, so the program is only 760 bytes big and consumed less than 75% of the chip.

Other than the main flash no other memory (e.g. EEPROM) was used.

Musical Theory

As already mentioned in the short description, this circuit will produce a 12 Bar blues . The original 12 Bar blues consists of the tonic (T; the first note in the scale of the key), the subdominant (S; the fourth note) and the dominant (D; the fifth note).

12 Bar blues

These three are played as chords according to the following sequence:

T T T T
S S T T
D D T T

I wanted a little bit more retro sound in my blues generator so used arpeggio for the chords which in my case just means quickly switching between the tonic and dominant of the current note. This was also widely used in 8-bit tunes to overcome the voice limit of sound chips (you will probably not what I mean when you hear it).

Walking Bass
These chords are accompanied with a walking bass in the key of the currently played chord. The walking bass uses the first, third, fifth, sixth and seventh note of the scale of the current chord like showed in the following scheme:

1 3 5 6 7 6 5 3 

Improvisation

The last part I utilized was a very simple improvisation on top of the chords and the walking bass. Improvisation in jazz and blues is mostly done by using the pentatonic scale (consisting of the first, fourth, sixth, eighth an eleventh note of the key) . This scale is independent of the current chord but it stills is in harmony with all chords.

In this implementation the AVR decides to go up or down one note with a chance of 37.5% each. It repeats the same note with a chance of 12.5% and doesn't play anything if none of the above is chosen. Although being very simple, this algorithm creates satisfy able results.

The Circuit

Aside from the AVR, power connection and reset button the circuit is dividable into three parts: the LED's, the temperature sensor and the sound output.


LED's

The LED's are simply used to output the current position of the walking bass (in binary of course). These were added very late to the project because it was easy to implement, the resource were there and it looks way cooler if something is blinking.

The LED D1 shows the most significant bit.

Temperature sensor

The temperature sensor is a simple voltage divider and is only used to initialize the random number generator with a 'random' number (read through the ADC).

Sound output

The sound output surely looks like the most complex part of the circuit although only consisting of an audio amplifier chip in it's minimal configuration. The potentiometer can (theoretically) used to control the output volume but as the minimal amplification of the audio chip is 20, most position will amplify the signal to the maximum.

The Software

The software is by far the most complex part of the project.

The following parts should provide an overview. For more technical details please take a look at the annotations in the source code.

Initialization

After the assigning register names and the interrupt table begins the general initialization (SREG, stack pointer, etc.) followed by the ADC initialization. This is kept very simple and it's only purpose is (as mentioned above) to read out the value of the temperature sensor and use this as...

Read more »

disassembled.txt

output of the disassembler to verify the size

plain - 12.59 kB - 01/05/2017 at 21:16

Download

board_bw.pdf

printable board

Adobe Portable Document Format - 4.31 kB - 01/03/2017 at 16:09

Preview
Download

board.pdf

board

Adobe Portable Document Format - 83.04 kB - 01/03/2017 at 16:08

Preview
Download

schematic.pdf

schematic

Adobe Portable Document Format - 35.15 kB - 01/03/2017 at 13:08

Preview
Download

blues_generator.hex

assembled source code, ready to flash

x-hex - 2.12 kB - 01/03/2017 at 11:47

Download

View all 6 files

  • 1 × C3: 100nF Capacitor
  • 1 × SW1: Button Button
  • 1 × TH1: TS-NTC-203 20k Ohm thermal resistor
  • 1 × SP1: Speaker 8 Ohm
  • 1 × IC1: ATTINY13 Microprocessors, Microcontrollers, DSPs / ARM, RISC-Based Microcontrollers

View all 14 components

  • The demonstration video is ready

    Jonas Schenke01/05/2017 at 21:07 0 comments

    The demonstration video is finally here!

    I've also made some minor tweaks to the details so everything should be done by now!

    Here is the video:


  • Details are finally here!

    Jonas Schenke01/04/2017 at 18:15 0 comments

    Hello again!

    A whole lot of details have now been added! This should make the documentation more or less complete, but I plan on uploading a video demonstrating the project (and maybe adding more pictures to the details).

    I'm probably also going to further refine the details (mainly to fix grammar and spelling errors, which I also should have done in the previous Blog entry -,-').

    Have fun playing around with the Blues Generator and don't hesitate to ask questions if you have any!

  • Release the blues!

    Jonas Schenke01/03/2017 at 16:20 0 comments

    Hello everyone!

    In the past couple of weeks I managed to build a little blues generator that I want to share with you.

    Yesterday finished and tested the circuit and I'm now working on the documentation and explanation (also on the musical theory behind this).

    More details should be available within the next 12 hours :-)

View all 3 project logs

  • 1
    Step 1

    Read the details!

  • 2
    Step 2

    Download the source code

  • 3
    Step 3

    Compile (I used AVR Studio 4 with the 2nd version of the assembler)

View all 7 instructions

Enjoy this project?

Share

Discussions

ericroer629 wrote 04/11/2022 at 10:58 point

This is looking one of the most impressive and interesting generator guide you can check budget camping generator information here on this link.

  Are you sure? yes | no

Vojtak wrote 01/05/2017 at 23:40 point

Nice toy. But the higher tones tear out my ears since they are not very accurate. Is there any reason why the tones are defined only by numbers 20 to 72 and full 8 bits are not utilized?

  Are you sure? yes | no

Jonas Schenke wrote 01/06/2017 at 07:21 point

These number only define the forth and the fifth octave and is later further shrunken down to only on octave in the generated key. 

Every other note can be generated from these using the formula f_base*2^k with k as the number of octaves to move the note up (with positive number) or down (with negative number). An A 5 (880 Hz) could therefore be generated by doubling the frequency of an A 4 (440 Hz).

Unfortunately this results in the precision loss in higher notes mentioned by you.

  Are you sure? yes | no

Similar Projects

Does this project spark your interest?

Become a member to follow this project and never miss any updates