LisaList2

Advanced search  

News:

Want an XLerator? Please participate in the market research thread: https://lisalist2.com/index.php/topic,594.msg4180.html

Pages: [1]   Go Down

Author Topic: Can a PET audio technique work on a Lisa?  (Read 6351 times)

stepleton

  • Sr. Member
  • ****
  • Karma: +147/-1
  • Offline Offline
  • Posts: 480
Can a PET audio technique work on a Lisa?
« on: April 30, 2025, 06:57:09 pm »

Oh for more spare time...

A Commodore PET 40xx/80xx has a speaker hanging off of pin 19 (CB2) of a 6522 VIA. See PDF page 4 of https://www.zimmers.net/anonftp/pub/cbm/schematics/computers/pet/univ/8032032.pdf

An Apple Lisa has a speaker hanging off of pin 19 (CB2) of a 6522 VIA (the keyboard VIA specifically). See the TONE signal on PDF page 2 of https://bitsavers.org/pdf/apple/lisa/hardware/Lisa_1_IO_Board/050-4008-H_IO.pdf and then the speaker on page 5.

This person has got a simulated PET to play (scratchy) audio samples from its speaker. Skip to the end to see the final product:
https://www.youtube.com/watch?v=3SlRbYfyNRY

The PET runs at 1 MHz and has a few dozen kilobytes of RAM. The Lisa: 5 MHz and many more. Could we use the technique in the video to boot into some assembly code that plays an audio sample on a Lisa without a DAC?
« Last Edit: April 30, 2025, 06:58:40 pm by stepleton »
Logged

warmech

  • Full Member
  • ***
  • Karma: +19/-1
  • Offline Offline
  • Posts: 33
Re: Can a PET audio technique work on a Lisa?
« Reply #1 on: May 01, 2025, 02:57:30 pm »

Alex and I discussed this as a potential demo for VCF in June, but we wound up scotching it for reasons I cannot immediately recall. I want to say it had something to do with insufficient duty cycle resolution for working with PWM audio, but that may be my current lack of coffee so far today. Whatever the reason was, it was extremely specific; I may let him chime in with his thoughts, rather than just guess, lol.
Logged

sigma7

  • Administrator
  • Hero Member
  • *****
  • Karma: +170/-1
  • Offline Offline
  • Posts: 573
  • Warning: Memory errors found. Verify comments.
Re: Can a PET audio technique work on a Lisa?
« Reply #2 on: May 01, 2025, 05:44:55 pm »

Oh for more spare time...

... code that plays an audio sample on a Lisa without a DAC?

I can barely imagine some of the wonderful things you would do if you had more spare time!

Not the same, but I think the simplest approach conceptually is copying pre-processed PWM data from a range of memory to the VIA.

eg. a series of MOVE (A0)+,(A1) instructions, where A0 points to a range of memory containing appropriate PWM data and A1 points to the VIA's PCR register which can set CB2 (the TONE output) high or low.

That instruction takes 16 cycles, and at 5 MHz, that means 3.2 us per write, making the maximum toggle rate about 156 KHz.

If you want hi-fi, then 1/4 of that rate could be sufficient, and by pre-loading 2MB of memory you might get 50 seconds of sound.

However, the pre-processing step seems too compute intensive to perform a real-time conversion from conventional samples of a hi-fi analog signal to PCM with hi-fi quality. Perhaps the PET example has some clever/efficient way to do it, or you can load the samples and wait while it is converted to PWM.

I suppose a custom build of the ESProFile software could allow continuously streaming (rather than sector by sector) PWM data from the parallel port to the speaker, but that's probably cheating.

Another approach is to use the Lisa's 3 bit level/volume control in conjunction with the PWM technique (at the cost of losing volume control :) )

eg. use the polarity of a sample to set the TONE signal high or low, then apply 3 bits of the magnitude of the sample to the level control. That would make a 4 bit DAC with a pretty fast sample rate, perhaps adequate for recognisable speech, assuming your source file has the corresponding sample rate.

Or add a jumper (maybe it needs capacitor coupling) from the output of the 6 bit Contrast DAC to Spkr In, and you'll have a high sample rate, retain volume control, and bonus visual effects!

edit: changed PCM to PWM, although I suspect it doesn't matter in this case
« Last Edit: May 02, 2025, 05:29:49 am by sigma7 »
Logged
Warning: Memory errors found. ECC non-functional. Verify comments if accuracy is important to you.

stepleton

  • Sr. Member
  • ****
  • Karma: +147/-1
  • Offline Offline
  • Posts: 480
Re: Can a PET audio technique work on a Lisa?
« Reply #3 on: May 01, 2025, 06:27:43 pm »

In the video, the technique that really seems to have made it possible for the PET was taking advantage of the 6522's shift register capability --- this allowing you to "byte-bang" the modulated audio signal into the VIA instead of bit-banging it. This is why the speaker being attached to CB2 is significant, as that's the shift register output.

This method could potentially boost the duty cycle resolution by up to 8x in comparison to directly toggling the CB2 line.

The 3-bit speaker offers an additional kind of control that could be quite powerful, but I haven't checked whether VIA lines PB1-3 can be altered conveniently whilst the VIA is in shift-register mode. If they can, you could imagine using it to account for the slowly-varying "envelope" of the sound. This would allow the pulse modulation to be dedicated to a kind of "compressed" version of the signal, relieving it of a lot of the work it would need to do otherwise to capture the audio's dynamic range. I suspect that would mean better fidelity.

(FWIW: speaking for myself, I'd be happy with the modulation all taking place offline or on a different computer and the Lisa simply "playing back" data from a specially-prepared file.)
« Last Edit: May 01, 2025, 06:30:36 pm by stepleton »
Logged

AlexTheCat123

  • Sr. Member
  • ****
  • Karma: +82/-1
  • Offline Offline
  • Posts: 302
Re: Can a PET audio technique work on a Lisa?
« Reply #4 on: May 01, 2025, 08:17:24 pm »

In the video, the technique that really seems to have made it possible for the PET was taking advantage of the 6522's shift register capability


The reason why I scrapped this idea when I first thought of it a couple months ago is because that shift register would only allow us to produce 9 different duty cycles (one for each bit that we can set in the shift register, plus the case when they're all zeros), which is basically equivalent to 3-bit PCM samples. And since this is some really terrible duty cycle resolution, I gave up on the idea.


But instead of using PCM, the guy in this video appears to be doing something called PDM (Pulse Density Modulation), where the density of ones in the bitstream going to the speaker is directly proportional to the amplitude of the audio signal. I had never even heard of PDM before, but now that I'm aware of it, I don't see any reason why this idea wouldn't work on the Lisa!


I recently redesigned a class for one of my professors at my university, and one of the labs that I created involves using an ESP32 to play back PCM-sampled audio on a speaker using the ESP32's hardware peripherals. I can fit a good 40-ish seconds of 16KHz unsigned 8-bit sampled audio into the ESP's 1MB of flash, so a 1MB Lisa should also be perfectly capable of playing back reasonably-long audio files at a pleasant sample rate. And a 2MB RAM card gives you even more space!



Logged

stepleton

  • Sr. Member
  • ****
  • Karma: +147/-1
  • Offline Offline
  • Posts: 480
Re: Can a PET audio technique work on a Lisa?
« Reply #5 on: May 02, 2025, 04:16:49 am »

Another potential advantage of modulating the volume:

In PDM, the representation of "no sound" (that is, a flat line at 0) is 101010101010101010101010: 50% on/off at the highest frequency possible. If we just play that at a fixed volume, there are a few possible consequences, not quite all exclusive of each other:

(bad:)
- This frequency is audible, or within the Lisa's audio system, it generates audible resonant tones. Annoying!
- Same, but maybe too high for humans, still audible to any pets.

(fine:)
- The audio system doesn't have adequate bandwidth for that frequency and so it essentially gets smoothed out and behaves like a DC bias on the speaker.

My money is on the (bad) outcomes being more likely, in which case being able to turn the speaker right down is going to be a big quality of life improvement. But even if things are (fine), I'm still pretty sure that relieving PDM of the need to recreate the audio's dynamic range will be an important quality win.
Logged

sigma7

  • Administrator
  • Hero Member
  • *****
  • Karma: +170/-1
  • Offline Offline
  • Posts: 573
  • Warning: Memory errors found. Verify comments.
Re: Can a PET audio technique work on a Lisa?
« Reply #6 on: May 02, 2025, 04:53:10 pm »

When the VIA is shifting out bits, the maximum shift rate available is phi2/2

On the 2/10 I/O Board, the VIA phi2 is CPUCLK/4, so about 1.25 MHz.

On the Lisa 1/2 I/O Board, the VIA phi2 is the 68K's E clock, which is CPUCLK/10 (with a 60/40 duty cycle IIRC, but that doesn't matter here).
With a stock CPU Board, E is about 500 KHz, and with an original 16 MHz XLerator, E is 1.6 MHz.

So the slowest hardware configuration's maximum shift rate is 250 KHz per bit, making the byte rate about 31 KHz. So that suggests the output in the audible spectrum will essentially average to the count of high bits - one of nine amplitudes corresponding to 0 bits high to 8 bits high.

The shift register can be set to shift bits slower than that using the T2 counter, but then you'll hear individual bits.

I expect one can manage to write a new byte at the same rate as it is shifted out, so you end up with performance of a 3 bit 31 KHz DAC.

If you simultaneously change the volume, I suppose one might get close to a 6 bit DAC.

Good luck!
Logged
Warning: Memory errors found. ECC non-functional. Verify comments if accuracy is important to you.
Pages: [1]   Go Up