Playing with sound

Using, learning, programming and modding the Gigatron and anything related.
Forum rules
Be nice.
Post Reply
User avatar
DavidHK
Posts: 21
Joined: 25 Aug 2019, 12:59

Playing with sound

Post by DavidHK » 08 Sep 2019, 17:33

Before running into the Gigatron I was experimenting with simple sound synthesis. In fact, during this project I was searching on YouTube for "8-bit music" and found some videos of "The 8-Bit Guy". I watched his other videos as well and now I am here. ;-)

So of course I am also interested in the sounds that the Gigatron can already produce and the sounds it could produce. My first step in this project is a small program I called "PianoBeep" (no the "beep" is not supposed to be a censored expletive, it just beeps in the original meaning of the word). It provides a keyboard like in the "Piano" BASIC program with the possibility to enter any value into the parameters wavA and wavX.

My goal is to test whether it is possible to produce sounds with an ADSR envelope. That is a sound that does not just beep but rises and decays in volume. Of course multiplications are not an option and so the only wave form where it is possible to adjust the amplitude is the pulse wave. And that is the second part of my PianoBeep program: it has options to modify the sound table for the pulse wave. It can change the amplitude and it can also change the width of the pulse to get different timbres.

The next step would be to write a second Piano program that changes the volume on its own, while a sound is being played. I hope it is fast enough.

If that is successful for a single channel my goal for multi-channel music would be to create an experimental ROM and change the meaning of wavA and wavX: wavA being the amplitude and wavX being the pulse width. The formula for outputting a sample would be

Code: Select all

if phase > wavX then sample += wavA else sample += 0
(no sound table lookup anymore). I am not sure whether I can squeeze that in the tight cycles of the audio loop. And of course with that change the existing Apps would be silent and would need slight modifications to use different values for wavA and wavX.

As a demonstration what could be done with simple pulse waves and ADSR envelopes, here is a video of The 8-Bit Guy demonstrating the Yamaha PSS-125: https://www.youtube.com/watch?v=tdZZCQEA99Y

Edit: I forgot to include the link to the Piano program, it is in my contrib folder: https://github.com/kervinck/gigatron-ro ... hkolf/apps
Attachments
gigatron-pianobeep.png
gigatron-pianobeep.png (8.64 KiB) Viewed 123 times

User avatar
marcelk
Posts: 329
Joined: 13 May 2018, 08:26

Re: Playing with sound

Post by marcelk » 08 Sep 2019, 18:11

You made the program that was on my list for a while. Great!

wavX does two things: bit 0:1 select the main wave form, and bit 2:7 provide some modulation of it. The latter doesn't produce interesting results with all waveforms, but for some it does.

I haven't thought too much about ADSR yet. I believed that it was going to be too hard to figure out how to do. But later somebody suggested that's it cheap if you have two channels play the same notes. You can then create volume control by playing with their phase difference. I haven't tried it yet.

There is a brief explanation of the current synthesis here: viewtopic.php?p=76#p76

User avatar
DavidHK
Posts: 21
Joined: 25 Aug 2019, 12:59

Re: Playing with sound

Post by DavidHK » 15 Sep 2019, 18:32

I now progressed to the next step in my experiment and published it as the "PianoAD" program. It changes the pulse wave sound table while the sound is being played to apply an attack-decay envelope.

I realized with the physical PS/2 adapter that I don't really know how long a key is being pressed (until repeated keys arrive), so I didn't add sustain and release yet. But I guess attack and decay are enough for a first demo.

I guess my next step would be to see whether I can create percussive sounds with just a pulse wave form. I haven't tried this yet. After this I guess a program demonstrating some MIDI tune would be great. But I will see how much time I have for this. ;-)


I noticed that the pulse wave creates some aliasing effects at higher frequencies. This might be a drawback for my plans. I will have to compare how significant the aliasing effects are for the other wave forms.

About the phase shifted sounds -- I guess that works well with the fundamental frequency but I am not so sure about the overtones. And it would need two channels for a single sound but I would still like to use all four channels independently.

User avatar
marcelk
Posts: 329
Joined: 13 May 2018, 08:26

Re: Playing with sound

Post by marcelk » Yesterday, 06:19

Going beyond the original capabilities, I like it. It might be right that the phase shifting only works with triangle.

Using wavA should also have the effect of limiting the pulse's amplitude. Have you tried that? After all: it adds a constant to the channel's 6-bit internal value and clips it at 63. For pulses this should have the effect of lifting the base, but keeping the peak as-is. Maybe I'm overlooking something.

I haven't figured the source of the aliasing. It could be discretisation noise: we throw away a lot of bits, and the normal way to deal with that is to move over the error to the next sample. The current sound driver can't do that. I'm also somewhat disappointed with the limited effect of the filters in this regard. On the other hand: we're already getting a lot compared to other systems without sound chip :-)

Edit: ROMv4 has the channelMask bits: with these you can reduce the number of channels to two or even one, while increasing their individual update rate. This can be a path to investigate the aliasing as well. The accumulated sample still goes out once every 4 scanlines, but it aggregates more samples from the waveform tables this way.
Attachments
Screenshot 2019-09-16 at 08.18.00.png
Screenshot 2019-09-16 at 08.18.00.png (87.97 KiB) Viewed 44 times

User avatar
DavidHK
Posts: 21
Joined: 25 Aug 2019, 12:59

Re: Playing with sound

Post by DavidHK » Yesterday, 17:03

Oh, yes, wavA should do the trick as well, I missed that! With my first PianoBeep demo I was a bit confused about the effect of wavA as all the values from 1 to 63 just turned the pulse wave silent -- but the values between 64 and 127 work like a charm. That should simplify matters a lot as now my project should work even without a custom ROM.

Regarding the aliasing, I guess that cannot be avoided with a relatively low sample rate. If I did the math correctly: 525/4*60 Hz would be ~7.8 kHz. Any frequencies (of the harmonics) above that would be mirrored down into that range, creating the aliasing frequencies. By the time they reach the analog filters it is already too late. Accumulating four values per sample should provide some digital low pass filtering before the sampling so it should work. But then again, I would like to keep four channels and rather avoid using high notes.

Edit: Oh, there is a mistake with my math: 7.8 kHz would be the sampling rate, so the highest frequency that can be sampled would be half of that, 3.9 kHz.

User avatar
DavidHK
Posts: 21
Joined: 25 Aug 2019, 12:59

Re: Playing with sound

Post by DavidHK » Yesterday, 19:31

In my next iteration I have now created "DrumsAD", which uses wavA to apply an envelope to the percussive sound table. Sounds to me like wavA is indeed performing well. Thank you for the hint!

Post Reply