MIDI Audio:

Using, learning, programming and modding the Gigatron and anything related.
Forum rules
Be nice. No drama.
User avatar
marcelk
Posts: 488
Joined: 13 May 2018, 08:26

Re: MIDI Audio:

Post by marcelk »

I have the nagging feeling that the low-pitch noise might be caused by the mismatch between 521 scan lines and 4 sound channels. Every 16.7 ms there will be an interval of 5, not 4, scan lines that are together producing a sample. That can and will overflow. The solution I had in mind is that the video loop injects an additional sample reset at the right time, namely after the first of those five. The ROM indeed does something like that but I think I mistimed that reset and it happens 1 scan line too late. That could easily cause a 30 Hz noise... Just theory (it doesn't match all observations yet...) but it will be easy to test and I'll put it on my todo list.

The high-pitch noises are aliasing effects that are almost impossible to avoid with this 4-bit DAC, the simplistic waveform generation and a low sample rate. I was secretly hoping that the high pass filter takes care of most of it, but it doesn't help much. Here is some explanation: https://theproaudiofiles.com/digital-audio-aliasing/ so no real hope of getting rid of it with the current synthesis.
Cwiiis
Posts: 27
Joined: 14 May 2018, 09:04

Re: MIDI Audio:

Post by Cwiiis »

at67 wrote: 24 May 2018, 11:50 I've updated the Gigamidi tool and the Gigatron's MIDI specification, here's a link to a .gt1 file that uses the new specification; it contains three separate MIDI tracks and a game-over stream, it also runs on Phil's emulator so it should work fine on 32K hardware.

Tetris MIDI sample:
https://www.dropbox.com/s/vrz3p65124she ... s.gt1?dl=0

Gigatron MIDI documentation:
https://github.com/at67/gigatron-rom/tr ... r/Emu/midi

Unlisted video, I don't want copyright strikes.
https://youtu.be/I9A3fj4FB7M
Haven't gotten round to checking this out yet, but I will :) The bassline of the MIDI in that video is off, I remember it being correct in the last one - a new issue, or am I just misremembering?
at67
Site Admin
Posts: 647
Joined: 14 May 2018, 08:29

Re: MIDI Audio:

Post by at67 »

Cwiiis wrote: 25 May 2018, 09:41 Haven't gotten round to checking this out yet, but I will :) The bassline of the MIDI in that video is off, I remember it being correct in the last one - a new issue, or am I just misremembering?
Which track?

The title track, (first one), is a different one to the main Tetris theme which starts at 52secs.
at67
Site Admin
Posts: 647
Joined: 14 May 2018, 08:29

Re: MIDI Audio:

Post by at67 »

marcelk wrote: 24 May 2018, 18:47 I have the nagging feeling that the low-pitch noise might be caused by the mismatch between 521 scan lines and 4 sound channels. Every 16.7 ms there will be an interval of 5, not 4, scan lines that are together producing a sample. That can and will overflow. The solution I had in mind is that the video loop injects an additional sample reset at the right time, namely after the first of those five. The ROM indeed does something like that but I think I mistimed that reset and it happens 1 scan line too late. That could easily cause a 30 Hz noise... Just theory (it doesn't match all observations yet...) but it will be easy to test and I'll put it on my todo list.
That probably explains the 30Hz signal you can faintly hear, what dB gain is the high pass filter registering at 30Hz? It probably doesn't matter, 30Hz is one of those obnoxious frequencies that permeates everything even when squished into almost oblivion. If fixing the ROM is out of the question then maybe a 3 component LCR notch filter at 30Hz will do the trick.
The high-pitch noises are aliasing effects that are almost impossible to avoid with this 4-bit DAC, the simplistic waveform generation and a low sample rate. I was secretly hoping that the high pass filter takes care of most of it, but it doesn't help much. Here is some explanation: https://theproaudiofiles.com/digital-audio-aliasing/ so no real hope of getting rid of it with the current synthesis.
Aliasing should be mostly taken care of by the low pass filter, but then your high pass filter undoes a lot of the work performed by the low pass filter. Obviously you used the two like this to dampen the 30Hz/low frequency spurious signals and to also meet the audio line out voltage requirements, (it's always a balancing act with trade-offs, I am not judging :)).

Looking at your frequency plot, your voltage is approximately 6dB down, (0.5), at 2Khz; your sample rate for each channel is 521*60/4 = 7815Hz right?
If so then it's understandable that aliased frequencies are getting through, especially with all the high energy content/noise present on the output of a HCT chip. I haven't designed any audio circuits in many years so my math is rusty and I have forgotten a lot of the details, here's a decent non academic explanation of some of the pitfalls with filter design, sampling and Nyquist sample rates.
User avatar
marcelk
Posts: 488
Joined: 13 May 2018, 08:26

Re: MIDI Audio:

Post by marcelk »

There could be more to it than just aliasing. The reduction from 8 bits accumulated to 4 bits out induces a discretisation error. It might be better to carry over the remainder of this truncation to the next sample, instead of resetting it. Well, all speculation and much tweaking potential.
at67
Site Admin
Posts: 647
Joined: 14 May 2018, 08:29

Re: MIDI Audio:

Post by at67 »

marcelk wrote: 25 May 2018, 11:51 There could be more to it than just aliasing. The reduction from 8 bits accumulated to 4 bits out induces a discretisation error. It might be better to carry over the remainder of this truncation to the next sample, instead of resetting it. Well, all speculation and much tweaking potential.
True, a running sum of remainders would help a little; I haven't looked in detail at the code that mixes the audio yet, but I did notice that the sample waveforms were all signed -31 to +31, so I assume you add all four channels together and output the top four bits? If so that's neat as it saves the shifts/divide you would normally require.

If this is how it works, is it possible to change the mask from 0xF0 to 0xFC in the ROM's native code and get 6 bits of mixed audio out? Obviously you would have to add more resistors to your resistor ladder, but it wouldn't be a difficult mod and the increase in audio quality would be obvious. (I know that 2 of the Blinkens would get sacrificed and the ROM code for them would need to change, but I'd be willing to make the trade on my Giga ;P)
at67
Site Admin
Posts: 647
Joined: 14 May 2018, 08:29

Re: MIDI Audio:

Post by at67 »

Added a working GCL example, it shows how to play back MIDI synchronously and asynchronously with respect to VBlank.

Example is here:
https://github.com/at67/gigatron-rom/bl ... diTest.gcl

Documentation is here:
https://github.com/at67/gigatron-rom/tr ... /at67/midi

If anyone finds it useful or has questions, please don't be shy.
Last edited by at67 on 07 Jun 2018, 00:08, edited 1 time in total.
User avatar
marcelk
Posts: 488
Joined: 13 May 2018, 08:26

Re: MIDI Audio:

Post by marcelk »

For demo purposes at the HaD conference I made a ROM file with your MIDI-blasting tetris.gt1 in it: https://marcelk.net/2018-05-26/theloop.2.rom

I put Tetris in place of Credits in the menu, and I removed Jupiter to free up ROM space. A hack in SYS_Exec_88 is also needed to accept the GT1 file, because it loads data on top of the stack where the ROM loader lives. The ROM loader puts itself on the stack in an attempt avoid collisions, so this file needs special treatment because it loads some data at 0x00a2.

I don't believe anybody at the venue heard the music because my speakers were smaller than those of the DJs, but may people enjoyed playing the game!
at67
Site Admin
Posts: 647
Joined: 14 May 2018, 08:29

Re: MIDI Audio:

Post by at67 »

Good stuff!
Post Reply