Bjorklund: The Algorithm in C

Read it and weep. I know I am ūüėõ

This was the most challenging piece of code to date. Outwardly simple, and with many existing examples in other languages, not to mention the C code example in Bjorklund’s paper, it should have been a doddle to implement on the Arduino, right?

But no. I realised the big downside to using the AVRISP: no access to the serial interface, which makes debugging impossible. Thankfully I could use the Teensy 3.1 to test my Code. But this in itself brought heartache, as there were some library conflicts¬†with Teensyarduino. A troubling story to be sure, but In brief, I battled through ’til dawn and eventually cracked the bastard.

My overriding¬†concern was – how much of the ATmega’s CPU time would be taken-up by using recursive function? I would have expected this to be a resource hog, and I worried that it wouldn’t handle 8 tracks simultaneously, slowing everything down. I’m happy with the current state of the MIDI clock (99.98% accurate), and this was something I didn’t want to compromise. I also witnessed some talk on the forums about Arduino’s limited stack size.

In the end, performance wildly exceeded my expectations. See the example outputs below.

Note that I have reversed the order or the patterns in alignment with the examples¬†in Toussaint’s paper.¬†See chapter 4 for many more examples. An interesting read for sure.

In the end, the pattern directions don’t¬†matter, because I’ve implemented track rotation and track reverse in the main application. So…

For 8 steps and 3 pulses, the pattern is:
10010010

Bjorklund took 8.00 microseconds.

Cuban tresillo / Habanera rhythm. “It can often be heard in early rock-and-roll hits in the left-hand patterns of the piano, or played on the string bass or saxophone. A good example is the bass rhythm in Elvis Presley‚Äôs Hound Dog.

The tresillo pattern is also found widely in West African traditional music. For example, it is played on the atoke bell in the Sohu, an Ewe dance from Ghana. The tresillo can also be recognized as the first bar of the ubiquitous two-bar clave Son given by [x . . x . . x . . . x . x . . .].

For 8 steps and 5 pulses, the pattern is:
01101101

Bjorklund took 10.00 microseconds.

Cuban cinquillo. Used extensively in jazz, 50’s rockabilly and West African traditional music. e.g hand-clapping pattern ‘Hound Dog’.

For 12 steps and 4 pulses, the pattern is:
100100100100

Bjorklund took 10.00 microseconds.

The 12/8-time Fandango clapping pattern. (I know, I know)

For 3 steps and 2 pulses, the pattern is:
011

Bjorklund took 5.00 microseconds.

E(2,3) = [x . x] is a common Afro-Cuban drum pattern. For example, it is the conga rhythm of the (6/8)-time Swing Tumbao. It is also common in Latin American music, as for example in the Cueca.

Lastly, a silly example to check performance again:

For 83 steps and 56 pulses, the pattern is:
01110110110110110110110110110110110110110111011011011011011011011011011011011011011

Bjorklund took 63.00 microseconds.

IMG_4240

This is going to be damn sweet.
ūüôā

Bjorklund: It lives!

I’m usually the one to grumble¬†when I come across all those meaningless, grubby 20-second videos on Youtube. But today I’m adding my own. What the hell.

Here is Bjorklund just come to life:

[embedyt] https://www.youtube.com/watch?v=tJSJNcvy3vM[/embedyt]

At this moment I have a tight MIDI clock running on the ATMega328 at 24ppqn, with the option to go to a higher resolution if and when I trade-up to a better processor(Teensy 3.1 here I come!).

The 4 encoders and buttons are multiplexed using a single MCP2317, and the LED matrices are driven by 2 MAX7219s (both apparently counterfeit but working perfectly).

What you see are the available tempo divisions from slowest (each quarter note) to fastest (each MIDI tick) flashing across the screen.

I’ve come-up with an elegant way to deal with the note queues, rotation and sending MIDI. I can send notes on 8 tracks, remaining stable to master BPM of >300. ¬†All Looking good so far!

All that’s left to do is implement Bjorklund’s algorithm and feed it’s output to the note queue.

Then finally¬†the controls/menu system and that’s it! It’s all optimization from there. It seems the most challenging part is documenting the process, but I’m gathering my notes…

ūüôā

Bjorklund: Breadboarding an Euclidean sequencer using Arduino / Sanguino with AVRISPmkii in Win7 and Linux.

I should be wiring-up the 4x4pole, but here I am fiddling with breadboards. Suddenly got it into my head that I must build an¬†Euclidean Rhythm¬†based MIDI/CV sequencer. Bjorklund’s algorithm will be used:

The problem reduces to the following: construct a binary sequence of n bits with k one’ s, such that the k one’ s are distributed as evenly as possible among the zero’ s. If k divides evenly (without remainder) into n, then the solution is obvious. For example, if n = 16 and k = 4, the solution is [1 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0]. The problem of primary interest is when k and n are relatively prime numbers [23], i.e., when k and n are evenly divisible only by 1.

Toussaint discovered (only in 2004!) that the resulting patterns of spaced pulses often represent the rhythms of many word music styles. This presents a simple way to generate new and interesting drum patterns.

There are already other Euclidean generators out there, and even one in the MIDIbix Seq4, but I have my own nascent ideas, even if I only a little knowledge on how to implement them.¬†Another distraction! ūüôā

The logical conclusion to this effort should be a PCB for a unit that can act as a standalone MIDI/CV sequencer in a box, and one that is small enough to be integrated into a Eurorack setup. After some research I decided to start with Arduino. It comes with MDI libraries as standard, and already there are lots of interesting projects out there to reference.

In keeping with the DIY philosophy, I forewent the purchase of an Arduino board and instead opted to set-up a development environment using ATmega microcontroller and the Arduino libraries: Рessentially to create an Arduino clone on a breadboard.

I am¬†using the ‘standard’ Arduino chip – the ATmega328p (used in the MIDpal). As I had a spare ATmega644 (used in the Shruthi-1), I decided to breadboard it as well. The 644 is not officially supported by Arduino, however there is an Arduino-compatible bootloader called Sanguino.

IMG_4218

There is plenty of information out there on how to breadboard these chips. The most useful video I found was this one from Notes and Volts, which helped me setup the 328p in no time.

[youtube https://www.youtube.com/watch?v=ufQZnAAxZ7A&w=400&h=255]

In the process, the concept and function of the pins became clear, and I could easily map the ATmega pins to their Arduino equivalents using the following diagram:

atmega328-pinout

For the 644 I used this reference and this pinout diagram:

atmega644-pinout

Once hooked-up, I needed a way to program the chips. Fortuitously I had an Atmel AVRISPmkii to hand. I bought this to program my Shruthi chips and used it for all of 5 minutes a few years ago.

avrispmkii

There are some issues to watch out for when using the AVRIPSMKii with Arduino:

  • The various sources I referenced all used a 10K pull-up resistor on the reset pin, however for the AVRISPMkii to work properly, this pull-up resistor must not have a value higher that 4.7KOhm. See P26 of this document.
  • In Win7, the Atmel USB driver conflicts with the Arduino IDE. A different driver must be installed. Full details here.
  • On Linux, the toolchain and associated libraries need to be installed. Further, to get the Arduino IDE working, the correct USB device permissions must be set specifically for the AVRISPMKii. This is achieved by updatinbg the UDEV rules. See P12 of this document. Note: I had to use ATTR{idProduct} instead of SYSFS{idProduct}.
  • If using avrdude we must always specify that we are using the the port (-P usb). See the tutorial here.
  • A green status LED on AVR indicates that connections are good. With the AVRISP, the board MUST be separately powered (5v) in order for the AVR to detect and program the chip.

OK, so after overcoming the AVRISP driver issues, the next task was to set the fuses and install the Arduino boatloader onto the virgin chips. This requires hooking-up the AVRISP to the correct Arduino/Sanguino Pins. Referencing the pinout diagrams above, making the connections is an easy task, but one that must be approached slowly.

Referencing the AVRISPmkii pinouts:

avrispmkii_pinout

Just to be clear, this is pin 1:

IMG_4210

I made a little breadboard adaptor for it…

IMG_4176

IMG_4178

Ending-up with something like this:

IMG_4197

After triple-checking the connections, I fired-up Arduino IDE. After many failed attempts, I was still not able to bootload the damn things. Attempts at querying with avrdude always returned the following error:

avrdude: Device signature = 0x000000
avrdude: Yikes! Invalid device signature.
Double check connections and try again, or use -F to override
this check.

A web trawl suggested that this was due to the crystal not oscillating. Switching-out the crystal and trying instead a 16Mhz resonator returned the same error.

As it turned out, the default avrdude transfer speed is too fast for the virgin chips, therefore it’s necessary to adjust the baudrate (-B option in avrdude) to allow the initial communication. I didn’t realise this until after I solved it, and this was the problem that soaked-up most of my troubleshooting time. Bah!

The desperate answer in my case was to install Atmel AVR studio 6.2 – an overly torturous and bloated product (1.5Gb install), but one that bore immediate results when following this blog post.

Later, I realised that I could have done this much more quickly with Linux, and without the need for that massive Atmel install. Here are the required commands (Ubuntu).

Now fire-up Arduino IDE. No serial port is recognized on the AVRISPMKii, therefore trying to upload a sketch will return a ‘no Com port‘ error. It took me a few minutes to figure-out that you must instead ‘Upload using Programmer’ i.e press shift when sending the sketch (or just ¬†cntrl-Shift-U). Also, it’s important to ensure you are uploading to the correct board type in the Arduino IDE (Arduino UNO vs Sanguin 644).

I attached a MIDI out port and an LCD, loaded-up a simple MIDI sketch to test it.

IMG_4206

It worked first time. A great start!

Next steps will be to wire-up some pots and buttons, and start writing the code.

4x4pole: I dream of wobbly resonance.

2013 started brilliantly, let there be no doubt. By April, my newly found obsession with DIY synthesisers reached a peak, and a small pile of worthy project PCBs was collected. Then work took over. For a year.

There were times during that winter of DIY-lessness that I looked forlornly, hopelessly, at the cardboard boxes of fresh components, and the half-built units soaking-up dust on the shelf.

Whilst unable to actually build, dreams of what was possible prevented me from going mad, and I spent my spare moments planning, plotting, scheming for the day I would wield the soldering iron again. 

Now that that day has come I can reveal the outcomes of my lengthy pause for cogitation:

The original plan  for the 4x4Pole Mission was to house the 4 voices together with a scavenged Fatar keybed. Many panel designs were drawn-up, with this being the final iteration in that direction (click to view).

The problems with this setup soon became obvious:

  • Originally I was to cut the 79cm panel in 5mm thick Acrylic, however the panel would likely still flex during use. Not ideal.
  • The positioning of the screens and controls was too dispersed. If possible, I wanted to be able to see all screens at once, and I tried grouping them together, but still without satisfactory results.
  • Since I was going to all this trouble to mount a keybed, why should I restrict it’s use to just one synth?

In the end, I went for a compromise solution – but one I am very pleased with:

  • The keyboard/MKE and UC16 now become a master controller, with in-built MIDIpal, a 3mm anodized aluminium faceplate, and joysticks!
  • The 4×4 Pole is racked on a 4U 19″ Aluminium Panel, and with (wait for it…) more joysticks!

The redesign went much faster now that I had a clear idea of the endpoints. The alumium faceplates were quickly designed in FPD and sent to be cut by SchaefferAG.

I was very pleased with the results – with one minor niggle: I only used 2mm Aluminium for the Rack faceplate, meaning that there is some flex. This is fixable, but I should have used 3mm aluminium, similar to the keyboard panel, which has no flex at all. Oh well, you live and you learn.

Must say though, the anodized panels turned-out way sexy-looking. Victory candy included!

No excuses now….and no time to waste….

In my last post – a full 18 months ago! – I ravaged my poor old Evolution UC16 MIDI controller to prepare it for the installation of panel-mounted pots. In the intervening period the assaulted PCB eyelets gave-up hope and fell off, leaving me with a considerable amount of microsurgery to get the board working again.

 

Not pretty, but perfectly functional. Liberal amounts of hot glue and some PCB varnish should give it a few years of extended life.

Once that was done it was a matter of mounting the boards and wiring-up. Time-consuming but largely trouble-free.

 

Colourful though….

 

So, the keyboard components have been tested and all work together. MIDI is internally wired from UC16 > MKE > MIDpal > out. Initial tests show this to be a stunning combo. The MIDIpal rules!

All I need now are the side and back panels. I know what I want, I just can’t afford the additional cost right now (about 70 euro). However, this is no problem because the 4x4pole is quickly coming together. As of last night, all boards were working as expected, the filters have been tuned, and the sound of awesomeness is in the air.

Just the wiring to go…..

 

in 3 or 4 days I should be there.

Shruthi-1 SMR4 MkII – NoisyLittleBugger Edition

Hooray!

It’s finally here: NLB’s special edition modded Shruthi-1 SMR4 mkII.

Mods:

  • 2/4 pole filter toggle switch
  • Bandpass 1/3 3-way switch
  • Filter Feedback FM toggle switch
  • Audio input routing switch – normal vs FM modulator
  • Filter FM Feedback amount pot
  • VCA overdrive pot
  • UFO Balcklight mod
  • Audio input and output volume¬†pots.
  • OLED
  • Styroflex capacitors
  • Suitable clothes!

Check here for details of the joystick mods…¬†here¬†for the filter mods……and here¬†for the drive mod.

Here is the SVG file for the case (right-click to download).

Many thanks to Mutable Instruments and the community.

Removing the spring from Gamepad Joysticks

[youtube https://www.youtube.com/watch?v=I3Nm4A_3N6Y&w=400&h=255]

To satisfy a couple of requests, I made this little vid to demonstrate non-destructive removal of the spring from standard gamepad joysticks (Xbox 360, PS3, Logitech, etc.).

If you don’t have a nephew’s games closet to raid, you can always buy the joysticks. This is my source. Tell Uwe I sent you.

Here’s where I show how to wire-them to the CV inputs of a Shruthi-1.

Back and building with vengeance…

New Drums:Yamaha RM50

This is the 1U rack version of the RY30. Release year: 1992 (manufactured from 1992 to 1995).

I’ve been eyeing them for quite a while and always thought I should pounce if one became locally available. Then two came along at once, and at 100euro per unit I had to get both.

IMG_2148

Even without any expansion cards, for a 20-year old module it’s sounding great, with a small set of high-quality drum samples on-board. There’s a limited but interesting drum-focused synth engine. Pitched synth sounds are also facilitated, with basic but functional parameters to edit. No crazy pads here, but definitely usable for bass work – there’s a satisfying low-end.

The 64 factory kits are OK, if a little too generic. Although there are not many basic samples, the preset sounds demonstrate what is possible. My interest is creating custom kits. There are 128 slots for user-created sounds using the on-board and imported RAM waveforms. More than enough.
Each drum sound can be made-up of two ‘Voices’. Each Voice in turn contains 2 ‘Elements’, which consist of one drum sample and and it’s synth engine.

The synth engine is simplicity itself. There’s a very basic pitch envelope generator, an amp envelope, resonant low-pass and non-resonant high-pass filters ( (12 and 24dB), and LFO for pitch, cutoff and amp modulation.

The MIDI delay effect allows the first note to be switched-off, leaving only the repeats. Looks interesting, especially for glitchy/granular effects. Finally, there’s good control over velocity sensitivity, where volume, pitch, cuttoff and decay can be set to different values.

CC assignments are basic – 6 fixed parameters can be assigned for real-time control at kit level. The CC assignment can be switched off per sound, so there is some flexibility.

No internal FX, however some samples have reverb built-in, and this can be gated. Nothing fancy, but the sounds do seem to fit together, making it sound nicely cohesive out-of-the-box. The compactness of the 1u RM50 is also strongly appealing, though it is bloody heavy.

Deep editing with only the front-panel buttons may seem a challenge, but I’ve found it surprisingly intuitive and straightforward.
There’s also a cross-platform patch editor. Simple, but does the job – except no MIDI input under Windows.

Thankfully there are Headphone outputs. Until I get a proper soundcard I can’t record any clips, but soon….

Other nice things:
+ Each drum sound has two separately-editable voices or ‘Elements’ that can be mixed using the balance control which, mapped to CCs provide for morphing kits!
+ Handles heavy MIDI streams.
+ Deep velocity sensing options for dynamic kits.
+ Reversible samples.
+ Audio Trigger inputs = modular fun!

Peremptory niggles:
– CC control at kit level only, and only 5 fixed parameters. But selectable per voice.
– No real-time pitch change except via EG, which is rather basic.
– No sample start adjustments, however there’s a unique delay control per Element which looks good for glitchy sounds.
– No LFO to pan. Voice outputs are mono anyway.
– No noise samples, and a shortage of Hihats, however…

Lucky for me, one unit unit came with additional wave sample ram already installed, which allows me to upload 512k of my own samples. Not too shabby.

There is also a third-party expansion module available, but I think I’ll have enough in one.

I’ve already uploaded some Goldbaby samples via the MIDI port using Elektron’s C6 sysex manager. Easy.

A scanned manual is available, in three parts:
Part1
Part2
Part3

Overall, I am very pleased with these acquisitions. I was going to build both the Sonic Potions LXR and the TR8060, but I simply don’t have enough time recently, and it’s beyond time I stopped farting around and got serious about recording for a change.

Firmware check
– Switch off RM50
– Press and hold PLAY + MACRO + SOUND while pressing the Power On button

Factory Reset:
– Hold play + utility buttons when powering-on

Battery:
3V lithium backup battery (CR2450)

Full specs:
– 16-bit AWM2 (48 kHz sampling frequency) with digital filter 22-bit linear D/A converter
– Layering 2 elements/voices, 2 voices/notes
– Polyphony 16
– Voices 500 preset + 500 variation + 100 user; optional Wave Card: 32 user (x3); optional Data Card: 500 variation + 100 user
-Rhythm Kits Internal: 64 preset + 64 user; optional Data Card: 64 user
– Operation Modes Multi Play mode, Multi Edit mode, Voice Edit mode, Utility mode
– Trigger inputs!
– MIDI Parameters Program change mode selection; Program change table; Control change settings; Control change assignment; Remote mode selection
– Displays Multi-function 48-character LCD; Edit LED (red); MIDI received LED (red)
– Expansion Slots External wave card slot (x3); External data card slot; Internal expansion memory board slot
– Connectors Headphones, Line out L/MONO & R, Individual line out (x6), MIDI IN, OUT, THRU
– Power 120/220 V, 14
– (W x H x D) 480mm x 44mm x 347mm (D); 18 7/8” x 1 3/4” x 13 5/8”
Release year: 1992 (manufactured from 1992 to 1995)

Cheap Bastard: Busboards are easy

Finally, I get some time to myself. But not much, so let’s crack-on.

First I connected-up the PSU to the mains. Now, if you are going to try this yourself I shouldn’t have to tell you to be careful, but I will anyway. BE CAREFUL. I’m not responsible if you fry yourself.

Anyway, I took no chances for first power-up. I stood well back and used a stick to¬†switch¬†it on, and I’m not ashamed of it ūüėõ

But it works. So, out comes the multimeter to measure the veracity of the advertised voltages.

IMG_2036

All looking good. Nice and stable output, no vibration and barely audible noise. The trimpot allows quite accurate tuning, however, it affects all three busses at once, and there is slight variation between them. Not a big deal?

Next was to grab some stripboard, a couple of large capacitors and suitable headers. It turned out that I ordered the wrong IDC connectors. So I have female connectors for the busboard, and male cable clamps. But this is no problem, as they can easily undergo a sex change with the help of some spare pin headers.

IMG_2033

IMG_2031

The connectors are wired as follows:

a100b_e

Initially I won’t be using the +5 bus, so I’ll only need the 10-pin headers. Stripboard makes it easy to follow the busses, and the whole thing took just a few minutes. This is just a first run. I’ll probably reinforce the tracks later. But as it is there seem to be no problems.

IMG_2032

IMG_2034

The capacitors are probably not even needed, but it’s no harm to ensure that the supply is filtered. Some details here.

After connecting the PSU, I measured the voltages at the pins and it seems that we’re in business!

IMG_2039

Let’s have a dance to celebrate:

[youtube http://www.youtube.com/watch?v=PeeOPR8bxac&w=400&h=255]

Cost of each busboard comes in well under 5euro. Now I just need a finished module to power ūüėõ

Cheap Bastard: No need for Baugruppenträger

While I’m waiting for some parts and test cuttings for the 4×4, it’s progress has been overtaken by this modular monkey business. I’m in no rush.

So, after assembling the Baugruppenträger and RAST, as expected, I required mounting rails to complete the job as first envisioned. Since I had a voucher for MusicStore, it was used buy the only rails they had Р12HE Adam Hall thingies at a fiver per pop. I got 4 to keep me stocked for future requirements.

Silly me hadn’t reckoned on them being made from a thick steel. As I don’t have the means to cut them, another much simpler and less expensive option popped-out: I could just glue or screw some 2cm wooden strips and mount the Baugruppentr√§gers directly onto these. Or, as I quickly realised, I could even just mount the vector rails directly this way and not require those ugly rack ears at all.

IMG_2020

IMG_2021

OK then Рto hell with the Baugruppenträger!

However, it’s 4 vector rails can still be used to complete two 84HP racks, thus filling the RAST. So, for future reference, I will only need the Vector rails and the Thread strips. I could even do away with these altogether, but since I have them I’ll use them.

In depleting my voucher I couldn’t resist trying a Monotron delay, especially because it has exposed CV points on the board and would thus could be re-housed into a 4HE module. It’s nice but surprisingly noisy. That’s not necessarily a bad thing ūüôā