YM2149 "distortion" – and a lesson learnt

154 views
Skip to first unread message

Martin Giese

unread,
Jul 10, 2025, 8:25:55 AMJul 10
to RC2014-Z80
Hi!

Last week, I soldered together my own take on the YM2149 sound module, heavily inspired by Ed Brindley’s module.  And just got another confirmation of the wisdom that one should never ever add any connection without understanding what it does.  I’m posting this here in case anybody else sees the same phenomenon and browses the net in search of a solution.

While everything seemed to be working just fine, I noticed a strange kind of very unmusical distortion in some of the base and percussion parts during playback in several of the PT3 tunes that come with RomWBW.

I first thought it might be due to signal levels being more than my cheap PC speakers like.  But attenuation didn’t help.  Then I thought it might be the center channel loading each other ones, but removing the connection to that didn’t help.

Anyway, after a few days of discontent I noticed in some experiments from BASIC that the notes came out lower than what I was calculating.  I remembered the mention of the YM2149’s built-in clock divider and started wondering how that is activated.

Turns out I had grounded the SEL pin of the YM2149, "following" (as I thought) Ed’s schematic.  (Without reading the documentation about the particular jumper involved) Grounding it activates the clock divider, so I was actually running it an octave low.  For much of the music, this doesn’t really matter, but I think for some of the percussion and bass effects, the (unchanged) speed of register updates in the playback software starts interfering with the frequency of the signals the YM2149 produces.

Removed one wire, and it sounds a lot better!

TLDR: if your YM2149 sounds kind of distorted while playing back pt3 files although it sounds OK when playing single notes: check the SEL signal!

Martin



Colin Piggot

unread,
Jul 16, 2025, 4:37:44 AMJul 16
to RC2014-Z80
A lot of distortion can occur due to the wrong frequency going to the YM2149 / AY-3-891x soundchips. For example when playing ZX Spectrum chiptunes which are expecting the soundchip to have a clock frequency of 1.7734MHz to match the exact clock used by the AY in the 128K Spectrum models.

Back when I built up one of Ed's sound cards and started playing tunes I noticed a lot of problems when just dividing the system clock into something that the AY can handle (1.5 - 2MHz), depending on the frequency tones will either be higher or lower pitched, envelope effects will sound wrong or silent.

So back in September 2021 I designed and released a clock module to feed the soundchip the exact 1.7734MHz signal - "ZX True Tone", or ZXTT for short. Here's a video showing the difference between even a 1.75MHz clock and 1.7734MHz (a ~23KHz difference) -> https://www.youtube.com/watch?v=kg0RLhcfcdA

More info,  videos, community links, on the ZXTT is on my website at https://2014.samcoupe.com

Colin.

Martin Giese

unread,
Jul 16, 2025, 5:51:13 AMJul 16
to RC2014-Z80
Hi Colin!

That’s very interesting, the difference is quite obvious in your video.

But I wonder why… with a faster/slower clock on the AY, both the tones will have a different pitch and the envelopes be slower or faster.  I wouldn’t expect any interference there, everything should be still equally faster or slower.  One quarter of the RC2014 CPU clock is 1.8432 MHz.  That means about 4% too fast playback, and 67 cents too high pitch.  But still exactly the same number of tone periods per envelope step, so supposedly no changed interaction between those.

On the other hand, if the chip tune relies on synchronising the CPU clock, i.e., the timing of AY register writes, with the speed of envelopes and the period of notes, then that might make a significant difference.  I have no idea if that is/was being done.  But if so, then it would really require getting not only the AY clock right, but in particular the ratio between that and the CPU clock.  As well as the playback software getting the timing just right.

Martin

Martin Giese

unread,
Jul 21, 2025, 5:27:14 AMJul 21
to RC2014-Z80
After some more thought, I think I understand the issue now.

The misalignment is not between the envelopes (as set by the sound chip registers) and the pitch (as set by other registers).

But it’s not with the CPU clock either like I was thinking.  The registers are updated at a rate of 50Hz (usually) and this is produced either by some timer circuit or by introducing an appropriate delay in the software.  In the latter case, this delay would be tuned to give exactly 50 updates per second, for whatever CPU frequency is used.

So then, indeed, if the 50Hz rate is kept, then the 4% speed difference in envelope speed and pitch can lead to some undesirable effects.

Martin

Martin Giese

unread,
Sep 17, 2025, 8:52:06 AM (7 days ago) Sep 17
to RC2014-Z80
I’ve decided to go for the “official” 1.7734MHz clock.  I bought some 17.734MHz crystals and built a Pierce oscillator with a 74AHCU04, i.e. an unbuffered CMOS inverter.  I couldn’t get the more period-correct 4000 series CMOS parts to run that fast from 5V.

As soon as I get near my soldering iron again, the 17.734MHz will get divided by 10 using a 74LS90 (*) wired “backwards” (i.e. divide first by 5 and then by 2 to get 50% duty cycle) and then back to the AHCU part to clean up the signal that comes out of the LS part.

Looking forward to listening to pitch perfect chip tunes :-D

The 50Hz interrupt source is still on the TODO list, but I’m thinking that a program like TUNE.COM, that knows the clock frequency, and that can be sure that nothing outside of its control is happening on the computer, ought to get close enough to the exact 50Hz.

Martin

(*) where did I get the 74LS90 you ask?  Well, of course by ordering some 74HC90 from China.  Sigh.
Reply all
Reply to author
Forward
0 new messages