Jump to content
  • 0

PSG


Yazwho
 Share

Question

Ok, I'm starting to hate writing audio code! So annoying to debug as you can't just stop and have a look at what's going on...

Ahem, anyway.. Is there an order that the PSG data should be written to the channels? I've got some very rare crackling and am wondering if its because the data is being used before its properly loaded, or some other sequencing problem. Should I prepare the data and just copy it in over during the vsync or similar? Is there a specific time when the channels are read?

Link to comment
Share on other sites

6 answers to this question

Recommended Posts

  • 0
6 minutes ago, StephenHorn said:

When I read "crackling" in a problem description with audio, my first thought is to ask: Was the emulator running at 100% speed? If not, it's possible that the audio output buffers created by the emulator are being exhausted.

In my experience, every program that uses audio may have some degree of noise caused by the emulator. This will likely not occur on actual hardware.

Link to comment
Share on other sites

  • 0

You can run the emulator with the command line option "-abufs 16". This increases the audio buffer from the default 8 to 16. This helped me with occasional audio dropouts (which I forgot to do in my videos, lol) You could increase the number further. At some point, you will start to notice lag in audio, I think.

Audio crackling can also appear when the emulator isn't running at 100% speed, such as often in the web-emulator, or I found when using the debugger, the speed could also change.

I think the order in which you set volume, frequency and waveform shouldn't play a significant role, at least in my experience so far. (Edit: well, as long as there is no significant lag between the writes.)

Edited by kliepatsch
Link to comment
Share on other sites

  • 0

Thanks all,

14 minutes ago, kliepatsch said:

I think the order in which you set volume, frequency and waveform shouldn't play a significant role

Is that the same for only setting\changing one of the 4?

-abufs16 is good to know, but unfortunately didn't fix the issue, although it does sound a bit better. using 32 or more doesn't do much though.

My machine isn't CPU throttled, so I dont think its that.

I'll rewrite the code to do it all in the vsync, maybe that will help...

Link to comment
Share on other sites

  • 0

I don't think that setting audio parameters during VSYNC or not during VSYNC should make any difference, especially not with the PSG which will just happily keep entoning whatever waveform at whatever frequency it is currently set to.

I've been doing a lot of digging through the MAME sources on how they emulate various audio hardware, and the thing about emulators is that they tend to drive the virtual audio hardware components in bursts - snagging a few hundred samples at a time. The X16 emulator grabs samples from the YM2151 in blocks of 256 (and I assume the PSG and DSP as well, but didn't go looking through that part of the code). If the emulator ever fails to produce the samples in a timely fashion, then the host's audio buffer will just run dry. Real HW wouldn't have this issue with the PSG or the 2151.

Changing just the freq or volume is very normal in chip music, as that's how effects like porta and volume fades happen - the order matters more on chips like SID and the YM because those have envelope generators which have a notion of keyDN/keyUP to signal the attack/decay/sustain/release. The VERA PSG doesn't have any kind of EG, so pretty much do whatever you want. I don't know deep down inside how it handles nuanced things - for instance, does the waveform's phase reset to 0 whenever you poke a freq into it, or does it just speed up / slow down its stepping through the waveform at whatever offset it happened to be at the time? Only if you get to really bit-banging the chip extra hard would such things have much effect on the sound output.

Try putting a single tone on a few voices, and then start doing things that would busy the emulator but not the X16 itself - turn on the mouse pointer and start moving that around - resize the window a bunch of times - have a bunch of visible sprites turned on (w/o bothering to update them at all) - etc - but leave the PSG playing a flat tone. If it crackles, then it's the emulator failing to fill its sample quota to the host's sound routines when requested.

Link to comment
Share on other sites

  • 0
8 hours ago, ZeroByte said:

I don't know deep down inside how it handles nuanced things - for instance, does the waveform's phase reset to 0 whenever you poke a freq into it, or does it just speed up / slow down its stepping through the waveform at whatever offset it happened to be at the time?

As far as I can tell, the phase doesn't get reset to 0. There is simply no way to do it. The phase offset is just increased with a rate according to whatever frequency the voice is currently set. In my experience so far, updating the PSG registers very often doesn't have a negative impact on audio quality.

(Why do I think the phase doesn't get reset? Two reasons: 1. Pitch slides work perfectly fine. If the phase would be reset on every update, the tone would sound distorted when doing pitch slides. 2. Turning on a triangle wave (from 0 volume to some nonzero value) produces a click with seemingly random intensity. This correlates well with the playback starting at a random point in the wave cycle, producing a sharp edge in an otherwise smooth waveform.)

Edited by kliepatsch
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.

Guest
Answer this question...

×   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.

 Share

×
×
  • Create New...

Important Information

Please review our Terms of Use