Jack Gassett

SID Filters

Recommended Posts

If you need some songs to test the filter I have some suggestions, all can be found in the HVSC. Some of those songs, like Exkrement, are quite annoying but that's not the point if you just want to test filters.

 

Blue Gnerk very good filter workout on all voices, both low and hi freq.

Exalt_01 just voice 1, tests very low freq filter response.

Exkrement just voice 1 enabled, tests high frequency filter response.

Fatum_Megademo_part_7 works out all voices, including white noise on voice 3.

Hell_Machine_part_1 absolutely a must for testing low freq response on all channels, goes on forever on a loop.

 
Also
Power_Of_Lard_part_11
Quality_Timely
Slow_Shit_and_Mystical
Sunga_Bunga_18_5
Two_In_One
 

Share this post


Link to post
Share on other sites

Ok, more information after digging in further...

 

Thinking that the tinySID library must not be driving the SID chip with the correct reg values I dumped the registers that tinySID was creating to compare against the registers created by the SIDDumper tool. Attached are the results if anyone wants to check them out.

 

To my surprise, they matched up perfectly... I can't find any differences that would account for the missing voice 1 lead... So much for tinySID being the problem.

 

But upon listening closer I noticed that the song starts out with voice 1 lead playing as it should. Its about 20 seconds into the song that you all of the sudden hear the lead fade out and stop playing from there on out...

 

Looking at the dump files I can see that the control register for voice 1 is at 41 for most of the song. 41 means square wave is selected for voice one and the GATE is triggered, this is from the datasheet for GATE:

 

Gate (Bit 0)

The GATE bit controls the Envelope Generator for Voice 1. When this bit is set to a one, the Envelope Generator is Gated (triggered) and the ATTACK/DECAY/SUSTAIN cycle is initiated. When the bit is reset to a zero, the RELEASE cycle begins. The Envelope Generator controls the amplitude of Oscillator 1 appearing at the audio output, therefore, the GATE bit must be set (along with suitable envelope parameters) for the selected output of Oscillator 1 to be audible. A detailed discussion of the Envelope Generator can be found in Appendix B.

 

When I was dumping the tinySID registers I marked the dump file when it started fading out. The fade out occurs around 8A93 in the hex file. If you scroll up and down from that point in time you see that the control register has been at 41 for a long time and it stays at 41 for a long time after that. It should be in the SUSTAIN state... It seems like SUSTAIN is fading out if it is held for a long time.

 

One thing we need to keep in mind is that this is working correctly in the NetSID implementation with a bit file that does not implement the filters... I guess the next steps are:

 

1) Look at the sustain code

2) Try to run this tinySID sketch with an older version of the RetroCade bit file that does not have the filters implemented and see if the sustain is, well, sustained.

 

Jack.

Conquestador_Reg_Dumps.zip

Share this post


Link to post
Share on other sites

Ok,

 

I loaded a RetroCade bit file from before the filters were implemented and it is doing the same thing... The voice 1 lead fades out after 20 seconds or so. We can rule out the changes for the filters causing this, the problem existed before the filters were added. But the problem does not exist in the NetSID standalone version. So something is going on with sustain that was either introduced in the VHDL when it was added as a Wishbone peripheral, or with the SID library (not tinysid this is a different library) that loads the registers to the SID chip.

 

I think we have a better idea where to start looking now, I have to call it a day for now.

 

Jack.

Share this post


Link to post
Share on other sites

Nice one Jack - yes that correlates with the thoughts / evidence I was seeing around the voices fading out, and also seeing issues when the gate was triggered, but lacking another hardware SID to drive from the sketch limited my debugging!

 

Hopefully it's just a minor fix in the VHDL... So it is only voice 1 that you think is affected? The reason I ask is that the SID have the weird ability to read back the envelope generator for voice 3 via a read register which could confirm what it's doing during the fade issue. Of course, you could always temporarily add a port to all the voices to read back the 8 bit envelope value which may be trivial to do?

 

Anyway, i'm sure now it's narrowed down it will be a quick fix, though I'm as confused as you as how adapting the netSID code would have changed the ADSR behaviour!

 

On another note, if there was room on the FPGA wouldn't it be cool in the future to have a version that provided 32 multiplexed voices like Bob Yannes originally wanted to do for the SID? :-)

Share this post


Link to post
Share on other sites
What this sounds like on a version of the SID HW without filters I'm not sure?
 

 

R: 176 14 0 0 33 10 192 112 14 0 0 33 10 192 52 6 128 7 65 141 0 0 0 0 15 
R: 176 14 0 0 33 10 192 112 14 0 0 33 10 192 68 6 208 7 65 141 0 0 0 0 15 
R: 176 14 0 0 33 10 192 176 14 0 0 33 10 192 52 6 32 8 65 141 0 0 0 0 15 
R: 176 14 0 0 33 10 192 240 14 0 0 33 10 192 36 6 208 7 65 141 0 0 0 0 15 
R: 176 14 0 0 33 10 192 176 14 0 0 33 10 192 20 6 128 7 65 141 0 0 0 0 15 
R: 136 15 0 0 33 10 192 72 15 0 0 33 10 192 12 5 48 7 65 14 16 0 0 0 15 
R: 136 15 0 0 33 10 192 72 15 0 0 33 10 192 12 5 224 6 65 14 16 0 0 0 15 
R: 136 15 0 0 33 10 192 136 15 0 0 33 10 192 28 5 144 6 65 14 16 0 0 0 15 
 
What does register 25 do? I noticed the code to toggle it on and off by "e" and "d" - is this controlling the filter by any chance?

 

 

I wanted to be able to enable/disable the filters, so I added a virtual register to control that. If you press 'd' the filters are entirely disabled, and the design behaves exactly like the old one. If you type 'e', then filters are enabled, including the in-filter mixer.

 

 

Very nice description of the filter above, by the way... :-)

 

Thanks :)

Share this post


Link to post
Share on other sites
Hopefully it's just a minor fix in the VHDL... So it is only voice 1 that you think is affected? The reason I ask is that the SID have the weird ability to read back the envelope generator for voice 3 via a read register which could confirm what it's doing during the fade issue. Of course, you could always temporarily add a port to all the voices to read back the 8 bit envelope value which may be trivial to do?

 

All the voices share the same HDL, so it must apply to all voices.

 

I can simulate the design and see what is happening inside. So far it looks like it does what it is supposed to do... need to investigate a little further.

 

 

Anyway, i'm sure now it's narrowed down it will be a quick fix, though I'm as confused as you as how adapting the netSID code would have changed the ADSR behaviour!

 

Might be a timing issue, not actually ADSR issue. I am not sure tinysid implementation is fast enough to emulate a C64, as it is. Might need some tweaking.

Share this post


Link to post
Share on other sites

Jack, just wondering a thing: I'll be using the Retrocade most for its synthesis feature (I was not even considering a future sid player implementation, though it's pretty neat), so is it possible to remove the TinySID in a eventual 500k oriented sketch?

Share this post


Link to post
Share on other sites

Not sure I follow you here,

 

you mean removing the SID implementation on the FPGA for the S3E500 ?

 

Reason I'm asking for a clarification is that "TinySID" is a software player, the SID implementation on hardware is "NetSID".

 

But the answer is yes, we can remove the SID in some sort of variant.

 

Alvie

Share this post


Link to post
Share on other sites
Jack, just wondering a thing: I'll be using the Retrocade most for its synthesis feature (I was not even considering a future sid player implementation, though it's pretty neat), so is it possible to remove the TinySID in a eventual 500k oriented sketch?

 

If you stay with the 500K you will be able to get the majority of the synthesis features. But you will miss out on the SID analog filters, even if we save space and do not include the tinySID library the 2 BRAMs needed by the SID analog filters rules out implementation on the 500K.

 

Jack.

Share this post


Link to post
Share on other sites

Ok, continuing the debug saga.

 

This is what is happening:

I'm looking at one song that I attached to the post earlier, Conquestador.sid. What I'm hearing is that when we play to song through tinySID the lead on voice 1 fads out after about 20 seconds... When I play it back using ACID64 and the standalone NetSID implementation the lead plays back without fading out.

 

This morning we made a player that will play back a register dump so we could better rule out the tinySID library. I dumped a sid file using the SIDDumper tool and played the same song back with the new sketch. Same problem, the lead fades out after 20 seconds.

 

As I started studying the dump file again I noticed something that I totally missed last night, the chip is doing exactly what the registers are telling it to do! I was just too tired to notice the rest of the story!

 

Take a look at this register dump:

post-29509-0-20481200-1365011328_thumb.p

 

You can see at 3A02 the control register at register 4 changes from 40 to 41, this triggers the gate and starts the note. I was assuming that there was a Sustain level set, but if you look at register 6 you see that sustain is set to 0. There is no audible sustain level.

 

If you look at register 5 you can see that the attack/decay register is set to 0F which sets the Decay to the maximum setting. According to the C64 datasheet that gives us a Decay of 24 seconds. So with Sustain set at 0 and a Decay of 24 seconds I'm hearing exactly what I'm supposed to hear according to what is being loaded into the registers. After 20 seconds is when the Decay starts to hit a level where I can clearly hear it fading out.

 

So now, the question is, why are two different players, tinySID and SIDDumper, both generating this output? What is different about ACID64 that it generates the correct output?

 

Maybe it is the read registers at 27 and 28.

 

Jack.

Share this post


Link to post
Share on other sites

Wow, that is interesting Jack.. You never know what those crazy C64 music coders might have been doing, I did read this myself and wondered who would ever want to do this:

 

 

ENV 3 (Register $1C)

Same as OSC 3, but this register allows the microprocessor to read the output of the Voice 3 Envelope Generator. This output can be added to the Filler Frequency to produce harmonic envelopes, WAH WAH, and similar effects. “Phaser” sounds can be created by adding this output to the frequency control registers of an oscillator. The Voice 3 Envelope Generator must be gated in order to produce any output from this register. The OSC 3 register, however, always reflects the changing output of the oscillator and is not affected in any way by the Envelope Generator.

 

... but I guess it's easy to report on any reads to $D400..D7FF to check the theory ?

Share this post


Link to post
Share on other sites

I checked the demo song I put on the sketch, and it does not read any SID register at all.

 

But it might use VIC or CIA. We need support for those if we want to play more complex songs.

Share this post


Link to post
Share on other sites

Yep, i've just done the same thing with a couple of songs - no reads from the SID (including 'ghost' register sets).

 

Might have a look at the other non-RAM blocks now, though the processor port mapping the RAM in and out makes this slightly more convoluted..

Share this post


Link to post
Share on other sites

Just had a look, tried a couple of songs and I couldn't see any reads or writes to VIC, CIA1 or CIA2, or reads from SID (D000-D800, DC00-DDFF), so not sure... I also checked the IO register and that was set to all RAM mapped in, and I/O from D000-DFFF (no ROM) in the unlikely event that they were somehow reading stuff from the ROMs...

 

Jack, so the one thing your combination didn't list as trying was ACID64 playing into the SID with filters? Just to fully rule out the VHDL side? In that case it should sound fine if the tinySID / SIDdumper is suspected as not emulating correctly...?

 

Cheers

Share this post


Link to post
Share on other sites

Yes, that is the next step. I have a feeling that tinySID / SIDdumper are just not handling more advanced SID files correctly. The next step is to get ACID64 to dump register files. I have a feeling that will be the solution...

 

Jack.

Share this post


Link to post
Share on other sites

Success!!!!

 

Days of beating our head against the wall and it was something incredibly simple!

 

As I was looking at ACID64 dumps it occurred to me that a big difference between the ACID64 and our approach is that ACID64 sets one register at a time while our sketch collects all the registers into an array and then does a for loop writing all the registers sequentially.

 

I went for a walk and then it hit me, wait a second, don't the ADSR registers come after the control register? Sure enough our sketch is loading the ADSR registers AFTER we start the envelope! It only took changing a couple lines of code and VOILA, everything I've tested so far sounds right. :) Phew, finally.

 

Attached is the working code.

tinysid-working.zip

Share this post


Link to post
Share on other sites

Well done! Is there a reason you don't write each register as it is updated and you collect them into a register first?

Share this post


Link to post
Share on other sites

Well, that's just how it worked for the YM2149 chip. The couple lines of code that I changed made it so we do write each register as it is updated, that's why its working now. :)

Share this post


Link to post
Share on other sites

Brilliant, you know I was looking at the same thing last night before I ran out of time. I was mainly thinking about whether there was anything that was triggered if the same values were written into the register would perhaps restart the envelope... not the answer but I was close!

 

Wouldn't it be better to arrange the code as:

 

 

while (1) {
while (!tick);
tick=0;
int clocks = cpuJSR(play_addr,0);
//printf("Ticck? %d\n",clocks);
....
 
Just because in the order it's in at the moment, it will do the code (with reg updates) and then wait for the tick. If there's any serial activity (or future code) it would slow down the time before reaching the next code execution? In this way it's closer to the real ISR in that the VBI would start the next round of code (and reg updates) immediately?
 
Glad to see it's all working, yay! Alvie - very keen to see the new HDL when you can publish it please!
 
Cheers 

Share this post


Link to post
Share on other sites

HDL will only have a small change - to remove the old mixer and permanently enable the filters.

 

Regarding the SID register "block": I implemented it that way so I could take a dump at each HZ tick, and also because I was afraid that if I directly write to SID registers, since CPU speed (emulated) is different might yield different results...

 

Anyway, I'll try packing tinySID as a library, so that sketch code becomes clearer. I also need to implement multi-song, high-speed and VIC/CIA emulation for more complex songs.

 

Alvie

Share this post


Link to post
Share on other sites

I agree that the envelope triggering issue is fixed with the direct register writing, which is great.

 

There's definitely still something amiss with the voicing. Compare these attachments for Ghostbusters 2 - it's Sidplay and the retrocade (with the latest code from above). The drums sound completely different / very hard to hear on the retrocade?

 

Any ideas?

 

Thanks guys

GHOSTBU2.mp3

GHOSTBU2_Retro.mp3

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now