6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Thu May 09, 2024 5:49 pm

All times are UTC




Post new topic Reply to topic  [ 65 posts ]  Go to page Previous  1, 2, 3, 4, 5  Next
Author Message
PostPosted: Fri May 25, 2018 6:57 am 
Offline
User avatar

Joined: Fri Nov 09, 2012 5:54 pm
Posts: 1393
cynlic wrote:
I more or less thought up the idea as a simplified/discrete SID.

Now that's going to be fun.

So you are just out to build something that offers a similar functionality like a SID,
but at hardware\software level it doesn't have to be compatible to the the SID,
and it feels like you would like to avoid using proprietary parts ?


IMHO just one 6502 CPU would be too slow for doing "three channel audio DDS" in real time at a certain frequency resolution.

A multiprocessor system with a master 6502 that does envelope control plus three slave 6502s with something like IDT7006 dual port RAM attached
probably still would be too slow. (Note those 320mA supply current per IDT7006.)

If you don't want to use FPGAs or CPLDs (Altera\Intel 5M1270 for instance) or a fast microcontroller (like the Propeller),
this probably calls for something like "a custom 24 Bit audio DSP" built from TTL chips. ;)
It's a pity, that the IDT7381 16 Bit ALU chip is out of production...
Edit: clarification: "DSP" only for DDS\PRBS signal generation, not for trying to implement something like a digital filter. You better stick with an analog filter design.

Hmm... remembering Jeff's KimKlone, it appears that the capabilities of a 6502 for handling a specific application
could be "boosted" a little bit when building a microcode ROM and some TTL chips around the 6502...


Last edited by ttlworks on Fri May 25, 2018 12:11 pm, edited 1 time in total.

Top
 Profile  
Reply with quote  
PostPosted: Fri May 25, 2018 7:21 am 
Offline

Joined: Thu Jan 21, 2016 7:33 pm
Posts: 269
Location: Placerville, CA
If the SID is your model, you definitely want to mimic that "digital oscillator plus analog filter" combination. You mentioned already having some experience with analog audio hardware so I'm assuming you can figure out the latter; as for the former, there's a great interview with Bob Yannes that lays out most of the workings of the SID's oscillator, and it's stunningly elegant in its simplicity, considering he didn't have time to optimize the design. It's straightforward enough that you could implement it in discrete hardware if you wanted, though it might be simpler to take cbmeeks's suggestion and use a microcontroller to generate the oscillator signals before running them through any further analog processing.


Top
 Profile  
Reply with quote  
PostPosted: Fri May 25, 2018 2:14 pm 
Offline

Joined: Wed May 23, 2018 9:00 pm
Posts: 9
ttlworks wrote:
So you are just out to build something that offers a similar functionality like a SID,
but at hardware\software level it doesn't have to be compatible to the the SID,
and it feels like you would like to avoid using proprietary parts ?

That was the original idea, yes. I admit I've sort of had my head turned by all of the options available -- the propeller mcu, the OPL-3 option, the DDS approach... Each one of these strategies has something that appeals to me. I'm actually warming to the idea of using a micro-controller, if only because it seems easier (as a beginner) to make the audio synthesis a sort of black box. I feel like if I can concern myself with synthesis details later, I'll have a better chance of making a project that I can come back to and improve.

ttlworks wrote:
IMHO just one 6502 CPU would be too slow for doing "three channel audio DDS" in real time at a certain frequency resolution. A multiprocessor system with a master 6502 that does envelope control plus three slave 6502s with something like IDT7006 dual port RAM attached probably still would be too slow.

Hmm. I assume this because the multi-tasking for envelope/filter control is pretty intensive? I could see how it might be difficult to get frequency, waveform, and envelope/filter instructions out to their various components within the number of cycles needed to produce accurate audio playback....though if that's the case I do wonder how Commodore achieved the granularity they made available with the SID? To my understanding, in software synthesis you would normally handle issues with the latency of control data through some kind of interpolation. I have no idea if this is possible in hardware, but maybe you could put up with a sluggish DDS system by interpolating between some set of fixed filter or envelope states? It wouldn't be very flexible, obviously. Maybe that's a goofy idea -- I don't know! :D


Top
 Profile  
Reply with quote  
PostPosted: Fri May 25, 2018 4:32 pm 
Offline

Joined: Thu Jan 21, 2016 7:33 pm
Posts: 269
Location: Placerville, CA
cynlic wrote:
Hmm. I assume this because the multi-tasking for envelope/filter control is pretty intensive? I could see how it might be difficult to get frequency, waveform, and envelope/filter instructions out to their various components within the number of cycles needed to produce accurate audio playback....though if that's the case I do wonder how Commodore achieved the granularity they made available with the SID? To my understanding, in software synthesis you would normally handle issues with the latency of control data through some kind of interpolation. I have no idea if this is possible in hardware, but maybe you could put up with a sluggish DDS system by interpolating between some set of fixed filter or envelope states? It wouldn't be very flexible, obviously. Maybe that's a goofy idea -- I don't know! :D

Commodore achieved a reasonable granularity with the SID because it's a separate chip running alongside the CPU providing oscillators, amplitude envelopes, and a filter. In software synthesis you don't get any of that for free, and you have to do it on a general-purpose processor rather than hardware specifically suited to the task. Moreover, changing the amplitude of a signal in software requires multiplication (unless you can figure out a cheat - the NES, for example, only provides it on the square/pulse and noise channels, because they only ever have a value of +amplitude or -amplitude,) and multiplication is expensive on an 8-bit CPU without hardware multiply. A proper resonant filter is also computationally expensive.

That's why early digital synthesizers eschewed the subtractive model altogether and went with more digital-friendly methods of synthesis like FM/phase modulation - for example, the DK Synergy managed to provide 32 sine-wave oscillators with freely configurable FM arrangements entirely in one board of TTL logic (take a look at the service documentation for it sometime, it's a fantastically clever design, particularly the way they get amplitude modulation without multiplication.)


Top
 Profile  
Reply with quote  
PostPosted: Fri May 25, 2018 4:42 pm 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10800
Location: England
(Some interesting links on the DK Synergy here.)


Top
 Profile  
Reply with quote  
PostPosted: Fri May 25, 2018 5:06 pm 
Offline

Joined: Mon May 21, 2018 8:09 pm
Posts: 1462
There are several approaches you could use, of course. I'll assume for the moment that you have a 5MHz 65C02, and that whatever display system you intend doesn't need to steal/interleave/stretch cycles in order to operate.

The hardest option, from a CPU load point of view, is direct synthesis on the CPU itself. At 48kHz, that means you need to produce a sample every 104 CPU clocks, regular as clockwork. This is very hard to achieve for any kind of complicated synthesis which would justify this approach. But if you want to try it anyway, I advise putting a FIFO buffer on the I/O port and clocking out from that into the DAC at a hardware controlled rate, rather than attempting to do software timing. If you absolutely *must* try this approach, the 6502 really is not the best tool for the job; try a 68K or an ARM.

The next option is to do DDS using a largish RAM chip and a free-running counter, in which you can adjust the value added per cycle, the wrap address and the wrap decrement under CPU control. The counter should have more bits than the RAM chip has address lines, and you just use the high-order ones (for better frequency precision). You can load samples into the RAM chip from the CPU, either from disk or by pre-calculating synthetic waveforms. Updating this instrument, once running, can be done 1000 times per second with a much more comfortable cycle budget of 5000. The chip itself can make as many samples per second as you like; run it off the same master clock (10 or 20 MHz) as the CPU - ordinary 74HC logic can probably keep up with that if you lay out your PCB sanely.

For bonus marks, find a way to generate multiple overlapping tones (potentially from more than one instrument), and mix them together, by modifying the above hardware. You don't need 20 MS/s for an audio DAC; you can multiplex several address counters onto one RAM chip. You may use a single DAC fed by a digital adder tree, or multiple DACs if you want to apply independent analogue filters afterwards. Or implement a digital filter using a short FIFO and adder tree for frequency/phase effects, and a second RAM chip (64Kwords should be enough) for reverb.

Further bonus marks: feed the address generators into each other for FM synthesis with arbitrary waveforms. Use your imagination.

The third option is an analogue NCO and filter bank, similar to the SID. Again, 1000 updates per second is doable if you need it. Less will usually be quite sufficient. Investigate how quickly typical demoscene chiptunes arpeggiate; you don't need to do much better than that.

A fourth option is to use a speech generator chip. Not sure how easy they are to find these days, but some of them can take an external input signal and run it through their internal filter banks. The data rate they require is not very high; the old TMS5220 runs at 40 50-bit LPC frames per second, for a total of 2Kbps worst case, for an 8kHz sample rate. Within those frames, it interpolates the filter bank parameters in several steps.

You can do smooth interpolation with hardware assistance as well, using an EWMA filter. That is: [code]X(n) = (1-1/N) * X(n-1) + (1/N) * C[/code}. If N is a power of two, you only need two adders to implement that. Chain two or more EWMA filters to get a smooth start as well as finish to the curve.


Top
 Profile  
Reply with quote  
PostPosted: Fri May 25, 2018 5:17 pm 
Offline

Joined: Thu Jan 21, 2016 7:33 pm
Posts: 269
Location: Placerville, CA
Chromatix wrote:
The next option is to do DDS using a largish RAM chip and a free-running counter, in which you can adjust the value added per cycle, the wrap address and the wrap decrement under CPU control. The counter should have more bits than the RAM chip has address lines, and you just use the high-order ones (for better frequency precision). You can load samples into the RAM chip from the CPU, either from disk or by pre-calculating synthetic waveforms. Updating this instrument, once running, can be done 1000 times per second with a much more comfortable cycle budget of 5000. The chip itself can make as many samples per second as you like; run it off the same master clock (10 or 20 MHz) as the CPU - ordinary 74HC logic can probably keep up with that if you lay out your PCB sanely.

This is actually a good "happy medium" between some of the more complex options - a simple looped waveform of 16-64 samples gives you a fair bit of room to use arbitrary interesting timbres, and isn't at all difficult to implement in hardware. About the only area where it's really lacking is if you want proper noise - you'd need to either update the waveform on the fly from a software noise source, or provide an option to switch out the wavetable source with an LFSR. (Though your suggestion of FM/PM with arbitrary operator waveforms has plenty of opportunity to generate noise itself, so maybe that wouldn't even be necessary.)


Top
 Profile  
Reply with quote  
PostPosted: Fri May 25, 2018 8:17 pm 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8432
Location: Southern California
My understanding is that cynlic was not seeking to do full MIDI and synthesize an orchestra, but just do three voices like the old-fashioned computers games did.  That definitely does not require 48K samples per second.  A third of that, with a Nyquist frequency of 8KHz should be plenty.  (You'll want a decent anti-alias filter, but that's pretty simple and cheap to make.)  Accuracy in the timing of individual samples will be plenty adequate with a 65c02 running at 10MHz and run on 65c22 VIA timer interrupts.  20MHz would be all the better.  This is not the same thing as trying to time it in software loops.  No hardware buffer necessary.  The 65c02 has outstanding interrupt performance (and miles and miles ahead of of the 68K).  Take advantage.

You can have lots of waveforms stored in tables.  256 bytes (one page) each is easy to work with and gives plenty of harmonic content.  The higher harmonics of higher frequencies wouldn't come through, but they might be too high for cheap computer speakers to reproduce anyway, or possibly even out of the hearing range.

The harder part would be envelope generation and programmable filters.  Multiplying D/A converters or digital pots could take care of the envelope generation.  The '02 can shift quickly for dividing by powers of two, so the hardware part would only have to take care of a few steps in between powers of two.  A power of two in voltage is 6dB in sound intensity.  I did experiments years ago where I stepped something quickly by up to 2dB at a time, ramping volume up and down as if with an envelope generator, and with cheap speakers here in the office, the steps were nearly inaudible.  I think I was using a digital pot that only changed the volume at zero crossings (so writing to it asynchronously won't be a problem), but I'd have to find my files on that stuff and look it up.  Having only four steps between 6dB points would make it 1.5dB which is a further improvement.  Eight steps, for 0.75dB, would be super, yet simple.

The matter of filters would mostly have to be taken care of in hardware.  I've done limited filtering in software on the '02 in realtime, and you could also have different wave tables pre-calculated, for example to have the same voice in different brightnesses, but again, it would be quite limited.

Noise is one thing I have not generated on purpose.  I suppose you could have a noise table and augment it with a very simple type of pseudo-random number generator that the processor could run.

_________________
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?


Top
 Profile  
Reply with quote  
PostPosted: Fri May 25, 2018 8:47 pm 
Offline

Joined: Thu Jan 21, 2016 7:33 pm
Posts: 269
Location: Placerville, CA
Well, certainly you can always improve the feasibility of software synthesis by reducing the sample rate. The question is whether you're going to like the results. 8 KHz is pretty poor fidelity for musical applications - the Nyquist frequency there is just past the fundamental frequency of the highest C on a piano, and that's not even getting into the additional harmonics (the 10th harmonic of A440 is above 4 KHz, and that's only, what, -20 dB in an ideal sawtooth wave?)

Now, I suppose if you were content with only square/pulse sounds (which, with hardware filtering, could actually work pretty well,) you could probably make 8 KHz work a bit better - with a phase-accumulator design, errors would manifest more as frequency/pulse-width jitter and probably be less noticeable, and as I noted earlier about the NES pAPU, amplitude control is as simple as a single XOR operation with square/pulse waveforms. (You could also do a 1-bit-output LFSR noise generator too, if you wanted.) That might be reasonable.

(Also, if you're doing a phase-accumulator design, you can add oscillator sync pretty cheaply to expand the timbral options a bit from pure square/pulse - just reset the slave oscillator if the carry-out from the master oscillator is 1. Ring-modulation is similarly cheap-'n-easy with square waves - just XOR the values of the two oscillators together - though you'd have to do this before applying the amplitude control, otherwise you'd need proper multiplication.)

But then, it's cynlic's call...


Last edited by commodorejohn on Fri May 25, 2018 9:13 pm, edited 1 time in total.

Top
 Profile  
Reply with quote  
PostPosted: Fri May 25, 2018 9:13 pm 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10800
Location: England
In the head post, it looks to me like the project idea is a microprocessor controlled (analogue?) synth:
Quote:
I’ve begun to wonder if I could use a 6502 as a sort of controller for a DIY synthesizer in the same way that the 6502 at the heart of the NES interacts with the system’s Audio Processing Unit.


In which case the 6502 needs to set up each note and update according to the envelope: it's not running at waveform speeds.

But of course there are many project ideas and one can always change one's mind.


Top
 Profile  
Reply with quote  
PostPosted: Fri May 25, 2018 9:44 pm 
Offline

Joined: Wed May 23, 2018 9:00 pm
Posts: 9
I'm sorry to slow the conversation down, but I think I might need a little clarity to fully understand the suggestions here.

GARTHWILSON wrote:
My understanding is that cynlic was not seeking to do full MIDI and synthesize an orchestra, but just do three voices like the old-fashioned computers games did. That definitely does not require 48K samples per second. A third of that, with a Nyquist frequency of 8KHz should be plenty.

Garth, you're right about my initial intentions for the project's scope. I'm not shooting for something that is either dead-on accurate to the SID or capable of rendering large pieces. Three voices with envelopes and some filters will be fine for me!

If I could ask a dumb question, when you refer to a 8kHz sample rate, are you talking about direct synthesis on the CPU, which is then passed on to the DAC and filter circuitry? If that's the case 8kHz seems a bit low, particularly if you're trying to maintain the upper partials, as commodorejohn said. That being said, I'm not sure that the sounds of the "8-bit era" were exactly characterized by 48kHz fidelity and very complex harmonics. I'll defer to people with more knowledge on that score :)! In either case, I wasn't imagining doing direct synthesis on the 6502 (like BigEd has noted). I'm not opposed to going down that road if it is fruitful or actually necessary, but it seems like there are a few options here that don't involve that. If I've misunderstood something, please feel free to enlighten me... I'm quite new to a lot of this.
commodorejohn wrote:
a simple looped waveform of 16-64 samples gives you a fair bit of room to use arbitrary interesting timbres, and isn't at all difficult to implement in hardware.

If I understand Chromatix and commodorejohn correctly, this strategy is kind of similar to how (I think) languages like csound implement their DSP -- allocating buffers of relatively few samples, which are then operated on chunks, producing a distinction between "control rate" and "audio rate" manipulation. I think it's it's also similar to the NES, which has "function generators" squeezed onto the same chip as the 6502? It seems like an extensible, powerful system, but I'm not sure I really understand the implementation details...yet!


Top
 Profile  
Reply with quote  
PostPosted: Fri May 25, 2018 9:48 pm 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8432
Location: Southern California
cynlic wrote:
If I could ask a dumb question, when you refer to a 8kHz sample rate, are you talking about direct synthesis on the CPU, which is then passed on to the DAC and filter circuitry? If that's the case 8kHz seems a bit low, particularly if you're trying to maintain the upper partials, as commodorejohn said. That being said, I'm not sure that the sounds of the "8-bit era" were exactly characterized by 48kHz fidelity and very complex harmonics.

and

commodorejohn wrote:
Well, certainly you can always improve the feasibility of software synthesis by reducing the sample rate. The question is whether you're going to like the results. 8 KHz is pretty poor fidelity for musical applications - the Nyquist frequency there is just past the fundamental frequency of the highest C on a piano

No, what I meant is that at a 16kSPS sample rate (a third of 48kHz), the Nyquist frequency is 8kHz, meaning that with a decent anti-alias filter, you could get near 8kHz audio, not 4kHz.  My hearing is still excellent; but I expect there are many my age who have nostalgia about computers of 1980 who may not even be able to hear 10kHz anymore.  A 10kHz limit would still give nine of the ten octaves though.

When I worked at TEAC in 1982-83, I worked on an awful lot (a couple hundred?) of Portastudio 4-track multitracking cassette machines with the mixing board built in, and their frequency response ended at 13kHz, but they used double the normal cassette tape speed and a 60kHz bias frequency (instead of the usual 100kHz) to keep that frequency response pretty consistent up to 0VU and maybe a little higher.  A lot of upscale home stereo cassette machines could hardly do 5kHz at 0VU, which is why the frequency response was specified at -30 or -40VU, just a little above the noise level, to get those better-looking numbers like 16 or 18kHz.  Our open-reel machines OTOH could do 20kHz without sagging at 0VU, and the output was much more solid.  The cassettes could not compare; yet cassette could still sound pretty darned good back then.  This was just before CDs took hold.

_________________
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?


Top
 Profile  
Reply with quote  
PostPosted: Fri May 25, 2018 9:55 pm 
Offline

Joined: Thu Jan 21, 2016 7:33 pm
Posts: 269
Location: Placerville, CA
Ah, okay. 16 KHz is definitely closer to a useful sample rate.

cynlic wrote:
commodorejohn wrote:
a simple looped waveform of 16-64 samples gives you a fair bit of room to use arbitrary interesting timbres, and isn't at all difficult to implement in hardware.

If I understand Chromatix and commodorejohn correctly, this strategy is kind of similar to how (I think) languages like csound implement their DSP -- allocating buffers of relatively few samples, which are then operated on chunks, producing a distinction between "control rate" and "audio rate" manipulation.

Well, you could do something like that, but what we were more getting at was basically a simple sampled oscillator - the counter or phase accumulator increments at a variable rate and its highest bits are used as an index into a memory table holding the samples for a short looped waveform. This allows you to have any arbitrary waveform without requiring any special logic to generate it from the counter/accumulator on the hardware end. Adding additional higher-order address bits for the memory would allow each voice to have its own separate waveform.

Aaaand I now find myself writing a simple 6502 softsynth, just for the heck of it...hmm.


Top
 Profile  
Reply with quote  
PostPosted: Fri May 25, 2018 10:56 pm 
Offline

Joined: Wed May 23, 2018 9:00 pm
Posts: 9
Thanks for clearing that up Garth.

It’s pretty cool that you worked on the Portastudio 4-tracks! I’m not really old enough to have ever used cassettes other than for audiobooks, which seemed to have a longer lifetime on the platform than music. I did purchase a Portastudio 4-track a few years ago for some not-quite-lofi recordings and tape loop projects. It’s an awesome little machine, imo.

commodorejohn wrote:
Well, you could do something like that, but what we were more getting at was basically a simple sampled oscillator


Right, right. People use a version of this kind of algorithm often in PureData tutorials I’ve seen. It’s instructive because PD will let you actually draw in a buffer which can be played back in the same way you describe.

I wonder, would the bit depth of the sampletable be any kind of limiting factor?


Top
 Profile  
Reply with quote  
PostPosted: Fri May 25, 2018 11:23 pm 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8432
Location: Southern California
cynlic wrote:
It’s pretty cool that you worked on the Portastudio 4-tracks! I’m not really old enough to have ever used cassettes other than for audiobooks, which seemed to have a longer lifetime on the platform than music. I did purchase a Portastudio 4-track a few years ago for some not-quite-lofi recordings and tape loop projects. It’s an awesome little machine, imo.

The Portastudios that existed when I worked at TEAC were the 144 and 244.  I know they came out with one or more others after I left.  One of the reasons I left was that it became very clear that the head life was only 60 hours yet we were told to lie to the customers and say it was 1,000 hours.  (Another reason was the frustration of working on older open-reel machines that we didn't have adequate documentation for, and sometimes we had to guess at part numbers, but the part-numbering system had changed since those machines came out, and I'd get laughed at at the parts department.  It's fun telling the war stories though.)

Quote:
I wonder, would the bit depth of the sampletable be any kind of limiting factor?

I think 8-bit samples are quite adequate for what you want.  As for the table size, 256 bytes will be the most efficient softwarewise to work with.  Let's say you have an 8kHz Nyquist frequency, so you make an anti-alias filter that starts cutting off at 7kHz.  A 256-sample table lets you have harmonics up to that point on a 55Hz fundamental.  Harmonics on a 32Hz fundamental could reach about 4kHz.  Not bad.  Of course you could also have a pure sine wave table with essentially no harmonics too.

_________________
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 65 posts ]  Go to page Previous  1, 2, 3, 4, 5  Next

All times are UTC


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: