Stupid 5B questions

Discuss NSF files, FamiTracker, MML tools, or anything else related to NES music.

Moderator: Moderators

Post Reply
Rahsennor
Posts: 479
Joined: Thu Aug 20, 2015 3:09 am

Stupid 5B questions

Post by Rahsennor »

Posting this in the music section instead of the emulator section in case any musicians have experimented with these edge cases.

Is volume zero audible? (I assume it isn't, but logarithmic scales never actually reach zero.)
What happens when you set the period registers to zero? (Is it the same as 1, does it wrap, or does it do something else entirely?)
What happens when you modify the period registers? (Does it affect the next period or the current one, I.E. does the chip count down or up?)
What happens when you modify the envelope shape while it's playing? (Probably the least-understood part of the chip, I'd be surprised if anyone actually knows the answer.)

The official docs I've scrounged don't mention any of the above, and the unofficial sources all seem to disagree on something. I've even found one YM2149 emulator that seems to flip-flop between treating noise period 0 as 1 or 32 depending on which VGM pack I feed it, with no obvious mechanism for it in the source! I'd be willing to write it off as a bug if fixing it didn't make one or the other of the two packs sound very weird.
User avatar
dougeff
Posts: 3079
Joined: Fri May 08, 2015 7:17 pm

Re: Stupid 5B questions

Post by dougeff »

I found a very nice datasheet for the YM2149.

http://www.atkinsoft.com/datasheets/YM2149.pdf

Volume zero looks pretty zero on their little graph.
nesdoug.com -- blog/tutorial on programming for the NES
User avatar
rainwarrior
Posts: 8734
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: Stupid 5B questions

Post by rainwarrior »

Rahsennor wrote:Is volume zero audible? (I assume it isn't, but logarithmic scales never actually reach zero.)
What happens when you set the period registers to zero? (Is it the same as 1, does it wrap, or does it do something else entirely?)
What happens when you modify the period registers? (Does it affect the next period or the current one, I.E. does the chip count down or up?)
What happens when you modify the envelope shape while it's playing? (Probably the least-understood part of the chip, I'd be surprised if anyone actually knows the answer.)
There's no inconsistency with the logarithmic approach if you think "0-2 is 3db louder than 0-1, 0-3 is 3db louder than 0-2, etc." all of the steps between levels are on the logarithmic scale with each other, 0 is a reference baseline voltage, and 0-1 is a reference absolute step size, from which all the other logarithmic steps can be derived relatively. However, the logarithmic scale is only an ideal, I think the actual output isn't quite accurate to that PLUS I believe it's internal amplifier clips the high end of it down (on my to do list to measure this). Oh, and to answer the question, yes I believe volume 0 is silent (unless I'm remembering very badly).

Period 0 just halts the oscillator, if I recall. I don't have any precedent to expect a period of 1 to be the same as period 0 (is there some chip out there that does this?). Not sure why it would wrap, either, for the same reason.

Edit: was dead wrong about that. Period 0 acts as period 1.

The last two questions are getting into some really nitty details. At the same time as these two questions, I would ask what happens when you come out of period 0 (i.e. does period 0 work as an effective phase reset, or is it a true halt?). Asking "what happens if you --- while it's playing" is a pretty vague question though, there's more or less infinite permuations of things you could ask about this (does phase of envelope matter x number of possible phase steps, does phase of period matter x same, is there some other internal clock phase, etc. all of this x writing every bit of every control register) so all I can say at that point is...

If you've got a hotswap ROM test ready let me know and I can record it.
Last edited by rainwarrior on Fri Mar 29, 2019 6:13 am, edited 1 time in total.
Rahsennor
Posts: 479
Joined: Thu Aug 20, 2015 3:09 am

Re: Stupid 5B questions

Post by Rahsennor »

rainwarrior wrote:Period 0 just halts the oscillator, if I recall. I don't have any precedent to expect a period of 1 to be the same as period 0 (is there some chip out there that does this?). Not sure why it would wrap, either, for the same reason.
I brought that up because MAME's emulator states period 0 behaves like period 1 for the noise and tone counters in the comments. According to them, the chip uses up counters that reset when they're greater than or equal to the period value, which does in fact give that behaviour, and has apparently been verified by register writes taking effect immediately instead of on the next period, prompting the third question. I'm sceptical that it would have been economical to implement the chip that way, and I don't have anything but this one file to back up this statement, so I'm taking it with a grain of salt.

Also, I have multiple VGM rips that actually use period zero, at least for (again) the noise channel, and seem to expect that it generates some sound. The fact that the pitch they seem to be expecting - and which even the one VGM player supplies - varies between different rips is what prompted the question. Some sound the same with 0 = 1, some with wrapping. I must be missing something, but I look at the write log, I see a zero, and I hear either a really deep sound or a really high one. I can't get them all to sound right with the same code. It's driving me up the wall.
rainwarrior wrote:Asking "what happens if you --- while it's playing" is a pretty vague question though, there's more or less infinite permuations of things you could ask about this (does phase of envelope matter x number of possible phase steps, does phase of period matter x same, is there some other internal clock phase, etc. all of this x writing every bit of every control register) so all I can say at that point is...
That's why I was hoping to find a decap or something. There's a bunch of ways you could implement the envelope logic, and most of them will do different things if you start messing with parameters at different points. I doubt I could test every case even with hardware in front of me.
rainwarrior wrote:If you've got a hotswap ROM test ready let me know and I can record it.
Do I have to do anything special for a hotswap? Will a simple NROM that loads itself into RAM and spams sprite DMA until a button is pressed do the trick? Is there any way I can test it in an emulator?
User avatar
TmEE
Posts: 960
Joined: Wed Feb 13, 2008 9:10 am
Location: Norway (50 and 60Hz compatible :P)
Contact:

Re: Stupid 5B questions

Post by TmEE »

rainwarrior wrote:Period 0 just halts the oscillator, if I recall. I don't have any precedent to expect a period of 1 to be the same as period 0 (is there some chip out there that does this?). Not sure why it would wrap, either, for the same reason.
On the TI PSG 0 produces lowest possible freq and 1 produces highest possible, and on SEGA VDP 0 is special cased to produce same output as 1. Those are not quite AY though lol.

Maximum attenuation on a channel does produce silence on a real AY (and the TI and VDP PSG). I haven't noticed any leakage effects.
User avatar
rainwarrior
Posts: 8734
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: Stupid 5B questions

Post by rainwarrior »

Rahsennor wrote:
rainwarrior wrote:Period 0 just halts the oscillator, if I recall. I don't have any precedent to expect a period of 1 to be the same as period 0 (is there some chip out there that does this?). Not sure why it would wrap, either, for the same reason.
I brought that up because MAME's emulator states period 0 behaves like period 1 for the noise and tone counters in the comments. According to them, the chip uses up counters that reset when they're greater than or equal to the period value, which does in fact give that behaviour, and has apparently been verified by register writes taking effect immediately instead of on the next period, prompting the third question. I'm sceptical that it would have been economical to implement the chip that way, and I don't have anything but this one file to back up this statement, so I'm taking it with a grain of salt.

Also, I have multiple VGM rips that actually use period zero, at least for (again) the noise channel, and seem to expect that it generates some sound. The fact that the pitch they seem to be expecting - and which even the one VGM player supplies - varies between different rips is what prompted the question. Some sound the same with 0 = 1, some with wrapping. I must be missing something, but I look at the write log, I see a zero, and I hear either a really deep sound or a really high one. I can't get them all to sound right with the same code. It's driving me up the wall.
Ah, that's interesting. I guess I could see that happening.

The old YM2149 emulator in NSFPlay appears to treat both period 0 and 1 as an "always on" silence. I couldn't say whether this is correct. I did some verification tests a while back, and it passed all of those I could think of at the time, but it wasn't a thorough effort and I plan to completely rewrite the emulation of this chip n the next version.
TmEE wrote:On the TI PSG 0 produces lowest possible freq and 1 produces highest possible, and on SEGA VDP 0 is special cased to produce same output as 1. Those are not quite AY though lol.
Also interesting.
Rahsennor wrote:Do I have to do anything special for a hotswap? Will a simple NROM that loads itself into RAM and spams sprite DMA until a button is pressed do the trick? Is there any way I can test it in an emulator?
If you want to test it in an emulator, make something that is a valid 5B ROM. (Only reason to use NROM for this is if it's a mapper your flash/dev cart doesn't support.)

Generally with hotswaps you have to use $2001 polling for timing. Polling in a a short loop tends to miss frames, so putting an extra wait in that loop can help.

For the swap wait, I generally just made buzzing noises with $4011 a few seconds apart to give myself time to swap. The buzz helps verify it's still running after the swap. I'm not sure if doing OAM DMA during the swap helps or not, but it's not a strict requirement or anything (I did many hotswap tests before hearing about the idea); it's also a convenient way to put a delay in your $2001 polling loop. In general I wouldn't do a "wait for input" thing, just because I like to compare to NSFs, but it's a valid way to synchronize too. I do recommend performing the whole test in a loop over and over again, so in case you swap late you can just wait until it comes around again.

Some old tests you might use as an example: http://rainwarrior.ca/projects/nes/swap_tests.zip
Rahsennor
Posts: 479
Joined: Thu Aug 20, 2015 3:09 am

Re: Stupid 5B questions

Post by Rahsennor »

TmEE wrote:On the TI PSG 0 produces lowest possible freq and 1 produces highest possible, and on SEGA VDP 0 is special cased to produce same output as 1. Those are not quite AY though lol.
I knew I'd implemented both behaviours in an emu recently! Memory like a sieve, I have.
TmEE wrote:Maximum attenuation on a channel does produce silence on a real AY (and the TI and VDP PSG). I haven't noticed any leakage effects.
Good to know, thanks. :beer:
rainwarrior wrote:The old YM2149 emulator in NSFPlay appears to treat both period 0 and 1 as an "always on" silence.
That sounds suspiciously like a PCM-friendly ultrasonic suppression hack. I have seen that exact behaviour in emulators for the TI PSG, which doesn't have an always-on silence like the AY. (I have rips from two Tandy 1000 games that do PCM this way, and I'm sure there are many more.)
rainwarrior wrote:If you want to test it in an emulator, make something that is a valid 5B ROM. (Only reason to use NROM for this is if it's a mapper your flash/dev cart doesn't support.)
Derp. It somehow didn't occur to me you can just use a Powerpack or something with actual FME7 support for this.
rainwarrior wrote:Generally with hotswaps you have to use $2001 polling for timing. Polling in a a short loop tends to miss frames, so putting an extra wait in that loop can help.
I was just gonna cycle-time everything. That'll work, right?
rainwarrior wrote:For the swap wait, I generally just made buzzing noises with $4011 a few seconds apart to give myself time to swap. The buzz helps verify it's still running after the swap. I'm not sure if doing OAM DMA during the swap helps or not, but it's not a strict requirement or anything (I did many hotswap tests before hearing about the idea); it's also a convenient way to put a delay in your $2001 polling loop. In general I wouldn't do a "wait for input" thing, just because I like to compare to NSFs, but it's a valid way to synchronize too. I do recommend performing the whole test in a loop over and over again, so in case you swap late you can just wait until it comes around again.

Some old tests you might use as an example: http://rainwarrior.ca/projects/nes/swap_tests.zip
Okay, I'll give it a shot. Might be a while before I can come up with anything, though, so don't hold your breath. Thanks for the help!

EDIT: also, I just realized that you can't modify the envelope shape while it's playing... writing register D resets the envelope! :roll: But that's another behaviour that isn't actually described in the official docs, albeit one all the emulators I've looked at agree on.
User avatar
rainwarrior
Posts: 8734
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: Stupid 5B questions

Post by rainwarrior »

Rahsennor wrote:That sounds suspiciously like a PCM-friendly ultrasonic suppression hack. I have seen that exact behaviour in emulators for the TI PSG, which doesn't have an always-on silence like the AY. (I have rips from two Tandy 1000 games that do PCM this way, and I'm sure there are many more.)
Well, three candidate behaviours of halt (stay in current state), silence (flat 0 or full volume), and high frequency (alternating between both) are distinguishable even without being able to record high frequency sounds (the latter comes out as a "half" volume signal), so whichever the case this is easy to sort out with testing.

I hadn't thought about it being a too high frequency so my (weak) memory of 0 being "silent" should be correct by default if it is, since all three cases are technically silent. ;)
Rahsennor wrote:
rainwarrior wrote:If you want to test it in an emulator, make something that is a valid 5B ROM. (Only reason to use NROM for this is if it's a mapper your flash/dev cart doesn't support.)
Derp. It somehow didn't occur to me you can just use a Powerpack or something with actual FME7 support for this.
Well, I had to use NROM for VRC7 tests, as I recall. Not 5B though.

Rahsennor wrote:
rainwarrior wrote:Generally with hotswaps you have to use $2001 polling for timing. Polling in a a short loop tends to miss frames, so putting an extra wait in that loop can help.
I was just gonna cycle-time everything. That'll work, right?
That's an even better way to do it, since it's much more stable, no skipped frames. (Actually I should do this in my own tests, even a fixed "~16mz" delay with varying amounts of code run in between is still probably more desirable than a "vsync with chance of skip".)
Rahsennor wrote:EDIT: also, I just realized that you can't modify the envelope shape while it's playing... writing register D resets the envelope! :roll: But that's another behaviour that isn't actually described in the official docs, albeit one all the emulators I've looked at agree on.
You can change its pitch, but yes it necessarily has to have a phase reset mechanism because most of the envelope modes are 1-shot.
User avatar
rainwarrior
Posts: 8734
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: Stupid 5B questions

Post by rainwarrior »

Rahsennor wrote:Is volume zero audible? (I assume it isn't, but logarithmic scales never actually reach zero.)
What happens when you set the period registers to zero? (Is it the same as 1, does it wrap, or does it do something else entirely?)
What happens when you modify the period registers? (Does it affect the next period or the current one, I.E. does the chip count down or up?)
What happens when you modify the envelope shape while it's playing? (Probably the least-understood part of the chip, I'd be surprised if anyone actually knows the answer.)
So just in case anyone comes on this thread and wonders what the answers were, eventually tests were done in this thread, where more or less the same line of questions came up again.

A quick summary though:

Volume 0 is silent.

Period 0 is remapped to period 1 for all 3 period types (tone, noise, envelope).

Count up is the correct behaviour.

The envelope's period is reset when you write $0D.
Pokun
Posts: 2681
Joined: Tue May 28, 2013 5:49 am
Location: Hokkaido, Japan

Re: Stupid 5B questions

Post by Pokun »

I have some stupid 5B questions I could not find answers for in the wiki or these threads.

1)
The Sunsoft 5B ties the /SEL pin low so that the internal divider is used and the input clock is halved. Does this mean that the clock is half of the CPU clock (NTSC: 1.789773 MHz, PAL: 1.662607 MHz), in other words 0.8948865 MHz and 0.8313035 MHz for NTSC and PAL respectively? So the formula to calculate the period value for a given frequency for an NTSC system is: "Period = 894886.5 / (32 * Frequency)" and not "Period = 1789773 / (32 * Frequency)" correct?

I also read somewhere that the NTSC clock is 1.7897725 MHz or even other values (might not affect the final period values though).


2)
Is it verified that the YM2149F SSG's smoother envelope ramping is because the internal divider is used? I've read about the different envelope levels in the SSG and AY before (here, there are some other interesting info here too like the unused bits that can store values) but there it didn't say that it only applies when using the divider, confusing me.
I know that some MSX computers that uses an SSG instead of an AY for its PSG uses the divider but also uses a faster clock (3.579545 MHz) so to maintain the MSX standard of 1.7897725 MHz for the PSG. I guess these systems benefits from the smoother envelope while still running at the proper speed for the PSG?


3)
What is the difference between YM2149 and YM2149F? I think I read somewhere that the 5B is an YM2149F but not an YM2149.
User avatar
rainwarrior
Posts: 8734
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: Stupid 5B questions

Post by rainwarrior »

I'll respond in the new thread. I had only posted here for reference purposes to lead people there instead. The questions you asked are more relevant to the new thread too, I think, which is more generally about AY/YM.
Post Reply