Pages: [1]   Go Down
Author Topic: 16 Step MIDI Drum Machine - Help ?  (Read 1103 times)
0 Members and 1 Guest are viewing this topic.
Brazil
Offline Offline
God Member
*****
Karma: 3
Posts: 616
Wusik Dot Com
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Guys, I'm working on a 16 Step MIDI Drum-Machine to run on Arduino Uno/Mega/...

I want to use its EEPROM to hold the patterns, so the user can use a Song-Link that plays patterns in order. But the problem is the size of each pattern, and I don't know how to optimize. I was wondering maybe if I could "compress" each pattern before storing, and "uncompress" on reading?

Here's the pattern per say.

Code:
unsigned int dmSteps[15];

Its just 14 Tracks + 1 Accent Track (last) - since this is a 16 bit number, each bit is a step On/Off.

I also need to decide how to store the patterns in the EEPROM and how to manage the Song-Mode. (shouldn't be too hard I got an Arduino Mega, which has plenty resources, but I want my first project to run on the Uno too.

Any hints would be mostly appreciated.

Thanks in advance.

Best Regards, WilliamK
Logged


Brazil
Offline Offline
God Member
*****
Karma: 3
Posts: 616
Wusik Dot Com
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

But them I could just go ahead and use one of those...

http://10kohms.com/arduino-external-eeprom-24lc256

 :-X

Wk
Logged


Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 217
Posts: 13742
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You want the pattern to be 15 channels and every bit is one beat? So all bit0's are beat 0; all bits 1's are beat 1 all bits 2's are beat 2 and so on until 16.  It is sort of a matrix, so let me think....

Rotate the matrix 90 degrees so every unsigned int is one beat (or was that the idea in the first place?)

Code:
#define NRBEATS 48    // just as example
unsigned int dmSteps[NRBEATS];
...
for (int i=0; i< NRBEATS; i++)
{
  for (int ch = 0; ch < 15; ch++)
  {
    if (bitSet(dmSteps[i], ch))
    {
      // SendMIDIchannel ch a beat
    } else {
      // SendMIDIchannel ch a silence (or just delay)
    }
  }
}

This way you just read one int at the time and instead of copying them to an array you could fetch them runtime from EEPROM, one int at the time. Should be fast enough, but keep an eye on your timing...

Code:
#define NRBEATS 48    // just as example
...
for (int i=0; i< NRBEATS; i++)
{
  unsigned int x = EEPROM.Read(2*i);
  x << = 8;
  x += EEPROM.Read(2*i + 1);
  for (int ch = 0; ch < 15; ch++)
  {
    if (bitSet(x, ch))
    {
      // SendMIDIchannel ch a beat
    } else {
      // SendMIDIchannel ch a silence (or just delay)
    }
  }
}

You might use an unsigned long to go to 32 channels smiley
« Last Edit: January 01, 2011, 02:15:25 pm by robtillaart » Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Brazil
Offline Offline
God Member
*****
Karma: 3
Posts: 616
Wusik Dot Com
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks, but things are a bit different. ;-)

First, I changed the specs to 14 channels + 2 accent channels. So we have 16 x 16 - channels x step

Now, I have a buffer for the next pattern to load, so I don't load and play from the EEPROM, I just load and write once and its on the memory, as it takes only 32 bytes to store the whole pattern.  8-)

I ordered the extra SparkFun chips as they are chip, but it would be fun to be able to compress a 32 byte pattern into something smaller, but I doubt I would go much lower, so extra EEPROM is a must indeed.

In any event, thanks anyway.

Wk
Logged


Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 217
Posts: 13742
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Thanks, but things are a bit different.

Could you share the code to show how you did it?
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Brazil
Offline Offline
God Member
*****
Karma: 3
Posts: 616
Wusik Dot Com
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Sure, give me a bit more time, as its almost ready, just missing the extra EEPROM chip I ordered. ;-)

Wk
Logged


Pages: [1]   Go Up
Jump to: