Jump to content
IGNORED

Using Pulse Density Modulation for 8-bit PCM


kool kitty89

Recommended Posts

Just a small request: Would you guys consider posting a video or audio file, even attach an MP3? I have an NTSC and I can't run the PAL stuff that I would so like to hear.

 

Thanks.

 

The PAL files should work on NTSC. They'll just sound slightly higher pitched than they should. Vice versa going from NTSC to PAL.

  • Like 1
Link to comment
Share on other sites

Hello Kyle

 

Just a small request: Would you guys consider posting a video or audio file, even attach an MP3? I have an NTSC and I can't run the PAL stuff that I would so like to hear.

 

Check out message Nr. 193 in this thread.

 

Sincerely

 

Mathy

Edited by Mathy
  • Like 1
Link to comment
Share on other sites

  • 10 months later...

Since a few people have emailed asking for the 1088XEL version of the PDM player, here's a ZIP file containing both the SIDE and XEL-CF versions of the player until I get a dedicated page set up on my website:

 

pdm.zip

 

I realise the player is in need of updates, including all the file handling fixes and improvements I've made to the XEX loader on which the player is closely based, stereo support, etc. It's on the to-do list. :)

 

  • Like 10
Link to comment
Share on other sites

  • 5 months later...
  • 4 weeks later...

I'm doing little something with digital playback, and I decided to finally try this trick by myself. It seems to work nicely in current Altirra, I use values 3,5 or 1,3.

But what is the consensus about the real hardware ? Is it reliable enough among all the machines ? Is there some new development ? I don't remember seeing anything new in this are for like a year.

Link to comment
Share on other sites

Supposedly Pokey's are much the same regardless of source although the external circuitry does affect the resultant waveform and might be different among models.

But I'd regard it as reliable enough to guarantee consistent results.

If it was the fact that there were differences we'd probably be able to work them out and document them to the point of knowing adjustment values per machine (though deducing exact machine model isn't an automatic thing - we can reasonably deduce if a computer is 400/800 but not which of those, XEGS due to ROM and memory control difference, 130XE due to extra RAM though throwing a spanner in the works there is expansions like 3rd party memory and U1Meg which can make a base machine appear different)

 

Probably the biggest audio inconsistencies are GTIA audio (speaker vs piped through) and the playback by tape motor control toggle having a different result depending on if it's a 410 or 1010 attached (I don't know about other models or 3rd party decks).

Link to comment
Share on other sites

52 minutes ago, R0ger said:

I'm doing little something with digital playback, and I decided to finally try this trick by myself. It seems to work nicely in current Altirra, I use values 3,5 or 1,3.

But what is the consensus about the real hardware ? Is it reliable enough among all the machines ? Is there some new development ? I don't remember seeing anything new in this are for like a year.

Well, there is the recent research done in this thread, starting from this post:

 

 

But I haven't seen anyone talking about important differences, between different machines..

 

Link to comment
Share on other sites

  • 1 month later...
  • 5 months later...

I should probably post about this on Spritesmind or something (I'm not sure I even have an account on there), but might as well mention it here given the conceptual overlap and on the off-chance any of the Atari 8-bit computer coders out there are also messing with PC Engine stuff. (I've seen a couple people doing that in the past, 6502 code heads and all) And heck, I've had this in my head for over 6 years now and haven't really talked about it anywhere.

 

 

 

 

But it seems to me you can use the 32x5-bit wave sample buffers in the Hu6280 CPU/Sound chip to store 5-bit PDM information, so you get the 32 amplitude levels from each 5-bit word, plus 32 additional linear levels from the pulse density (hypothetically more than that with more complex noise shaping, but I'm thinking simpler than that but still nicer sounding than straight PWM) so an effective 10-bit output.

 

In this case I think it's more literally PDM and not sort of twisting the definition as I did with my starting post for this topic. It's sort of like pushing bits through a serial shift register in loop mode at a high idle clock rate, but you're shifting out 5 bit words rather than 1 bit. (so in effect you're spitting out a looping, oversampled high frequency multi-pulse waveform that gets effectively filtered down to a linear amplitude sample)

 

You'd need to double buffer samples using 2 of the sound channels intermittently, muting the back buffer and loading it, then waiting to update the sample output (via cycle counted code or a timer interrupt). I was mostly thinking in terms of timer interrupts here since this method could allow similar sample rates to the other 10-bit PCM hack (using 2 channels and a volume offset for upper and lower 5-bit values, or less of an offset for just 8-bit resolution, but in any case requiring the CPU to set every single sample manually, so one interrupt per sample played if using an interrupt driven routine).

 

So with the onboard timer interrupt, you get approximately 6.99 kHz or an integer division of that. So that'd be 6.99 kHz 10-bit PCM output, potentially with software-mixing of multiple 8-bit channels, ADPCM or DPCM decoded samples, etc (with a look-up table to convert 10-bit linear PCM to the appropriate 32x5-bit register data). But more useful/less CPU intensive than that would be to chop the 32x5-bit buffer into 4 chunks of 8x5-bits for 4x 8-bit resolution interleaved/multiplexed channels. (useful for simplified code and low overhead mixing of 8-bit samples, or compressed samples decoded to 8 bits, plus additional software mixing on any of those 4 channels to 8-bit saturation: also lighter since pure 8-bit math is faster than mixing to 16 bits and clipping to 10)

 

Further, if you could synchronize the timer interrupt with the wave buffer playback frequency, so rather than looping the sample only plays once per interrupt, you could also potentially use the same basic technique to achieve 27.96 kHz 8-bit playback with that same 6.99 kHz interrupt. (worst case you'd still have some 6.99 kHz carrier tone aliasing where the idle high looping technique oversamples those overtones out of the audible range) You could also use slower timer intervals for less overhead, but then the aliasing falls more and more into the audible and nasty range.

 

Since the wave generator and timer are based on the same source clock, I'd think you could synchronize them as such, but not sure.

 

The oversampling 'whole 32x5-bit buffer as a single amplitude sample' seems like the more foolproof option, and the one that seems more like 'why didn't someone do that back in the 90s' sort of thing. Plus it's got the advantage of leaving the 4-bit logarithmic volume control totally free, so you can play with master volume on the simulated-PCM channel(s) by just setting the volume register as normal. (or potentially do Amiga-style extended resolution by modulating that volume level on top of everything else: something that does work on the PC Engine, but requires intermittent channel use to avoid clicks/pops when the volume register is set, which is irrelevant if you're already using 2 channels in a double buffered set-up)

 

Or take another 2 channels (for double buffering) and use the same mechanism there for 10-bit output, then use a volume offset to allow that to be added with the first channel for 20-bit output. Of course, that's kind of pointless at 7 kHz, and more interesting if you could get the ~28 kHz 8-bit synchronized method working and used the volume offset for low+high 8-bits and 28 kHz 16-bit mono output. (which would be pretty nice, potentially a lot nicer and more flexible for streaming compressed or uncompressed PCM audio from the CD Unit than trying to buffer into the hardware ADPCM decoder:  useful compared to straight redbook audio even with 16-bit 28 kHz LPCM since it takes up less space on disc and could allow more dynamic uses of sound/music data and interspersed game data loading, but also much more useful for software mixing multiple sampled SFX channels rather than choppy single-channel ADPCM SFX)

 

**that and this leads into another topic regarding how the ADPCM decoder in the CD-ROM module was kind of pointless and would've been nicer to have a full 128kB of program RAM instead of the separate 64kB of ADPCM buffer RAM. 

 

 

 

 

 

 

** on a side note, a typical 8-bit shift register in loop mode could be used for 1-bit PDM with effective 3-bit linear amplitude per byte loaded. (I looked into that a while back for potentially hacking VIA or ACIA type chips for sampled sound output, but their max bitrate seemed too low to be really useful for that: though using them for looping 1x8-bit sample, complex pulse tone/noise waveforms seemed a little more interesting)

I'd think POKEY's serial data output could also be hacked similarly, for what that's worth.

 

 

 

 

  • Like 1
Link to comment
Share on other sites

7 hours ago, kool kitty89 said:

I'd think POKEY's serial data output could also be hacked similarly, for what that's worth.

Funny you mention this. I thought about this once, too. Never got any further, but it could be a nice project. Especially if you put a 400-500kHz clock on clock-in. I think the start and stopbits won't interfere. Run serial out through a low-pass filter, amp and you have line-out :)

 

Edit: or loop back to audio-in!

Edited by ivop
Link to comment
Share on other sites

Here's an "old-skool" sketch which could turn Pokey into a high speed 1-bit DAC.

 

sio-dac-sketch.thumb.png.317faa12f02414691a9d833a69755a53.png

 

There's a Don't Dead Open Inside in there ;)

 

But seriously, any opinions, improvements, thoughts on this?

 

The start and stop bits might have to be mitigated for in software. And what should the oscillator's frequency be? 32MHz would lead to 250kHz on pin G (/128). 40MHz is 312.5kHz. Not sure how fast is possible. I know Mr. Atari did experiments with externally clocked SIO at around 500kHz for reading and around 400kHz for writing that worked. But in this case the audio data has to be streamed from somewhere, too, which also takes time, so 312.5kHz might even be on the high side. 250kHz might be possible. Double of what Pokey can generate itself.

 

  • Like 1
Link to comment
Share on other sites

  • 9 months later...
  • 2 years later...
On 6/4/2018 at 5:42 PM, Stephen said:

Oh man! If you can get your SID player using PDM - I wonder how close to an original SID it would be?

It took some time, but I finally remembered this was something I wanted to try.

 

This only runs on Altirra 4.10 (didn't check any older versions), and it does not work correctly on atari800 because its Pokey emulation is broken.

 

Nevertheless, I checked on real hardware and it sounds worse than on emulation. Not good. Without having to read through this whole thread, did you eventually agree on which AUDF values during init works best on real hardware? It currently uses 3 and 12.

 

Do you think v7 sounds better than v6.1?

 

@Stephen perhaps you can try on real hardware and your cool audio equipment and tell me how it sounds? I hear some sort of noise in the background that's not there on emulation.

new-v7.xex old-v6.1.xex

  • Like 2
Link to comment
Share on other sites

2 hours ago, ivop said:

It took some time, but I finally remembered this was something I wanted to try.

 

This only runs on Altirra 4.10 (didn't check any older versions), and it does not work correctly on atari800 because its Pokey emulation is broken.

 

Nevertheless, I checked on real hardware and it sounds worse than on emulation. Not good. Without having to read through this whole thread, did you eventually agree on which AUDF values during init works best on real hardware? It currently uses 3 and 12.

 

Do you think v7 sounds better than v6.1?

 

@Stephen perhaps you can try on real hardware and your cool audio equipment and tell me how it sounds? I hear some sort of noise in the background that's not there on emulation.

new-v7.xex 7.87 kB · 0 downloads old-v6.1.xex 6.4 kB · 0 downloads

There is some noise on the real hardware due to switching artifacts, which PDM is sensitive to because of the high-frequency switching. One source is that the gates for the volume bits don't switch at the same speeds.

 

image.thumb.png.68301735a0cf87a62d4973c13826e6e3.png

  • Like 5
Link to comment
Share on other sites

Based on this and the thread in the Programming section, there's been discussion about leveraging POKEY to do wavetable synthesis.  I'm not technically up to speed as most here, but I do play music and own quite a bit of gear, so I'm not a total idiot.

 

My understanding of wavetable synthesis is that you leverage a waveform, presumably a small bit from a sample, to create sounds.  The PPG is the most well known and one of the pioneers of this technology.

 

This is opposed to what some call "romplers" - basically using the actual sample to create sound.  Not a sampler per se, but not using the pure sampled waveform as noted with wavetable synthesis.

 

I've listened to the examples here - it's sample based, but it looks like it's not sampled music...or am I misunderstanding?  Is there a "dummies" version of what is being explored here?

Link to comment
Share on other sites

On 10/21/2023 at 3:24 PM, ivop said:

@Stephen perhaps you can try on real hardware and your cool audio equipment and tell me how it sounds? I hear some sort of noise in the background that's not there on emulation.

Sorry - I have been super busy but am hoping to make time to get one of my Atari's running on the test bench so I can scope the audio.  I did a really quick test if those 2 versions on Altirra, did not use my headphones or earbuds, but couldn't really hear a difference.  I will let you know how the real hardware sounds.

Link to comment
Share on other sites

15 hours ago, Stephen said:

Sorry - I have been super busy but am hoping to make time to get one of my Atari's running on the test bench so I can scope the audio.  I did a really quick test if those 2 versions on Altirra, did not use my headphones or earbuds, but couldn't really hear a difference.  I will let you know how the real hardware sounds.

Thanks. Here's a song that more clearly has a higher fidelity in 8-bits. On Altirra it definitely sounds better, but on real hardware I was not so sure. But I have terrible speakers, even normal Pokey doesn't sound that clear, so I was wondering what others with better hardware think.

 

More files are here: https://github.com/ivop/atarisid/tree/master/atarisid7/xex

 

 

as6s-cn.xex as7s-cn.xex

Edited by ivop
  • Like 1
Link to comment
Share on other sites

On 10/22/2023 at 4:10 PM, rdefabri said:

I've listened to the examples here - it's sample based, but it looks like it's not sampled music...or am I misunderstanding?  Is there a "dummies" version of what is being explored here?

Yes, the SID emulator uses 256 bytes waves (well, 512 bytes, but it's twice the same period which makes faster code possible) to simulate the SID sound. Each waveform, pulse width, and volume has its own wave.

  • Like 2
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...