[Coco] SSC & MIDI
Bill Pierce
ooogalapasooo at aol.com
Sun Jun 22 11:41:35 EDT 2014
Are you using the Lyra file format or the standard MIDI format for your song file storage?
The Lyra format is a propriety format and has to be "interpreted" into midi code before playback, which if you're using that, you've already got some sort of engine for that. But, the raw standard Midi format can be sent straight to the dw4 MIDI port without any translation therefore saving tons of processing time (and MUCH shorter code).
The only thing that the Coco has to change in the Midi protocol is the timing. The timing stored in the standard midi file (SMF or ".mid"), is stored in a "run-length" variable. This meaning the timing values can be anywhere from 2 to 4 bytes long. The further into the song, the longer the value. Also, the Coco clock is much slower than what Midi expects, so the timing value is converted from 24 clocks per quarter note to 48 clocks. The timing is just the delay between note lengths, so that's all on the software side and has nothing to do with anything sent to MIDI. Only the raw Midi data is sent to the port.. at the appropriate timing intervals.
Lyra uses a software delay loop to create the delay. Mike Knudsen developed a better (more stable) way to do this in Ultimuse3 in OS9. Since OS9 literally runs on the "clock" to determine it's interrupt intervals for multiple processes, the clock module in OS9 keeps accurate timing relevant to whatever type of clock hardware is being used (IE. RTC, Dw, software, etc). In UME3, Mike accesses the system DAT to retrieve the system clock value, then determines if it's changed since the last access, then determines if it needs to wait until the next note and "sleeps" until then. If I remember right, he uses an 16 bit value for the counter, then a single byte for "rollover" counts.
In reality, the MIDI spec offers MUCH more than just "playing notes" and is very much an OS within itself if used as such. MIDI has thousands of command sequences designed for much more than "playing music". It can control almost any "available" parameter of a MIDI synth such as reverb, delay, pitch bend, attack, sustain, decay, program change (instrument), ect. Of course the synth used determines what is supported, but MIDI provides a means if it's available. MIDI also has another cmd set called "MMC" or "MIDI Machine Control". This protocol was originally created to control tape machines and such in the studio so they could be sync'ed to operate with the MIDI sequencers, but eventually expanded into almost every piece of pro audio equipment made. Almost every piece of audio gear in my studio can be controlled by MIDI including my stage light system that I use for live shows. Actually, now that the average PC with it's massive memory and cpu power can run MANY tracks of recorded PCM samples and produce "real" music, MIDI music is usually only used through "Virtual Instruments" or to control other equipment such as EQs, Reverbs, Multi-FX units. recorders etc.
But anyway.... I can give you code examples of how to create MIDi timing without the use of Lyra or Ultimuse3's propriety formats and use direct raw MIDI data to create compact song formats that take up much less room on the Coco and work much more efficiently. Also, I have code that will allow the use of MIDI on the VCC 1.4.3b TCP port. There's slight differences in using DW4 MIDI and Becker Port MIDI under RSDOS. In NitrOS9, the drivers already adjust for the differences.
If I wasn't so tied up in my "MShell" project, the project I would now be working on is a full blown MIDI sequencer for the Coco and Nitros9 that uses standard MIDI files and format. I have started several "layouts" for such software and even have a few routines started, but got involved in writing the MShell code so I archived it for now. I hope to revive that project soon since I'm stuck on a DW4 driver bug which is plaguing part of MShell's development. Until the dw4 bug is fixed in Nitros9, MShell is destined to be an "OS9 only" utility with support for dw4's drive systems only and little to no v-port support.
Let me know offlist if you're interested in any of the Coco MIDI stuff I've collected.
Bill Pierce
"Today is a good day... I woke up" - Ritchie Havens
My Music from the Tandy/Radio Shack Color Computer 2 & 3
https://sites.google.com/site/dabarnstudio/
Co-Webmaster of The TRS-80 Color Computer Archive
http://www.colorcomputerarchive.com/
Co-Contributor, Co-Editor for CocoPedia
http://www.cocopedia.com/wiki/index.php/Main_Page
E-Mail: ooogalapasooo at aol.com
-----Original Message-----
From: jmlaw <jmlaw at iprimus.com.au>
To: coco <coco at maltedmedia.com>
Sent: Sat, Jun 21, 2014 10:43 pm
Subject: [Coco] SSC & MIDI
As the SSC & MIDI topic has come up, I’ve posted some info on my current
project at the facebook group.
The background is I’m trying to do a 60 fps 1 & 2 pixel horizontal scrolling
Super Mario Bros demo (may lead to more later). My focus isn't so much on
cloning it as I am wanting to learn about game programming, and it's a great
case study for that with lots of info online. That said, I do intend to try
to make it as accurate as I can. With the tile updating, managing four
pages, software sound just wasn’t going to be enough to keep the frame rate
up, so I’ve had to consider some alternatives. Namely the SSC & DriveWire 4
MIDI.
Now that you’re moving to tiles Nick, maybe something to consider if you
haven’t already?
So here’s a copy of that for anyone not in the group who may find it
useful/interesting or whatever. Maybe it'll come up in someone's Google list
search some day...
***********
I've been working with the Speech & Sound Cart for the Mario demo background
music (BGM). Studying everything I could find on Nintendo Entertainment
System (NES) music has taught me heaps about how to apply software envelopes
to the SSC generated tones to get a near-perfect NES sound. Though using
software envelopes you could probably emulate the sounds of many other
systems too.
Not everyone has a SSC so I've also spent some time studying Aaron Wolf's
DriveWire 4 MIDI. I moused a short score of the Overworld theme BGM in
Robert Gault's modified version of Lyra and via Vcc 1.43b (Becker port) and
with the aid of the DriveWire spec, I've learned enough to have it sounding
the notes from my own code, but the timing was off. Knowing I'd have to
write the code to play the BGM which controls the timing by frame (vsync
interrupt) I figured I'll do the SSC first then work out the timing for
DriveWire MIDI in relation to that. DriveWire MIDI via the Becker Port and
the SSC work in a very similar way so it's ideal. I wasn't going to mention
this yet until I'd done it all, but it's come up on the mailing list, so I
may as well
A few hiccups:
The SSC requires a delay before sending a command after a reset or it will
be ignored. Unless I missed this, it's not documented anywhere. From my
tests, testing the status doesn't work in the usual way after you first
reset the SSC. I've narrowed it down to 285 cycles after a reset before the
SSC is actually ready for commands. 284 cycles you just get allophones for
the tone data sent as it ignores the direct access to the AY-3-8913 command.
My SSC model is the 26-3144A. I've sent Simon my test binary for the delay,
he has the other model and it still works with a 284 cycle delay so it may
be there's a ROM difference between the models?? A simple delay loop after a
reset fixes this problem. I've extended the delay above 285 cycles just to
be sure.
I also had trouble opening the DW4 MIDI channel. I was using the quick
version of the command, but could not get it to work after four nights of
trying. Maybe I misinterpreted the spec, but the longer open channel command
worked perfectly first go. What a relief
I have the main melody square 2 (SQ2) channel playing from my own code to
the SSC, I have one more thing to fix then it's add the harmony (SQ1), the
baseline (TRI) and percussion noise (NOI) channels. A few things to work out
but should hopefully have a sample wav, a few more pics & a vid soon.
In the waveform pic, the top channel is the SQ2 NES, the lower the SSC. This
was just my first test. The background noise is greatly exaggerated as I
maximized the volume in the SSC recording to compare it to the NES recording
in Audacity (I have to adjust my envelopes). The VU meter in the Mario pic
is working for the SQ2 channel, the others are just displaying test values
until I write the code to play those. They all update per frame and work in
MESS & Vcc too, which is great considering the timing required to run them,
thought I'd have issues with that.
Ah and playback at 0.89 MHz as I haven't modified my SSC for the CoCo 3 when
run at 1.78 MHz yet, so you can play the BGM on a CoCo 2 also. A
semi-graphics VU meter of a similar style would be fairly simple in
comparison.
So yeah, that's what I've been up to since the Mario scrolling vid, (link in
the comments of post with the level editor if you missed it).
***************
I'm not claiming to be an expert on any of this by any means, I'm just
learning it myself and sharing what I've leaned to date. If I'm wrong feel
on any of it feel free to set me straight :) This is just my experience.
Bill Pierce is far more knowledgeable on MIDI than I am, I'm just having a
go.
Thanks heaps Aaron for the DW4 and the MIDI and the Vcc Becker port, it
opens up some really nice options for game background music, maybe even the
sound effects, not sure haven't got that far yet. I'm a bit worried there
may be some noticeable lag re the latter but lets see...
Thanks RG for the Lyra DW4 MIDI mod, helped a lot initially.
Thanks Bill Pierce for the music/MIDI info on your site, first place I
started when looking into this :)
Peace :)
--
Coco mailing list
Coco at maltedmedia.com
http://five.pairlist.net/mailman/listinfo/coco
More information about the Coco
mailing list