Page 2 of 2

Re: Audio IC

Posted: Fri Jul 14, 2023 7:27 am
by GARTHWILSON
The only analog audio output I've done on a 6502 was by feeding samples to a D/A converter, on regular intervals from a VIA's T1 time-out IRQ, with no FIFO.  My workbench computer runs at 5MHz and I've done up to 140,000 samples per second this way, although because of the jitter I get at 5MHz, there's seldom any reason to go beyond about 24,000 interrupts per second, depending on the application.  The processor has no problem keeping up, assuming you don't have a lot of math or other processing to do for each sample.  You could still combine sounds at different frequencies and from different wave tables in software numerically controlled oscillators (NCO).  Barnacle wrote that brick-wall filtering is hard.  The reason for this is that component tolerances have to get really tight compared to what we usually deal with in hobby.  I can give you a circuit for a 5th-order low-pass filter though, which although not an 8th-order, achieves the purpose if you stay a little further below the Nyquist frequency, and works well with relatively standard resistors and MLCCs.  You can scale the cut-off frequency up and down by dividing or multiplying resistor and/or capacitor values by the proportion you want to move it.

Proxy wrote:
question just is, what's a good sampling rate? (ie speed at which data is loaded into a DAC/SN76489). 44.1kHz would be ideal, but that also means loading 43kB of data every second.

I've done intelligible speech at about 6 or 8ksps and only two or three bits, which was all you got from early talking toys.  (This assumes the speech is already compressed into a very narrow dynamic range.)  The toys usually did not go to the expense of using an output anti-aliasing filter though, so there were some strange effects which you'll avoid if you do use one.  Even for music, I don't think you'll need nearly as many bits per sample as you probably think you do if the music doesn't have the dynamic range of classical music.

The sound quality of high-end audio cassettes, just before CDs took over, was pretty darned good; and you can get almost the same S/N ratio with just 8 bits, and you can get much better frequency response if your sampling rate is up to the job, and much more consistent high-frequency output, and without the flutter.  The first time I heard digital audio was at an Audio Engineering Society (AES) convention.  Although it sounded really good and mostly really clean, there was something about it that sounded strange, which I figured later must have been because their anti-alias filters were inadequate, and the small amount of intermodulation distortion probably from the speakers acting on the ultrasonic image aliases were producing these artifacts at audible frequencies.

Here are a couple others of my posts that I think will be helpful:
viewtopic.php?p=30252#p30252
viewtopic.php?p=16393#p16393
See also other posts in the same topics.  (Wow—I can't believe these are about a decade old already!)

Re: Audio IC

Posted: Fri Jul 14, 2023 4:43 pm
by barnacle
GARTHWILSON wrote:
Although it sounded really good and mostly really clean, there was something about it that sounded strange, which I figured later must have been because their anti-alias filters were inadequate, and the small amount of intermodulation distortion probably from the speakers acting on the ultrasonic image aliases were producing these artifacts at audible frequencies.
Aliasing occurs when a signal of higher frequency than the Nyquist limit remains present on the signal being sampled. The practical effect is that it is reflected into the frequency below the Nyquist limit: for example, if you're sampling an 11kHz signal at 10kHz, the alias frequency is at 9kHz and as that frequency increase, the alias frequency drops. But the filtering reduces its level as it gets further above the Nyquist limit so you mostly hear aliases close to the limit. And of course, once they're sampled, they're there for good; there is absolutely no way to remove them.

So it's possible to get ultrasonic aliases - and you're most likely to get them there because of the limitations of practical filters - but most people aren't going to hear them, unless the amplifiers/speakers are really bad.

Interestingly; that's how software defined radio works: an RF signal is sampled at a rate _way_ too low to meet Nyquist, deliberately introducing aliases in defined bands, one of which can be isolated for further processing.

Neil

Re: Audio IC

Posted: Fri Jul 14, 2023 7:52 pm
by Agumander
AndrewP wrote:
I'm going this route too but I'm putting the DAC behind a pair of 74HCT40105 16x4bit FIFOs (in parallel for 8bits). I then use a 32KHz clock divided-by-two to tick 8bits out of the FIFOs into the DAC at 16KHz.
I too have a "FIFO" though it's only one byte :P

I have a bit less to worry about with timing though since I dedicate a second 6502 to producing samples. The interrupts are produced by a 40103 clocked at 1/4th the rate of the audio processor clock. At the slowest setting it has 1024 cycles to produce samples at 13.6kHz.

Re: Audio IC

Posted: Wed Sep 20, 2023 1:40 am
by sburrow
Agumander wrote:
How much of the lifting do you want it to do for audio? I just use a TLC7524 DAC and compute samples directly on a 6502
gfoot wrote:
If you have a VGA-capable video circuit then that is outputting about 30,000 scanlines per second - you could piggyback on that to grab one or two bytes during each blanking period for audio output. It's kind of life a free FIFO - the CPU can populate those bytes ahead of time once per frame and not have to worry about timing as much as the video circuit will then send them to the sound hardware at the right rate.
I read through the entire topic and, besides being very confused about definitions and other particulars, I didn't see a one-size-fits-all answer. I like the two ideas above though. I went through the TLC7524 datasheet and, well, I don't even know where to start with DACs it seems. They recommend op-amps connected to it, etc etc. Couldn't someone create their own DAC with a latch and some resistors? I feel like I do the same thing with my video circuits, but I'm just so unfamiliar with audio basics.

Any recommended resources for me to get a rough idea of where to start? I just watched George's videos on a similar topic, one of which is here: https://www.youtube.com/watch?v=iFAMWvIqvng, I suppose I could just make duplicates of this circuit to get more voices?

I've been using my 6522's T1 timer to generate tones for a while now, but I'm looking for something more capable than a single-voice output. Any suggestions are welcome. Thank you everyone!

Chad

Re: Audio IC

Posted: Wed Sep 20, 2023 6:12 pm
by Sean
I ran across a page of microcontroller audio projects. Perhaps there are some ideas that could be cadged from there.

http://elm-chan.org/he_a_e.html

Re: Audio IC

Posted: Wed Sep 20, 2023 7:03 pm
by gfoot
sburrow wrote:
I read through the entire topic and, besides being very confused about definitions and other particulars, I didn't see a one-size-fits-all answer. I like the two ideas above though. I went through the TLC7524 datasheet and, well, I don't even know where to start with DACs it seems. They recommend op-amps connected to it, etc etc. Couldn't someone create their own DAC with a latch and some resistors? I feel like I do the same thing with my video circuits, but I'm just so unfamiliar with audio basics.
I think you could use a resistor network for the DAC, depending on what you're driving though I think you may still need an op amp or something similar to form an analogue buffer. There's a very simple way of using an op amp to just copy a voltage level, by connecting the output pin to the inverting input pin.
Quote:
Any recommended resources for me to get a rough idea of where to start? I just watched George's videos on a similar topic, one of which is here: https://www.youtube.com/watch?v=iFAMWvIqvng, I suppose I could just make duplicates of this circuit to get more voices?
I never followed that video up, but I did put two of those together, and it worked fairly well. It's basically what you're doing with the 6522, but using external counters. You only get square wave output of course, and constant volume. If you used two or more together then you'd need to mix the signals, but you could use a XOR gate for that as the signals are digital - or you could use an op amp to add two analogue signals together (or rather, to interpolate between them, but it's effectively the same thing).

I also tried to add a digital volume control/mixer, but my analogue electronics were not up to scratch, I'm sure my approach was very poor. This is where unless you're really interested in how to make the circuit work, it makes more sense to use an off-the-shelf part, if you can find useful ones that are still produced.

If you want really good sounding audio then Moritz Klein has made many YouTube videos about various aspects of analogue synths, which are well presented and fairly easy to follow, but perhaps not so much aimed at microprocessor control.

If I ever want to make good audio with a 6502-based system, my main plan has always been to use large ROMs for wavetable synthesis. I have some ridiculously huge EPROMs that could be programmed with all sorts of things - different waveforms, amplitudes, mixes between signals, etc.

But I do like the idea of encoding it into the video memory, for something mixed by the CPU. Another approach that AndrewP pointed out (I think?) is to use FIFOs, allowing the CPU to take an interrupt and write a batch of samples into the FIFO, then the other end of the FIFO drives some form of DAC. All that said, I am wary of anything where the data comes from the CPU though as it's going to be fairly expensive on the CPU to do any serious mixing.

Re: Audio IC

Posted: Thu Sep 21, 2023 1:49 am
by Yuri
sburrow wrote:
Agumander wrote:
...

I read through the entire topic and, besides being very confused about definitions and other particulars, I didn't see a one-size-fits-all answer. I like the two ideas above though. I went through the TLC7524 datasheet and, well, I don't even know where to start with DACs it seems. They recommend op-amps connected to it, etc etc. Couldn't someone create their own DAC with a latch and some resistors? I feel like I do the same thing with my video circuits, but I'm just so unfamiliar with audio basics.
You could make a DAC with a resistor ladder for an audio circuit just as you would for a video circuit, how good it would be would depend on how accurate your resistor tolerances are. Personally I'd prefer to use a premade DAC for that purpose. That way I don't have to mess with having to figure out if I have a problem with wiring vs. resistors vs. something else.

As for the Op Amp, these can be had for fairly cheap and if you're just driving line level voltages to another bit of stereo equipment, you shouldn't need to go crazy. Take a look at the LM386, there are a plethora of instructions on the web on how to hook it up to act as a hi fidelity amplifier for high end headphones. (Note, that would be too high for line level voltages, but the principles are the same.)

Re: Audio IC

Posted: Thu Sep 21, 2023 9:48 am
by gfoot
It's well worth checking out the Music 5000 thread (viewtopic.php?f=4&t=4436) that Chris Jordan has just joined and resurrected - it was a very impressive system from the 80s that he designed, and while it's probably more complex and capable than you were looking for, it could be a good source of inspiration and maybe there are some useful subsets of the functionality that could make sense.

Re: Audio IC

Posted: Sat Jan 31, 2026 9:35 pm
by No True Scotsman
Agumander wrote:
How much of the lifting do you want it to do for audio? I just use a TLC7524 DAC and compute samples directly on a 6502
My first audio peripheral will be based on the TLC7528 (the dual version of the 7524) in voltage mode.

Today, I learned that a raw PCM file is simply a list of samples in left-right-left-right order, with no header or framing information. It should be relatively easy to set a timer to count down the sampling period and trigger an interrupt to load two samples into the DACs without having to parse a bunch of metadata.

I further learned that FFmpeg can covert any audio file to unsigned 8-bit raw PCM, which is exactly what I need to feed the two voltage-mode DACs.

The outputs of the DACs will be buffered and low-pass filtered using two TS922 rail-to-rail op amps before going into a PT2257 stereo volume control and a pair of LM386 audio amps.

(Question: Is it possible to both buffer and low-pass filter a DAC output using only one op amp?)

My second sound module will be based on the SAA1099 stereo sound generator. Hearing this chip ruined me for the SN76489 and the like. It's probably as close as I'll ever get to a SID again at a reasonable cost.

Re: Audio IC

Posted: Sun Feb 01, 2026 3:29 am
by GARTHWILSON
No True Scotsman wrote:
(Question: Is it possible to both buffer and low-pass filter a DAC output using only one op amp?)
How sharp do you want the filter?  And does your DAC have a voltage output, or a current output?  A VCVS (voltage-controlled voltage source) 2nd-order filter can be done with a single op amp if you start with a signal voltage instead of a current.  You could follow it with an RC for a 3rd order, if the load is relatively high impedance.  I can't offhand think of a way to do it with a current-output DAC though.  Also, what are you considering to be a buffered output?  Common, cheap op amps can't handle a very heavy load, especially capacitive, since their output impedance is not zero like the ideal, theoretical op amp has, and that combined with the capacitive load put an extra pole in the transfer function, and depending on where that pole is, in the Nyquist plot, you may lose your phase margin and get an oscillator.

What I have done, many times, is to use an op amp pair to get a 4th-order LP filter, followed by an RC to get the 5th, and then run its output into something like your LM386 to drive earphones or a speaker.  I wrote a program decades ago to simulate it and get the nicest frequency-response curve, but I no longer need to run it; I just take previous ones I've done and scale the R and C values for the desired frequency.  (Again though, this assumes a voltage input, not a current input.  If the DAC has a current output, another leading op amp will be needed for the conversion.  They come in duals and quads anyway though.)  Let me know what you think, and then I can recommend a circuit using common R and C values.  I really should add a section to my site for useful general-purpose circuits to support our hobby computers.  I really am primarily an analog designer, not digital.

Re: Audio IC

Posted: Sun Feb 01, 2026 6:19 am
by barnacle
There's a trick the old (ancient?) Soundblaster cards used, whereby they used a switched capacitor filter chip clocked from the ADC/DAC sampling frequency (or some multiple thereof; I don't recall which) so that the anti-aliasing and reconstruction filters tracked the sampling frequency.

Very sneaky; the only real issue was that at the highest sampling frequencies, there was also a bottom end high-pass filter (in addition to the expected top end low-pass filter) which gave a lower response limit of around 300Hz.

Never used it myself; just had to fight with it to get the cards to work as we needed them.

Neil

Re: Audio IC

Posted: Sun Feb 01, 2026 1:24 pm
by No True Scotsman
GARTHWILSON wrote:
No True Scotsman wrote:
(Question: Is it possible to both buffer and low-pass filter a DAC output using only one op amp?)
Also, what are you considering to be a buffered output?
The goal is to prevent the output voltage from sagging under load. I'm not sure if it's even necessary with this DAC, but I've always heard it's done.

Re: Audio IC

Posted: Sun Feb 01, 2026 4:57 pm
by No True Scotsman
No True Scotsman wrote:
I'm not sure if it's even necessary with this DAC....
Well, I remembered the datasheet saying the DAC behaves like an R2R ladder in voltage switching mode, which suggested to me that an op amp output buffer will be needed.

I was looking at chapter 4 of Analog Devices' CMOS DAC Application Guide just now, and it appears to confirm it.