Surfing on Entropy

March 21, 2019 at 10:28 am (art, computers, music) (, , , )

I was passed a link to this interesting comment from Brian Eno: “There is not enough Africa in computers” (thanks Richard).

I’ve now read this a couple of times and was still left wondering quite what lay behind the comment.  So I tried to find the original interview between Kevin Kelly (then editor of Wired I believe) and Brian Eno so I could read it in full.  Unfortunately it isn’t on the same link anymore, but with some googling, you can find it in the Wired archive here.

There are a number of really fascinating discussion points – I really recommend reading the whole article – and it provides the context for that isolated quote. I did find some of the answers a little contradictory at times though.

A disclaimer, to date the music and views of Brian Eno seems to have passed me by, so these comments start with this interview in isolation. I look forward to seeing what he would say now and finding more about his ideas of generative music.

On the one hand I believe he is saying he doesn’t like the “set it in motion and it will perform predictably” aspect of computers – he likes the idea of providing inspiration and guiding principles that may or may not produce something depending on the live inputs of the viewer/reader/listener – he appears to like the serendipity of it all … but later on he talks of “black boxes for music” where he has set the rules and the box produces the music according to those rules, with some input from the listener depending on their mood.  The box become some combination of player and instrument if I understand his view correctly.

Right near the start of the interview, he suggests that the orchestral tradition is too constraining, but I see it as a (more limited admittedly) set of programmable components ready to do the composer’s bidding.

When you look at how the orchestra developed from Mozart’s time through the Romantic period, contrasting those early Classical period works with Beethoven, Brahms and then the later large scale deployments of Mahler, there is quite a lot of scope for variability there and the basic “machine” evolved enormously through that time. Then when you look at what Stravinsky did in his ballet music or what Debussy did with his completely alternative view of harmony through to the likes of Messiaen recreating birdsong in his Turangalia symphony (including incorporating the electronic Ondes Martinot), then as a “programmable box” an orchestra is actually quite a versatile person/machine system in action.

I guess he doesn’t like the idea that a composer sets the rules and the orchestra is then condemned to just reproduce them.  But I wonder what he thinks about jazz and improvisation? Good jazz still follows rules, but every performance is different. But it isn’t random. Is a jazz ensemble “more Africa” than an orchestra?  Or maybe it is a matter of the illusion on unpredictability.  When I look at something like the Long Player – that is a key set of rules, and you exactly determine what the music will be at any point – but the cycle is so long (designed to last a thousand years) that every time you dip into it, you don’t really know what you will hear.  Or at the other end, is John Cage’s As Slow as Possible where you can go back after several months and the music is still exactly the same.

I guess some of this relates to the difference between analogue and digital.  Digital is obsessed with chopping up the analogue reality into small measurable chunks – be that discrete frequencies that we call semitones in Western music, pixels on a computer screen, or even the digitising of the end results as a digital bit stream to be played back via audio hardware off a CD or MP3.  But even when digital and in theory part of a finite space, that space is so vast as to approximate to the entire musical repertoire or pictorial output of any artist, composer or musician (as least as far as human senses are concerned).

I’ve always been fascinated with the idea of the computer screen representing an unimaginably large single number and that counting through them all would show every possible image that screen could display.

In theory the digitisation of music could be represented the same way – if every note on the piano keyboard had a number 1 to 88, then a piece of music (forgetting rhythm for the moment) is essentially one very long base 88 number.  That’s not too dissimilar to how a pianola worked, although physical layout of the cut-outs are key here, or even MIDI in today’s world, when linked with a sense of the flow of time of course.  I remember my school having a dictionary of musical themes and it basically worked on those lines (although it only worried about a single octave, so it was essentially a 5-10 digit “base 7” number).  I’ve always wanted that book, but so far have never seen one since.

So just because things can be reduced to number and handled by computer, is that any less “Africa” than a free-flowing analogue equivalent?  I guess a key distinction is not necessarily digital vs analogue, but more pre-determined vs unpredictable.

In a weird way, fast forward these last 20 years and computers have become so complex as to be largely unpredictable to many.  Now that these already complex machines are hooked up to the even more complex global machine that is “the Internet” (by whichever definition to choose to use – remember it is just a series of tubes), then most of us would be hard pushed to be convinced by the argument that computers are things that always behave the same way based on the same inputs.

I am reminded here of Bjarne Stroustrup when he said (I believe): “I have always wished for my computer to be as easy to use as my telephone; my wish has come true because I can no longer figure out how to use my telephone.”

I’m also reminded of the fact that computers may soon be able to pass the Turing Test, not because they’ve become as smart as humans, but possible because there is a real possibility that humans are becoming as dumb as computers…

Back to Brian Eno:

“What people are going to be selling more of in the future is not pieces of music, but systems by which people can customize listening experiences for themselves.  Change some of the parameters and see what you get.”

He was after unfinished pieces of musical ideas to be combined in a new form as the listener experiments.  Of course, in a sense he was overestimating the listeners – today listeners want “customized listening experiences” but at the granularity of the song, the tune, not the musical extract or idea or concept.  And they don’t really want the effort of having to produce it themselves.  Of course they have it in droves with on-demand streaming where algorithms are “changing the parameters” on your behalf.

His ideas for evolutionary music and art may still come about, but again probably more by presaging the idea of algorithms creating music and art. But does that make the algorithms the composers and painters?  The jury is still out on that one, but he may well get his “furniture music” this way – his “ubiquitous 24 hours a day” music “infiltrating every waking moment of our lives”.

It is interesting his view on the use of machines.  He suggest we all need to be “surfing on entropy” – to be able to ride the wave of unpredictability and complexity becoming apparent.  I think that is very, very apt today, but the huge irony here being that this unpredictability and complexity has come about by the very components he considered too constrained, “not enough Africa”, now being let loose as they’ve grown more powerful and complex, on the world.

Machines are no longer doing “predictable, boring and repetitive things” – they are the very instruments of uncertainty.  We can still exert influence – by surfing the wave of complexity:

“When you surf, there is a powerful complicated system, but you’re riding on it, you’re going somewhere on it, and you can make some choices about it.”  You either ride it an use it with skill to get your own direction, or you give up and go with the flow.

There is an interesting section discussing the difference between art and science.  Art “doesn’t make a difference” – in that he means that whilst art will stimulate emotions, create large emotional experiences (e.g. watching a film) then end when the experience ends.  Of course, with today’s blended and mixed reality, is that still the case?

A fascinating read, especially with the benefit of 20 years passing in the mean time. The context might be slightly different, but many of the thoughts are still amazingly apt for today.  I’d love to know what he thinks about these thoughts again today.

Kevin

 

Advertisements

Permalink Leave a Comment

ATtiny85 MIDI to CV

March 2, 2019 at 4:07 pm (computers, music) (, , , )

There are a number of projects out there that provide a MIDI to CV function utilising some flavour of the ATtiny family of microcontrollers.  But most of them go from USB MIDI to CV but I wanted a genuine 5-pin DIN MIDI to CV.  This was the result.

It has taken a basic MIDI in circuit from the Internet (Google will find a few of these kicking around) and pairs it with the ATtiny85 CV out section of Jan Ostman’s cheap USB MIDI 2 CV design.

Update: Jan Ostman has now written a tutorial on how to do this directly using the USI on the ATtiny85. Read it directly from the expert here http://blog.dspsynth.eu/diy-good-ol-midi-to-cv/

The result is as follows (excuse the poor representation in Fritzing, it served its purpose). Note that the 6N138 only had 5 active pins in the Fritzing part, so the extra dodgy link shown below is a fudged link for pin 7 to GND via a 4.7k resistor.

MIDItoCV2_schem

I also have a version for the ATtiny2313, but the main changes are as you’d expect.  Basically I was having problems with the ATtiny85 missing MIDI messages and wondered if a hardware UART would be better.  Turned out it was just my dodgy code with no real error checking getting out of sync with the MIDI stream.  But it took trying it on a 2313 to highlight the real issue, so back to the ATtiny85 and now all is well.

Design wise, its fairly simple ATtiny85 wise with the pin usage as follows:

  • SoftwareSerial receive on D3 (PB3) which is physical pin 2.
  • Gate output on D2 (PB2) which is physical pin 7.
  • CV output using the PWM signal tied to OC1A triggered off timer 1, which is D1 (PB1) on physical pin 6.

The code uses the same trick that Jan Ostman used in his code – if the top compare value for PWM operation is 239 then there are 240 graduations for PWM.  To cover a MIDI range of C2 (note 36) to C7 (note 96) is 60, so the PWM compare value required for a linear CV voltage output is basically (note-36)*4.

In terms of timer control registers, this all translates over to (refer to the ATtiny85 data sheet):

  • Set PWM1A i.e. PWM based on OCR1A
  • Set COM1A1 i.e. Clear OC1A (PB1) output line
  • Set CS10 i.e. Prescaler = PCK/CK i.e. run at Clock speed
  • Clear PWM1B is not enabled (GTCCR = 0)

The value for the PWM cycle is set in OCR1C to 239, and the compare value is set in OCR1A between 0 and 239, thus representing a range of 0 to 5v giving 1v per octave, assuming a 5v power supply.

When porting to the ATtiny2313, a similar scheme was used, but timer 1 is a 16 bit timer, and the control registers were slightly different, but I still used the 0-239 range.

Reading around the different modes, I ended opting for the use of Fast PWM with the compare value in OCR1A and the maximum PWM cycle value (239) in ICR1.  The timer register settings were thus as follows:

Timer 1 Control Register A (TCCR1A):

  • 7 COM1A1 = 1 COM1A1(1); COM1A0(0) = Clear OC1A on compare match; set at TOP
  • 6 COM1A0 = 0
  • 5 COM1B1 = 0
  • 4 COM1B0 = 0
  • 3 Resv = 0
  • 2 Resv = 0
  • 1 WGM11 = 1 WGM11(1); WGM10(0) = PWM from OCR1A based on TOP=ICR1
  • 0 WGM10 = 0

Timer 1 Control register B (TCCR1B):

  • 7 ICNC1 = 0
  • 6 ICES1 = 0
  • 5 Resv = 0
  • 4 WGM13 = 1 WGM13(1); WGM12(1) = PWM from OCR1A based on TOP=ICR1
  • 3 WGM12 = 1
  • 2 CS12 = 0 CS12(0); CS11(0); CS10(1) = Prescaler = PCK/CK i.e. run at Clock speed
  • 1 CS11 = 0
  • 0 CS10 = 1

Timer 1 Control Register C left all zeros.

I don’t know if it was the version of the ATtinyCore I was using, but the bit and register definitions for Timer1 for the ATtiny2313 didn’t seem to match the datasheet, so I just used the bit codes directly.

In terms of ATtiny2313 pin definitions, the following were used:

  • Hardware serial receive on D0 (PD0) which is physical pin 2.
  • Gate output on D11 (PB2) which is physical pin 14.
  • CV output using the PWM signal tied to OC1A triggered off timer 1, which is D12 (PB3) on physical pin 15.

A quick note on the MIDI serial handling.  My first code was very lazy and basically said:

Loop:
  IF (serial data received) THEN
    read MIDI command value
    IF (MIDI note on received) THEN
      read MIDI note value
      read MIDI velocity value
      set CV out value based on MIDI note value
      set Gate signal HIGH
    ELSE IF (MIDI note off received) THEN
      read MIDI note value
      read MIDI velocity value
      set CV out value based on MIDI note value
      set Gate signal LOW
    ELSE
      ignore and go round again waiting for serial data
    ENDIF
  ENDIF
END Loop

This generated a very quirky set of issues.  Basically when there was serial data available and a MIDI note on or off command detected, the read of the note and velocity data was returning and error (-1) which I never bothered checking.  Basically the code was running too fast and the next MIDI byte hadn’t registered yet.  So when (-1) was passed on as the MIDI note, it was resulting in a note on code thinking the MIDI note was 255, which was rounded up to the highest note (96).

The result was that I could see the gate pulsing in response to MIDI note on and off messages, but the CV voltage went high as soon as the first MIDI message was received.

The next version used test that said

IF (at least three bytes of serial data received) THEN

which means that if things get out of sync, eventually bytes are skipped until there are three bytes that equate to a note on/off message.  Crude, but it worked enough to show the principle.

The final code includes proper handling of the “Running Status” of MIDI, as described here: http://midi.teragonaudio.com/tech/midispec/run.htm

I used the 8MHz internal clock for the ATtiny85.

To test all of it together, I used my ATtiny85 MIDI Tester.

I might add some kind of selection for the MIDI channel.  Right now its hard-coded in a #define.  One option might be using an analogue input and a multi-position switch with a resistor network.  Or maybe a “tap to increase the channel” digital input switch.  Or if I use the 2313 version, I could use more pins and use a BCD or hex rotary switch or DIP switches.

2019-03-02 16.00.27

Here is the full code for the ATtiny85 version, which can be loaded up from the Arduino environment using the ATtiny85 core by Spence Konde. 

// MIDI to CV using ATTiny85
// NB: Use Sparkfun USB ATTiny85 Programmer
//     Set Arduino env to USBTinyISP
//     Set to 8MHz Internal Clock (required for MIDI baud)
#include <SoftwareSerial.h>

#define MIDIRX 3  // 3=PB3/D3 in Arduino terms = Pin 2 for ATTiny85
#define MIDITX 4  // 4=PB4/D4 in Arduino terms = Pin 3 for ATTiny85
#define MIDICH 2
#define MIDILONOTE 36
#define MIDIHINOTE 96

// Output:
//  PB2 (Ardiuno) = Pin 7 = Gate Output
//  PB1 (Arduino) = Pin 6 = Pitch CV Output
//
// PB5 set as digital output
// PB1 used as PWM output for Timer 1 compare OC1A
#define GATE    2  // PB2 (Pin 7) Gate
#define PITCHCV 1  // PB1 (Pin 6) Pitch CV

SoftwareSerial midiSerial(MIDIRX, MIDITX);

void setup() {
  // put your setup code here, to run once:
  midiSerial.begin (31250); // MIDI Baud rate

  pinMode (GATE, OUTPUT);
  pinMode (PITCHCV, OUTPUT);

  // Use Timer 1 for PWM output based on Compare Register A
  // However, set max compare value to 239 in Compare Register C
  // This means that output continually swings between 0 and 239
  // MIDI note ranges accepted are as follows:
  //    Lowest note = 36 (C2)
  //    Highest note = 96 (C7)
  // So there are 60 notes that can be received, thus making each
  // PWM compare value 240/60 i.e. steps of 4.
  //
  // So, for each note received, PWM Compare value = (note-36)*4.
  //
  // Timer 1 Control Register:
  //   PWM1A = PWM based on OCR1A
  //   COM1A1 = Clear OC1A (PB1) output line
  //   CS10 = Prescaler = PCK/CK i.e. run at Clock speed
  //   PWM1B is not enabled (GTCCR = 0)
  //
  TCCR1 = _BV(PWM1A)|_BV(COM1A1)|_BV(CS10);
  GTCCR = 0;
  OCR1C = 239;
  OCR1A = 0; // Initial Pitch CV = 0 (equivalent to note C2)
  digitalWrite(GATE,LOW); // Initial Gate = low
}

void setTimerPWM (uint16_t value) {
  OCR1A = value;
}

void loop() {
  if (midiSerial.available()) {
    // pass any data off to the MIDI handler a byte at a time
    doMIDI (midiSerial.read());
  }
}

uint8_t MIDIRunningStatus=0;
uint8_t MIDINote=0;
uint8_t MIDILevel=0;
void doMIDI (uint8_t midibyte) {
  // MIDI supports the idea of Running Status.
  // If the command is the same as the previous one, 
  // then the status (command) byte doesn't need to be sent again.
  //
  // The basis for handling this can be found here:
  //  http://midi.teragonaudio.com/tech/midispec/run.htm
  //
  // copied below:
  //   Buffer is cleared (ie, set to 0) at power up.
  //   Buffer stores the status when a Voice Category Status (ie, 0x80 to 0xEF) is received.
  //   Buffer is cleared when a System Common Category Status (ie, 0xF0 to 0xF7) is received.
  //   Nothing is done to the buffer when a RealTime Category message is received.
  //   Any data bytes are ignored when the buffer is 0.
  //

  if ((midibyte >= 0x80) && (midibyte <= 0xEF)) {
    //
    // MIDI Voice category message
    //
    // Start handling the RunningStatus
    if ((midibyte & 0x0F) == (MIDICH-1)) {
      // Store, but remove channel information now we know its for us
      MIDIRunningStatus = midibyte & 0xF0;
      MIDINote = 0;
      MIDILevel = 0;
    } else {
      // Not on our channel, so ignore
    }
  }
  else if ((midibyte >= 0xF0) && (midibyte <= 0xF7)) {
    //
    // MIDI System Common Category message
    //
    // Reset RunningStatus
    MIDIRunningStatus = 0;
  }
  else if ((midibyte >= 0xF8) && (midibyte <= 0xFF)) {
    //
    // System real-time message
    //
    // Ignore these and no effect on the RunningStatus
  } else {
    //
    // MIDI Data
    //
    if (MIDIRunningStatus == 0) {
      // No record of state, so not something we can
      // process right now, so ignore until we've picked
      // up a command to process
      return;
    }
    // Note: Channel handling has already been performed
    //       (and removed) above, so only need consider
    //       ourselves with the basic commands here.
    if (MIDIRunningStatus == 0x80) {
      // First find the note
      if (MIDINote == 0) {
        MIDINote = midibyte;
      } else {
        // If we already have a note, assume its the level
        MIDILevel = midibyte;

        // Now we have a note/velocity pair, act on it
        midiNoteOff (MIDINote, MIDILevel);
        MIDINote = 0;
        MIDILevel = 0;
      }
    } else if (MIDIRunningStatus == 0x90) {
      if (MIDINote == 0) {
        MIDINote = midibyte;
      } else {
        // If we already have a note, assume its the level
        MIDILevel = midibyte;
        
        // Now we have a note/velocity pair, act on it
        if (MIDILevel == 0) {
          midiNoteOff (MIDINote, MIDILevel);
        } else {
          midiNoteOn (MIDINote, MIDILevel);
        }
        MIDINote = 0;
        MIDILevel = 0;
      }
    } else {
      // MIDI command we don't process
    }
  }
}

void midiNoteOn (byte midi_note, byte midi_level) {
  // check note in the correct range of 36 (C2) to 90 (C7)
  if (midi_note < MIDILONOTE) midi_note = MIDILONOTE;
  if (midi_note > MIDIHINOTE) midi_note = MIDIHINOTE;

  // Scale to range 0 to 239, with 1 note = 4 steps
  midi_note = midi_note - MIDILONOTE;

  // Set the voltage of the Pitch CV and Enable the Gate
  digitalWrite (GATE, HIGH);
  setTimerPWM(midi_note*4);
}

void midiNoteOff (byte midi_note, byte midi_level) {
  // check note in the correct range of 36 (C2) to 90 (C7)
  if (midi_note < MIDILONOTE) midi_note = MIDILONOTE;
  if (midi_note > MIDIHINOTE) midi_note = MIDIHINOTE;

  // Scale to range 0 to 239, with 1 note = 4 steps
  midi_note = midi_note - MIDILONOTE;

  // Set the voltage of the Pitch CV and Enable the Gate
  digitalWrite (GATE, LOW);
  setTimerPWM(midi_note*4);
}

 

Permalink Leave a Comment

ATtiny85 MIDI Tester

January 25, 2019 at 10:28 pm (computers, music) (, , )

Having spent some time messing about with building simple synthesizer circuits, I’m putting together a simple MIDI to CV converter.  I have one using an ATtiny85 but think I’m struggling from the fact it is only using SoftwareSerial, so I plan to have another go with an ATtiny231w pretty soon now.

One thing I was missing though was a simple “hands free” MIDI tester.  Now it would be fairly simple to hook up my laptop or a keyboard to a MIDI cable and use that, but I wanted something I could just plug in and leave sending MIDI data out to whatever I was building.  So the idea of using a simple USB-powered ATTiny85 to creating a continuous set of MIDI note on and not off messages was born.

I’m using one of those cheap Digispark USB clones you can buy. I had no luck ever getting the USB programming side of it to work, (its supposed to be able to have the nucleus boot loader installed to provide a software USB implementation), but its easy to programme if you have an 8-pin DIL test clip, in my cased hooked up to a sparkfun tiny programmer.

2019-01-25 21.22.26

Basic design notes for the board:

  • P1 (equivalent to Arduino D1 and the ATtiny85 pin 6) has the built-in LED.
  • I’m using P2 as MIDI TX and P3 as (unused) MIDI RX (D2 and D3, mapped to ATtiny85 pins 7 and 2).
  • P0 (ATtiny85 pin 5) as a digital input with internal pull-up resistors enabled.

I’m using a simple MIDI out circuit from the Internet that shows:

  • DIN pin 5 – MIDI OUT signal directly connected to P2.
  • DIN pin 2 – MIDI ground.
  • DIN pin 4 – MIDI +5v via a 220R resistor.

The resistor was soldered inside an in-line female MIDI DIN socket.

2019-01-25 21.36.522019-01-25 21.42.10

A switch was soldered across from P0 to GND on the Digispark board.  The code will flash the LED when the switch is registered so you know you’ve done something.

That is pretty much it.

2019-01-25 21.51.47

2019-01-25 21.51.56

In terms of code, I just tested it with an increasing scale of a few octaves, with the switch being used to increase the tempo (by reducing the delay between notes). Of course, you can use whatever test pattern works for you.

My initial (simple) code below.

Important: You must “set the fuses” to use the internal 16MHz clock in order to get the MIDI baud rates for the SoftwareSerial implementation.

Kevin

// MIDI Code Test Generator using ATtiny85
// NB: Use Sparkfun USB ATtiny85 Programmer
//     Set Arduino env to USBTinyISP
//     Set 16MHz Internal Clock (required for MIDI baud)
#include <SoftwareSerial.h>

// Pin Mapping for DigiSpark USB/ATtiny85
//  P0 = PB0/D0 = Pin 5 Attiny85
//  P1 = PB1/D1 = Pin 6 - built-in LED
//  P2 = PB2/D2 = Pin 7
//  P3 = PB3/D3 = Pin 2 - wired to USB+
//  P4 = PB4/D4 = Pin 3 - wired to USB-
//  P5 = PB5/D5 = Pin 1 - wired to RESET
//
// Use the Arduino D numbers below (which are the same as Digispark P numbers)
#define MIDITX   2
#define MIDIRX   3
#define BUTTON   0
#define BLTINLED 1

// MIDI Parameters for testing
#define MIDI_CHANNEL     1
#define MIDI_LOWNOTE     36
#define MIDI_HIGHNOTE    90
#define MIDI_VELOCITY    64
#define MIDI_DELAYMAX    550
#define MIDI_DELAYMIN    50
#define MIDI_DELAYSTEP   100

#define MIDI_NOTEON      0x90
#define MIDI_NOTEOFF     0x80

SoftwareSerial midiSerial(MIDIRX, MIDITX);

int delayRate;
int buttonState;
int lastButtonState;
byte midiNote;

void setup() {
  // Switch will trigger HIGH->LOW
  pinMode (BUTTON, INPUT_PULLUP);
  pinMode (BLTINLED, OUTPUT);
  digitalWrite (BLTINLED, LOW);
  buttonState = HIGH;
  lastButtonState = HIGH;
  
  midiSerial.begin (31250); // MIDI Baud rate

  delayRate = MIDI_DELAYMAX;
  midiNote  = MIDI_LOWNOTE;
}

void loop() {
  buttonState = digitalRead (BUTTON);
  if ((lastButtonState == HIGH) && (buttonState == LOW)) {
    ledOn();
    delayRate = delayRate - MIDI_DELAYSTEP;
    if (delayRate < MIDI_DELAYMIN) delayRate = MIDI_DELAYMAX;
  }
  lastButtonState = buttonState;

  midiNoteOn (MIDI_CHANNEL, midiNote, MIDI_VELOCITY);
  delay (400); // Need note on long enough to sound
  midiNoteOff (MIDI_CHANNEL, midiNote);
  delay (delayRate);

  midiNote++;
  if (midiNote > MIDI_HIGHNOTE) midiNote = MIDI_LOWNOTE;
  
  ledOff();
}

void midiNoteOn (byte midi_channel, byte midi_note, byte midi_vel) {
  midiSerial.write (midi_channel+MIDI_NOTEON);
  midiSerial.write (midi_note);
  midiSerial.write (midi_vel);
}

void midiNoteOff (byte midi_channel, byte midi_note) {
  midiSerial.write (midi_channel+MIDI_NOTEOFF);
  midiSerial.write (midi_note);
  midiSerial.write ((byte)0);
}

void ledOn () {
  digitalWrite (BLTINLED, HIGH);
}

void ledOff () {
  digitalWrite (BLTINLED, LOW);  
}

Permalink 1 Comment

John Stump 1944-2006

May 28, 2018 at 8:03 pm (interesting, music) (, )

Whilst scanning  back through old posts, I found Adagio Cantabile with a rock tempo feel … describing a parody piece of music, designed to be unplayable, by John Stump.  However on following the links, it turns out that the Wikipedia page describing the work was deleted, with the deletion log effectively concluding:

Delete There is absolutely nothing to suggest this classical music spoof is notable enough for inclusion in an international encyclopedia.

Knowing what I know of music, human nature, parody and general good fun (and also some of what is included in said international encyclopedia), I couldn’t disagree more!  There are countless classrooms around the world with this piece of music on a poster on the wall and many a music student will know of it.  For that reason alone it should be included and a little of its history ought to be recorded.

Thankfully, where Wikipedia fails, a nephew of John Stump comes to the rescue.  You can read about the mischievous composer here on Greg’s Lost in the Clouds blog:

He had worked in the field of “music engraving” for most of his life, beginning in 1967, and I remember looking with fascination at his “music typewriter” in his office in my grandmother’s garage, so it didn’t surprise me that Uncle John would have created something like this fake musical piece.

Turns out he wrote two other satirical pieces, all three of which are preserved on the web site of  Bryan Higgins.  Here you can find:

Along with two other works in a similar vein by others:

(the rest of Bryan’s collection is worth a browse too – a bit of an eclectic collection)

Greg and Bryan, thank you for going where Wikipedia appears not to have the collective imagine to tread.  The Internet is a better place for it.

Kevin

Permalink Leave a Comment

ATtiny85 Synth from Jan Ostman

March 31, 2018 at 3:38 pm (computers, music) (, , , )

I’ve wanted to make a simple synth for a while and stumbled across the excellent DSPSynth site from Jan Ostman, which provides a range of designs for Euro-module compatible synthesizer modules.  One thing that really caught my eye was the CZ1 chip which implements the Casio Phase Distortion method of sound synthesis (I used to have a Casio CZ synth).  The chip is based on an ATtiny85 and the code is available as open source along with a circuit design here: https://janostman.wordpress.com/the-3hp-paperface-euro-modules/

Unfortunately, being a bit of an ATtiny85 novice, it wasn’t totally clear to me quite how to put this together from the bits and pieces I had lying around.  So this is by way of documenting how I got this doing based on the circuits and code from dspsynth.eu.

Note you can buy pre-built modules and kits from the site with proper pcbs and “paperface” front modules which all look very smart.  But as I was just tinkering I wanted to see how much I could get going myself.

And of course massive thanks to Jan Ostman for doing all the hard work and publishing the designs in the first place.

Building the Synth

Parts list for me:

I originally grabbed a couple of very cheap “ATtiny85 devboards” off ebay that include a micro-USB connection, but these turned out just to be a way of powering the boards, not programming them.  I tried using an Arduino as an in-circuit programmer, but in the end the Sparkfun programmer was so easy to use, I just use that now all the time.

dspsynth provides two circuits related to the CZ1 chip.  On the main HP3 paperface module page is a complete euro-module compatible circuit including power regulator and jacks for inputs and outpus.  In the “CZ1 manual” is a much simpler circuit that just shows a simple output stage as follows:

dsp-cz1

So I used this as my output side.  For the inputs, I took two 10k pots connected to the input pins via a 22k resistor each as shown in the full dsp paperface circuit (but without the jack connectors).

The whole thing was powered using the 5v and GND pins from one of those cheap USB “devboards” I mentioned, although I didn’t use that to host the ATtiny85 itself as they aren’t really breadboard friendly.  I did need a simple 8-pin socket adaptor to breadboard adaptor to seat the ATtiny85 nicely though.  Pics below.

2018-03-31 16.04.292018-03-31 16.05.112018-03-31 16.05.17

2018-03-31 16.03.58

Programming the ATTiny85

The source code is provided here: http://www.dspsynth.eu/files/code/pdvco.ino.  The official module uses the TinyAudioBoot system which allows you to upload firmware over one of the audio inputs.  I didn’t bother with that for my tinkering, so I was just loading the pdvco.ino source directly using the Arduino IDE and the Sparkfun programmer.

One thing that had to be done was “set the fuses”.  As I say, as a ATTiny85 novice, this took a bit of googling.  But it turns out all I really needed was to set the internal clock for the device to 16MHz (I uploaded the code without this step and there were some very interesting audio effects coming out of the thing – as you’d expect the digital to analogue conversion was all off sync).

If you select the right parameters in the Arduino IDE (ATtiny85; Clock: Internal 16MHz) and then select “burn bootloader” this has the effect of setting the fuses for the clock speed.  At this point, when the code fired up it all seemed to work and sounded a lot better.

Next Steps

Now I’ve had a bit of a play and an see what the ATtiny85 can do, I plan to explore some more of his designs.  Of particular interest is seeing if I can create a MIDI in to CV module using the principles in his USB MIDI to CV interface. But I want real MIDI so will be experimenting with the serial ports on the ATTIny85 (and worrying about getting MIDI to 5v input levels).

Once again, many thanks to Jan Ostman for publishing these designs and letting people like me have a play with DSP synthesis with such a cheap and available microcontroller from a starting point of relatively little knowledge about such things.

Kevin

 

Permalink 1 Comment

Long playing for 1000 years

December 10, 2016 at 6:29 pm (computers, music) (, )

I first stumbled across the Longplayer project when I saw a mention of their Longplayer for Voices on Kickstarter.  Then I completely forgot about it until Christian Payne (Documentally) mentioned that he’d caught up with the originator of the project on his long-form, email newsletter, ‘Backchannel’ at which point I looked it up again.

The project is great – a very long-term musical project (a bit like As Slow as Possible) conceived and composed by Jem Finer.  The one line summary is that he has recorded a sequence of music for some ‘singing bowls’ and the project combines various processed versions of this 20 minute piece in a range of different ways, resulting in a piece of music that will play continuously for 1000 years without repeat.  The long version can be found on the about page for the project (its worth a read).

To listen along, there is a live stream available from the website or listening stations in a couple of locations in London and San Francisco.  There are a series of live performances too where players play extracts of the piece.

And more recently there is now an iOS app that uses the same 20 minute piece, the same time-driven algorithm and a sense of shared time via the Internet to make the app play exactly the same part of the music available in the physical spaces and via the web.

The ‘score’ is a simple representation, with six concentric rings showing the sounds in six variations of the 20 minute piece.  But the algorithm behind Longplayer will play each ring at different speeds – with one of the rings taking 1000 years to complete.

There is a visual representation of the score with an indication of which part of each ring is currently playing.  This is available via the web and the iOS app.  The following show four stages of the app over a 24 hour or so period.

Notice how the second ring progresses the quickest, but some of the others hardly at all.  The third ring is the 1000 year ring, so over 24 hours there is no movement at all

2016-05-06 21.00.352016-05-06 23.15.362016-05-07 06.15.482016-05-07 13.13.332016-05-07 17.27.24

A great app, a great project and fascinating music!

Kevin

 

Permalink 1 Comment

MIDI Arp

December 1, 2015 at 11:17 pm (computers, internet, music) (, , , , )

I wanted to do something with MIDI and Arduino.  I’ve just picked up some cheap Arduino Nano Ethernet shields, based on the Microchip ENC28J60, so thought I’d combine the two.  The ENC28J60 and a cheap Arduino Nano makes for a very compact and economical Ethernet ready microcontroller and I have a nice Roland MT-32 Synth module gathering dust that I wanted to try again.

2015-12-01 21.16.05

My initial idea was to use MIDI to trigger sounds based on arp requests received by the Arduino, (hence the name MIDI Arp), but then decided that on my home network arp requests wouldn’t give a lot of variation, so I decided to see if I could trigger on the destination IP address of any packet received.

First I needed the MIDI interface.  I followed the simple circuit and example provided on the Arduino website, but wanted it all self-contained inside a MIDI plug rather than on a breadboard, so I soldered up the 220 resistor inside a 5 pin MIDI DIN plug as follows (MIDI pins are number 1, 4, 2, 5, 3 for some reason):

  • Arduino GND – Brown – MIDI Plug pin 2
  • Arduino 5v – Red – 220 Ohm resistor – MIDI Plug pin 4
  • Arduino TX (Pin 1) – Orange – MIDI Plug pin 5

This was then connected to the Arduino and the MIDI test programme showed that all works fine.

2015-12-01 21.16.212015-12-01 21.19.13

So, to the Ethernet side of things.  The following is an excellent starting place for the ENC28J60 based nano shield:

After reading this, I decided to use the UIPEthernet library as my starting point as I liked the idea of a plug-in replacement to the standard Arduino Ethernet library.  There was two major things to work out – first, how to set the device into some kind of promiscuous mode, assuming it supports it at all; second how to grab the destination IP address from any received packets.

From the ENC28J60 data sheet, the key register that controls the receiver filtering is the Ethernet Receive Filter Control Register – ERXFCON (see section 8 ‘Receive Filters’).  There are a number of modes for filtering and the UIPEthernet library is set up to filter for the unicast address associated with the MAC address configured for the module, for broadcasts, and to use the pattern matching filter to spot arp packets.  It turns out that to set the receiver into promiscuous mode, this register just has to be set to zero.

Now this is where things got lazy.  I just dived into the UIPEthernet library sitting in my Arduino library folder and hacked about. I might tidy this up one day and do it properly.

The low-level driver code can be found in utility/Enc38j60Network.cpp.  In the Enc28J60Network::init function, there is a line that sets up the ERXFCON register:

writeReg(ERXFCON, ERXFCON_UCEN|ERXFCON_CRCEN|ERXFCON_PMEN|ERXFCON_BCEN);

This needs to simply be changed to clear the register:

writeReg(ERXFCON, 0);

Next, how to store the destination IP address.  Again, simplicity ruled this one too.

The high-level interface to the library can be found in UIPEthernet.cpp and UIPEthernet.h.  I added two public functions and two private variables to the UIPEthernetClass class in UIPEthernet.h:

public:
  IPAddress lastSrcIP();
  IPAddress lastDestIP();
private:
  static uip_ipaddr_t uip_lastipsrc;
  static uip_ipaddr_t uip_lastipdest;

Then in the UIPEthernet.Cpp file, added the code to store the last source and destination IP addresses from received packets.

First, define a structure to dig into to the IP header (a bit of a layer violation, but I wasn’t after neat designs really).  Add the following after the definition of ETH_HDR near the top of the file.

#define IPBUF ((struct uip_tcpip_hdr *)&uip_buf[UIP_LLH_LEN])

Then add two (static) global variables to the file:

uip_ipaddr_t UIPEthernetClass::uip_lastipsrc;
uip_ipaddr_t UIPEthernetClass::uip_lastipdest;

Add two accessor methods to retrieve the last source and destination IP addresses (with appropriate conversion to the Arduino Ethernet friendly IPAddress format):

IPAddress UIPEthernetClass::lastSrcIP()
{
  return ip_addr_uip(uip_lastipsrc);
}
IPAddress UIPEthernetClass::lastDestIP()
{
  return ip_addr_uip(uip_lastipdest);
}

Finally add the code to save the addresses to the UIPEthernetClass::tick() function, on reception of a packet.

          Enc28J60Network::readPacket(in_packet,0,(uint8_t*)uip_buf,UIP_BUFSIZE);
          if (ETH_HDR ->type == HTONS(UIP_ETHTYPE_IP))
            {
              uip_packet = in_packet; //required for upper_layer_checksum of in_packet!
#ifdef UIPETHERNET_DEBUG
              Serial.print(F("readPacket type IP, uip_len: "));
              Serial.println(uip_len);
#endif
              uip_arp_ipin();
              uip_input();
              if (uip_len > 0)
                {
                  uip_arp_out();
                  network_send();
                }
                // Extra code added here
                uip_ipaddr_copy(uip_lastipsrc, IPBUF->srcipaddr);
                uip_ipaddr_copy(uip_lastipdest, IPBUF->destipaddr);
                // Extra code ends
            }

That should be all that is required to expose the destination IP address of any received packet via the UIPEthernet class (ok, breaking compatibility now with the standard Arduino Ethernet library).

The arduino sketch file now consists of the following:

/*
MIDI based on 
 http://www.arduino.cc/en/Tutorial/Midi

UIPEthernet Examples used for rest
NB: Requires hacked UIPEthernet Library!
 */
#include <SPI.h>
#include <UIPEthernet.h>
#include "IPAddress.h"

int lastIP;
int thisIP;

// Initialise note array with whole tone scales in octaves 3 through to 6
// C3 = 36
// C4 = 48
// C5 = 60
// C6 = 72
// C7 = 84
#define NOTES 24
int notes[NOTES] = {
  // C3  D3  E3  F#3 G#3 A#3
     36, 38, 40, 42, 44, 46,
  // C4
     48, 50, 52, 54, 56, 58,
  // C5
     60, 62, 64, 66, 68, 70,
  // C6
     72, 74, 76, 78, 80, 82
};

void setup() {
  //  Set MIDI baud rate:
  Serial.begin(31250);

  // Initialise the uIP and UIPEtherent stacks
  uint8_t mac[6] = {0x00,0x01,0x02,0x03,0x04,0x05};
  IPAddress myIP(192,168,0,6);
  
  lastIP = 0;
  thisIP = 0;

  Ethernet.begin(mac,myIP);
  
  // Initialise patch using program change
  // 32 = Synth 1, Fantasy
  midiCmd (0xC0, 32);
}

void loop() {
  Ethernet.maintain();
  IPAddress sip = Ethernet.lastSrcIP();
  IPAddress dip = Ethernet.lastDestIP();
  thisIP = 256*dip[2] + dip[3];
  
  if (thisIP != lastIP)
  {
    lastIP = thisIP;
  
    int note = (thisIP & 0xff) % NOTES;  // Scale to number of notes
    int vel  = ((thisIP & 0xff00) >> 8)/4;        // Scale to val between 0 and 64

    //Note on channel 1 (0x90), some note value (note), middle velocity (0x45):
    noteOn(0x90, notes[note], 16+vel);
  }
}

//  plays a MIDI note.  Doesn't check to see that
//  cmd is greater than 127, or that data values are  less than 127:
void noteOn(int cmd, int pitch, int velocity) {
  Serial.write(cmd);
  Serial.write(pitch);
  Serial.write(velocity);
}

void midiCmd(int cmd, int val) {
  Serial.write(cmd);
  Serial.write(val);
}

The final byte of the IP address determines which note from the array of notes to play (modulo the number of notes) and the third byte determines the volume to be used, scaled and with a minimum specified.

There is a control message to set the voice on the MT-32 to Synth1-Fantasy as this sounds suitably ambient. There are no note-off messages, so notes are allowed to keep ringing. As the note array defines four octaves of whole tone scales, the running-on notes create quite an interesting effect.

2015-12-01 21.40.12

There seems to be a regular drone set up, which I think is due to the IP address of my PC and router. These two addresses provide a sort of default back-drop of sound to anything else going on.

In order to get anything useful though, it would be no good just using a port on the router, as even the dumbest, cheap modern router will tend to do some MAC level filtering on ports. I had a laptop and the Arduino plugged into an old Netgear En104 4-port Ethernet hub, which has no intelligence (as far as I know) built in – so the Arduino could see everything coming out of the laptop.

The results were quite pleasing. Google has a nice enhanced drone to it. You can really hear the clutter of a site that is pulling in ads from all over the Internet – such as Amazon or YouTube or a news site.

Edited to add:  Here is a short video below showing them being opened.  It’s a bit crude but you get the general idea.

 Maybe next, I’ll see if I can do the same with a Wi-Fi link for the Arduino instead of wired Ethernet.  It might also be worth trying different scales and alternative mappings of notes to addresses.

Kevin

Permalink Leave a Comment

Rule 34 for Music

March 22, 2015 at 1:37 pm (music) (, , , )

If you’ve been around on the Internet for a while, you’ve probably heard of Rule 34, which I tend to paraphrase as “if you can think of it, there is porn of it” to which there is the corollary comment “if there isn’t yet, then there soon will be”.  Well, I think there is a version of Rule 34 for music, which could be stated thus:

If you can think of the style and the tune, then somewhere there exists a cover of that tune in that style.

In short, if you can imagine it, it probably exists on YouTube somewhere.  Here are some recent examples:

Red Hot Chili Pipers.  Think rock and bag pipes.  Particularly be sure to look at their covers of Smoke on the Water/Thunderstruck and We Will Rock You.

Andrea Vedrucci.  Covers just about anything imaginable from classical to game theme tracks.  Look out for the Mario Triology!

Dr Pez.  Guitar and accordion covers of a whole range of music.  Some of the game theme tunes are great!  Look out for Animal Crossing (Bossa Guitar and Accordion duet) and the Wii Shop channel (smooth jazz guitar and accordion).

Brett Domino. I’m sure I’ve mentioned Brett Domino before, but his covers of songs are amazing.  Look out for Bad Romance and the Justin Timberlake Medly.

You can even get technology in on the act.  Here are some drones performing the James Bond Theme.

As I said. If you can imagine it, there is probably a cover of it.  Google will almost certainly provide.

Kevin.

Permalink Leave a Comment

I’ll name that tune in …

January 14, 2015 at 11:10 pm (internet, music) (, , , , , , )

Whilst studying music at school some(mumble, mumble) years ago (pre Internet really) I remember there being an old book on the shelves alongside the vinyl recordings of classical music that fascinated me.  It was a music dictionary.  Not in the sense of a dictionary of music words, but in the sense of being a dictionary of musical themes.

Basically, how it worked, was you thought of a tune, transposed it to start on a C, and then spelt out the letter names of the tune and looked it up.  So, for example, the National Anthem would go CCDBCDEEFEDCDCBC once transposed, so you’d flick through for the C section, then find the entry CCD… and so on, as they were all listed in alphabetical order, and it would tell you it is the National Anthem.

There were tens of thousands of well known classical themes in that book and I always wanted a copy, but never, ever found one to buy.

As I started to find my way onto the largely textual Internet in the early 1990s, I always thought that this kind of thing would make a great website, but instead of typing in letter names, why not submit a MIDI file with the pitch values, do the transposition automatically and then return the results.  Of course, this never happened, it got binned in my “might think about it one day” pile and forgotten.

Well technology has a habit of spawning useful applications and of course, these days there are now a number of services that let you look up a tune by various means.  I heard a tune over a tannoy system today that I’m sure is a fairly recent pop song, but not one I know.  The kids didn’t recognise my poor rendition of it either, so I turned to the Internet.

If you have a mobile handy to record an extract, then you have a number of very good apps that will tell you what it is.  Shazam is one of the most popular, and available on the major platforms.  However, I belive it will only work for the actual legitimate recording of the song – I don’t think you can play the tune on a piano, for example, and ask it to recognise that.

However, musicpedia and MelodyCatcher do aim to do just that.  You can play in the tune on a virtual keyboard, creating the equivalent of the CCDBCD… above and if it recognises it, it will tell you what results have come back in its search. Musicpedia is best for classical themes whereas MelodyCatcher appears to support a wider range of styles.

But the applications that have given me the most entertainment this evening are WatZatSong and Name My Tune.  These both allow you to record and extract, post it on the site and wait until someone listens to it and posts and answer if they recognise it.  WatZatSong has a number of snippets of poor quality, but largely recognisable recordings.  There are people singing, playing guitar, capturing recordings on their phones.  And the site allows you to browse both submissions and answers and vote to agree or dissagree with the identification.

But nothing beats Name My Tune for shear entertainment value. It will only accept uploads via a microphone, and it is quite amusing listening to all the attempts at whistling, huming, singing in “la”s or “dum”s, playing on old casiotone keyboards, playing on a recorder, penny whistle … you name it.  I’m sure I heard a stylophone for one!  It is great!  The only downside is that it doesn’t have any of the social features of other sites.  You click though the sound clips (a bit like a one-way, audio version of chatroulette) and if you know one, can fill in the author and title and click “send” and off it goes on its merry way.  There is no way to know if you were correct or satisfied the questioner’s query as far as I can tell.

But if you want a peculiar way to spend an evening, that is guaranteed to make you smile, do take a look.  It was quite a lot of fun.

But I still don’t know what my tune is …

Kevin.

Permalink 1 Comment

Gareth Wood and Gilbert Vinter Music for Brass Band

May 18, 2013 at 3:01 pm (music) (, , , , , , , , )

It’s been a while since I played in a brass band, but one lasting memory is the dedicated concentration you’d find coming up to a competition. A singular focus on a single piece of music to get it sounding the best it could possibly be. There are lots of composers of brass band “test pieces” but two of my personal favourites are Gareth Wood and Gilbert Vinter, largely because their music is very descriptive, interesting to play and interesting to listen to. Their writing doesn’t feel like music that is written just to test the band, but music to convey an idea.

These days there are lots of modern composers writing for brass band or wind orchestra who write in this symphonic, thematic way, but 20 odd years ago there was still a lot of arrangements of classical music being used in contests. I personally don’t have any decent recordings of many of these works, but in the days of the Internet, YouTube can provide.

Except when it can’t!  I’ve looked everywhere I can think of so far and can’t a recording of my favorite Gareth Wood piece – The Margam Stones, so I’ve had to upload a slightly dodgy MP3 from tape from tape from tape from vinyl recording that I’ve had for ages.  The playing quality is not bad, but there are a few dodgy moments and the sound is very wobbly, so I’m not sure it really does the piece justice, but it’s all I have for now.  If you know of a better recording, please let me know!

I also couldn’t find a recording of Variations on a Ninth by Gilbert Vinter, so again I’ve uploaded a slightly better, but still a bit iffy version of that too.

So here, with links to videos, are my favorite Gareth Wood and Gilbert Vinter pieces, all of which I’ve been fortunate to play at various times (although not all in actual performances).

Gareth Wood

Gilbert Vinter

All amazing pieces of music from two very talented composers.

Kevin.

 

Permalink Leave a Comment

Next page »