Jump to content
IGNORED

MidiJoy - Using your Atari as a Chiptune-instrument


freetz

Recommended Posts

Dear all,

 

I'd like to open this thread on my recent development "MidiJoy" because the topic of the thread which led to its inception is now only merely loosely connected to what has come out of it. I'll begin with posting some general information on MidiJoy, afterwards I'm looking forward to questions, comments and bug reports here :).

 

The most up-to-date information will probably always be on my website: http://www.phobotron.de/midijoy_en.html and a video introducing the basic idea of MidiJoy is available on YouTube.

However, the software will only be available after the ABBUC hardware contest in which MidiJoy is participating (this is part of the competition's rules). Of course I'd be glad if you vote for it in the contest, and if it should make it to the Top 3, I'd make MidiJoy available for free afterwards :).

 

Enjoy,

 

F.

  • Like 4
Link to comment
Share on other sites

Introduction

 

MidiJoy is a software that makes the Atari 2600-PC-Interface created by Sebastian Tomczak compatible with Atari home computers.

The interface emulates a USB-Midi (serial Midi is optional) device that can be accessed by any kind of instrument as well as sequencer software on a PC or Mac that can output Midi data (e.g. Ableton Live). MidiJoy receives these data from the interface via the joystick ports and plays them on the POKEY sound-chip. In contrast to most SIO-based Midi interfaces, a MidiJoy-driven Atari can bei used as a live instrument in real time with up to four sound channels simultaneously. At the same time, all POKEY parameters (AUDCTL, AUDC1-4) can be changed on-the-fly fly, or you could activate ADSR envelopes while playing. Music input can be recorded and saved to disk for later usage - even in your own programs/games.

 

The source code for the Teensy board (an Arduino offspring) interface is available as open source as the basic idea is based on Sebastian Tomczak's interface. The adapted code is very simple and just converts incoming Midi data into bit combinations that are sent to the Atari via its joystick ports. The software on the Atari end makes full use of the capabilities of the Atari's POKEY sound chip and thus partly extends the features of the Atari 2600-interface: Instead of just two voices with a 32-pitch range of the TIA, MidiJoy enables you to make full use of four voices spanning four octaves. Two 16-bit channels are also possible, and with corresponding POKEY frequencies, a much larger range of sounds can be created. The playback of samples - such as with the original interface - is on the development roadmap of MidiJoy.

Link to comment
Share on other sites

The Interface

 

Due to the more powerful POKEY soundchip compared to the 2600's TIA, the setup of the orignal interface - for which all credits go to Sebastian Tomczak - as well as the Teensy code need to be adjusted in a few ways in order to use them on these home computers. The following images show the design and wiring used by MidiJoy:

 

InterfaceFullSize_small.jpgInterfaceConnected_small.jpg

Link to comment
Share on other sites

Setting Up the Interface

 

The interface can be assembled without any soldering or using old joystick cables.
To do so, one needs:

  • A Teensy 2.0 Board with pin-header
  • Two DB-9 breakout boards (f) for breadboard use
  • One full-size breadboard
  • 11 cable connectors (m/m) for connecting the Breadboard and the DB-9 ports
  • Optional: two fully patched DB-9 extension cables (m/f) in case you don't want to plug the DB-9 connectors right into your Atari

When all parts are obtained, simply plug the Teensy board as well as the DB-9 breakout boards into the breadboard. If you use a full-size breadboard, make sure that the DB-9 ports are in the right distance so they fit into the computer's joystick ports. In that case you would also have to remove the shoulder screws for the ports to fit in.

 

Once this is done you only need to connect the pins of the Teensy board to the DB-9-connectors:

Atari Player 1 Pin 1 ---> Teensy Port B0 (digital pin 0)
Atari Player 1 Pin 2 ---> Teensy Port B1 (digital pin 1)
Atari Player 1 Pin 3 ---> Teensy Port B2 (digital pin 2)
Atari Player 1 Pin 4 ---> Teensy Port B3 (digital pin 3)
Atari Player 1 Pin 6 ---> Teensy Port B7 (digital pin 4)
Atari Player 1 Pin 8 ---> Teensy Ground

Atari Player 2 Pin 1 ---> Teensy Port F4 (digital pin 19)
Atari Player 2 Pin 2 ---> Teensy Port F5 (digital pin 18)
Atari Player 2 Pin 3 ---> Teensy Port F6 (digital pin 17)
Atari Player 2 Pin 4 ---> Teensy Port F7 (digital pin 16)
Atari Player 2 Pin 6 ---> Teensy Port B6 (digital pin 15)

Pins 7 and 8 (D2 and D3) on the Teensy board are optional and can be used to connect a "classic" serial Midi board, the schematics can be found here. When installed, you could use both USB- as well as serial Midi devices at the same time.

 

After the interface is fully assembled, the Arduino development environment including the Teensyduino extension needs to be installed on the Mac or PC. With this program, the source code can then be flashed on the Teensy. Once this is done, the interface should be detected by the Midi sequencer software on the Mac/PC. Then the interface can be connected to the Atari and MidiJoy can be started.

Link to comment
Share on other sites

Using MidiJoy on the Atari

 

MidiJoy.jpg

 

When you have connected the interface to both the Mac/PC and the Atari has booted into MidiJoy, you are ready to play music on your Atari by sending Midi notes from the Mac/PC to the interface. A simple equalizer will give you visible feedback as well.

All incoming data will be adjusted correctly to the Atari note table and then played immediately. As far as possible, proper scales are used also in distortion modes 2 and 12. Pressing the SPACE key switches between two different scales in mode 12.

 

Incoming Midi data is expected on Midi channel 1 to 4. These are then played through the corresponding sound channels on the Atari. Midi channel 1 is special: here, up to four voices are being split up automatically to unused sound channels on the Atari. This enables playing multi-chords with up to four voices in real time, for example via a Midi keyboard connected to the Mac/PC. Five or more voices will overwrite the last used channel.

 

You may use your own ADSR envelopes (see next post) during live playback by activating one of them by pressing keys 1 to 8. Envelope data needs to be loaded prior to starting MidiJoy (e.g. via DOS).

 

Keys O to I control the eight bits of the AUDCTL register. This enables making live use of all POKEY features such as filters, 16-bit voices or frequency changes. Like with sound programming in general, only certain combinations make sense. For example, it is advisable to set POKEY's frequency to 1.77 MHz (bits 5 and 6) when using 16-bit voices (bits 3 and 4 respectively).

Individual channels can use different distortions (AUDC1-4). These can be set using keys A to D, F to H, Z to C and V to N. The status of each bit is displayed on the screen.

 

The tabulator key starts and stops the recording mode. Pressing RETURN resets all recordings, for example to start anew.
While recording, all incoming note data is saved to RAM and can then be played back using the P key (after recording is stopped). A counter displays the memory area used by the recording. This area can afterwards be saved for later use by jumping into DOS (J key) and use the "Save Binary File" function there. This of course requires that MidiJoy has been started with DOS in the background - simply booting the executable from a game DOS or SD-card will not allow you to save your recordings!

 

Take note that when you enter recording more, also the silence until the first note value comes in is recorded. So if you press TAB and only then start to boot your Mac/PC, you'll have a long(er) silence at the beginning when you later start to play the recording.

Link to comment
Share on other sites

ADSR Envelopes

 

MidiJoy supports ADSR (Attack/Decay/Sustain/Release) envelopes both for live performance as well as for playback. In order to allow for maximum flexibility, envelope data can be loaded on a case-by-case basis and can also be exchanged with other users of MidiJoy.

 

An envelope data block consists of 256 bytes ($00 to $FF) which can be used in variying proportions for the ADS- as well as the Release-phases of each voice. Each byte modifies the volume for 1/50 second (1/60 on NTSC machines). ADS values range from 0 to 15 and reduce the note's volume, i.e. a value of zero leaves the volume unchanged whereas a value of 15 will always silence it. In the release phase it is the other way round: values here will be added to zero (although not exceeding the last volume value), i.e. a value of zero is silence and anything above will result in the voice still being played / faded out.

 

An envelope file (see here for a sample structure) has to start at $4F00 and begins with four index/offset bytes pointing at the start of the ADSR-data for each voice. These four bytes are followed by a fifth byte indicating the position after the end of the fourth voice's Release-phase.
Actual ADSR-data begins with a status byte containing the length of the subsequent ADS-phase, followed by the ADS-envelope data. The last byte here is special: it indicates whether the sustain phase should be repeated from an earlier position onwards which is useful if you want to create a vibrato and keep it going indefinitely as long as the key is being pressed.
To do that, this byte contains the number of bytes the envelope counter should 'rewind'. A zero means the volume will remain at its last level, otherwise the counter will be set back by the number specified here. Take note to count this 'rewind' byte into the status byte as well.
Following the 'rewind' byte is the Release-phase data up to the beginning of the next voice's ADSR-data.

 

In order to use ADSR envelopes you simply need to load a file containing the envelope data in the prescribed format to address $4F00 prior to launching MidiJoy or one of the playback programs. The separation between note data and envelope data allows you to record music and add or change the ADSR envelope at a later stage, giving you all the flexibility you need.

 

If you want to use multiple envelopes during live performance, there are eight slots available from $3400...$34FF up to $4B00...$4BFF where envelope data can be stored and selected with keys 1 to 8.

 

Example sound files demonstrating the difference between a track with and without ADSR envelopes can be found here and here.

Edited by freetz
Link to comment
Share on other sites

Recording format

 

The recording format is kept very simple and consists of five bytes per incoming Midi data:

  • Byte 00: Sound channel on the Atari
  • Byte 01: AUDCx value (distortion und volume)
  • Byte 02: Frequency (AUDFx)
  • Byte 03: Duration until note is played in 1/50th seconds (low-byte)
  • Byte 04: Duration until note is played in 1/50th seconds (high-byte)

Tracks with many simultaneous notes which are played very quickly therefore create a much larger memory footprint than fewer, longer notes. If no note (or pause) is longer than five seconds, then the high-byte can be omitted when parsing the recorded file. Similarly, when distortion is always the same, the sound channel and the volume could be written into four bits each. Both changes would require changes in the playback routine, but would also almost reduce the amount of data by half.

 

ADSR envelope data is not part of the recording, but ADSR envelope files can be loadad prior to playback.

Edited by freetz
Link to comment
Share on other sites

Playback

 

Two small playback routines in assembler will be available for free, one for playback using VBI (as in the demo disk above) and one without using interrupts. Both can be accessed from BASIC as well. They are less than 256 bytes in size and thus fit nicely into page six for example.

 

There is a demo disk on my homepage available as well which demonstrates the playback of MidiJoy sound files in BASIC as well, simply boot into DOS with BASIC enabled, load the .EXE file and jump back into BASIC. In BASIC you can start playback with

X=USR(1536,20480,40000)

(in your own songs, the second and third parameter must match the note data RAM area as displayed in MidiJoy). To stop/pause simply enter

POKE 207,0:FOR X=0 TO 3:SOUND X,0,0,0:NEXT X

and continue playing with

POKE 207,1

A third playback routine has ADSR envelope playback enabled. As it is too large for storing it in Page 6, it is generally advisable to use it in machine language programs only.

 

Due to the ABBUC hardware contest rules, the source code for the player can only be made available after the contest at the end of October.

Edited by freetz
  • Like 2
Link to comment
Share on other sites

It's a bit difficult to measure as for example with a Midi-Keyboard hooked up to a PC which is then in turn connected to the Atari, latency is induced already at the first link. What the source code of the Teensy can tell you is that each note information is held for 3000 microseconds, i.e. 3 milliseconds, i.e. 0,003 seconds. Each note consists of two bytes, one for pitch and one for volume, so it is 0,006 seconds per note and thus 0,024 seconds between the volume information of the first note and the pitch information of the fourth note in a four voice chord.

Shorter periods of time would be possible (the original interface worked with 30 microseconds!), but that program basically didn't do much else rather than POKEing the incoming values into the sound registers.

But as I said, this is just the ATARI side of the equation, the latency between the PC/Mac and the interface is out of my reach...

Link to comment
Share on other sites

Needless to say, if you use ASIO4ALL (which is a Midi setup on PC that reduces latency) in your DAW, or if you go to something else non-PC such as an Atari ST, or a hardware sequencer like the Alesis MMT-8 (like I have) then latency is not an issue at all.

 

Question: Would a function on the Atari side to set the MIDI channel so only notes registered with a certain MIDI channel get played on the Atari?

Link to comment
Share on other sites

Wow, this is fantastic! Very nicely done indeed. I'm going to have to put one of these together for my studio. I've loved the Atari Pokey sound since the first time I saw an Atari 8-bit back in 1980. And I have lots of Atari 8-bit computers lying around doing nothing.

  • Like 2
Link to comment
Share on other sites

@Synthpopalooza: I use ASIO4ALL on my PC setup, but still I had issues with a little bit of latency - not all too much, but could be recognized when recording vocals at the same time. But this may just be my setup. In the rather simple setup that I used for testing MidiJoy (Keyboard - Mac (Ableton) - MidiJoy) there was no noticeable latency whatsoever.

 

Regarding the MIDI channel, this can be done one the DAW-side, at least with Ableton: When you set one track to output on Midi Channel 2 to 4, this track will be played on the Atari on voice 2 to 4 accordingly. Midi Channel 1 is of course still played on voice 1, so as long as you don't have multiple notes at the same time on channel one (which would be automatically mapped to voices 2 and above on the Atari), you could have up to four different tracks on the DAW which map to four individual voices on the Atari which in turn can be configured individually in terms of distortion. Because of this approach, I'm not sure what difference it would make if I add a filter function on the Atari to play a certain Midi channel only.

Edited by freetz
Link to comment
Share on other sites

One possible use of this function, is that I do multitracking when I do my recordings, and sometimes I layer my instruments ... so ideally, let's say I am doing a synth pad or some other track that requires chords or notes played all at once, on MIDI channel 1, it'd be good to also be able to set the Atari so that all the voices are also playing on that same channel for layering purposes. There would need to be a cycling algorithm I guess, so that if 5 notes are active at once, the one hit first would be the audio channel that gets silenced.

 

I'm still old-school with my setup, and my hardware sequencer only puts out to one channel at a time.

Link to comment
Share on other sites

@Synthpopalooza: I use ASIO4ALL on my PC setup, but still I had issues with a little bit of latency - not all too much, but could be recognized when recording vocals at the same time. But this may just be my setup. In the rather simple setup that I used for testing MidiJoy (Keyboard - Mac (Ableton) - MidiJoy) there was no noticeable latency whatsoever.

 

Regarding the MIDI channel, this can be done one the DAW-side, at least with Ableton: When you set one track to output on Midi Channel 2 to 4, this track will be played on the Atari on voice 2 to 4 accordingly. Midi Channel 1 is of course still played on voice 1, so as long as you don't have multiple notes at the same time on channel one (which would be automatically mapped to voices 2 and above on the Atari), you could have up to four different tracks on the DAW which map to four individual voices on the Atari which in turn can be configured individually in terms of distortion. Because of this approach, I'm not sure what difference it would make if I add a filter function on the Atari to play a certain Midi channel only.

Channel filtering/transposing may be better suited on the Arduino side, it is doing the midi decoding. Perhaps either using CC or PC messages to set an offset from the default channel mapping; either a shift of all 4 or on a channel by channel basis (more complex).

Something along the line of a channel offset nibble that is subtracted from the incoming Channel nibble of the Status byte. 0 would be default; a value of 3 would shift a message on channel 5 to be processed as a Pokey Voice 2 message. A value of 13 would shift a Channel 0 message to Pokey voice 3.

Don't know if this would be out of scope for the contest deadline, but when I get a little time I'll mess with the .ino

Yogi

Link to comment
Share on other sites

Hello Freetz

 

Since MIDI can be used to control more then one instrument, would it be possible to use more then one Atari at the same time?

 

Sincerely

 

Mathy

 

PS my musical talent is limited to recognizing songs and instruments and some of their players, so I'll probably never use your interface. But Synthpopalooze's posting triggered this question.

Link to comment
Share on other sites

Hello Freetz

 

Since MIDI can be used to control more then one instrument, would it be possible to use more then one Atari at the same time?

 

Sincerely

 

Mathy

 

PS my musical talent is limited to recognizing songs and instruments and some of their players, so I'll probably never use your interface. But Synthpopalooze's posting triggered this question.

Yes, it would be possible to have 4 Atari/Arduino interfaces with each assigned to 4 channels: first one on channels 0-3, second on channels 4-7 and so on. Or for a thick sound, more then one atari on the same channels but detuned from each other ( as can be done with duel Pokeys in a single Atari).

Yogi

  • Like 1
Link to comment
Share on other sites

@Synthpopalooza: I'm still not sure if I get what you need, but if you send a chord on Midi channel one (which is specifically set up for this purpose), it will be automatically split up to the four available channels, with a maximum of four simultaneous notes of course. Once one voice slot becomes vacant, a new chord note will fill it up. This is different to Midi channels 2-4 where only one note is played at a time. This is necessary in an environment where you want to use distortion on one channel and pure tones on another, with each Midi channel assigned to one specific distortion.

If I still didn't get that right, I'm sorry ;). But in any case, the Atari and MidiJoy does know nothing about the Midi channel a note comes from - the assignment Midi channel -> Atari voice is done in the Arduino and would have to be changed there. A solution as Bill suggested by using CC or PC messages would be easy to implement as it would just require to add a function doing what it should do, as long as the output to the Atari sends the actual voice channel to be used on the Atari. This is necessary as I have to reduce the processing time on the Atari as far as possible in order not to drop notes while processing. And I'm already hitting a boundary here ;)...

  • Like 1
Link to comment
Share on other sites

@Mathy: Yes, it is possible the way Bill has already described. It's just the Teensy code that would have to be adapted slightly, and I'll adjust the source in a way that one would only have to change a variable in the beginning of the code. Good idea :).

But don't hold yourself back from assembling the interface just because you think you don't have enough music experience! Actually one reason I came up with MidiJoy is the fact that you can play so many existing Midi tracks from the PC on the Atari and record them for later use on the Atari. So next time you need a nice title or background tune for a game or so, you could create it with no knowledge of music or music programming at all. I think I have to stress this feature a bit more so that people don't think that this is a setup for music buffs only ;)...

  • Like 1
Link to comment
Share on other sites

  • 4 weeks later...

Unfortunately, I can't edit my previous posts anymore, so I'll have to add this missing information here:

It is also possible to change the distortion within the ADSR envelopes. Bits 5-7 of each ADSR-envelope byte sets the distortion of that specific time-frame. Otherwise, if it's not set, the standard distortion set for this channel is used. With this feature one can create a whole lot of new instruments by mixing different "clean" and "noisy" distortions while at the same time adjust their volume pattern in steps of 1/50th or 1/60th of a second respectively (PAL/NTSC).

It would be awesome if people would eventually upload their envelope-"instruments" so others can see what the POKEY is capable of :). Just a few more days until the competition's result are announced and I can offer MidiJoy to the public...

  • Like 2
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...