Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AY UGen freqtotone method is incorrect. #348

Open
telephon opened this issue Jan 2, 2023 · 2 comments
Open

AY UGen freqtotone method is incorrect. #348

telephon opened this issue Jan 2, 2023 · 2 comments

Comments

@telephon
Copy link
Member

telephon commented Jan 2, 2023

Yes, it seems to be the freqtotone method of the AY ugen is not correct.

*freqtotone { |freq|
		// Approximate empirical...
		//^(109300 / (freq - 3.70727))
		^(110300 / (freq - 0.5))
	}

Here is a test:

Here is the datasheet: http://atariage.com/forums/index.php?app=core&module=attach&section=attach&attach_id=397711
On page 18ff. there is a formula that needs proper implementation.

```supercollider
// starting point for tests.

(
Ndef(\x, { 
	var mapping = { |x| (110300 / (x - 0.5)) };
	var freq = MouseX.kr(200, 700);
	var f = mapping.(freq);
	AY.ar(f, f, f) + Saw.ar(freq) * 0.1 
	
}).play;
)
@jamshark70
Copy link
Contributor

jamshark70 commented Nov 21, 2023

There is also perhaps some relationship to the sample rate. I used AY successfully at 44.1 kHz and it was by and large in tune with other synths. But just now (perhaps for the first time) I ran it at 48 kHz. It sounded a bit less than a minor third too low.

This is puzzling because 1/ if the AY sample/hold behavior works by counting samples, a higher sample rate would produce a higher pitch, but instead it's lower, and 2/ the ratio 48 / 44.1 in 12ET is just shy of a semitone and a half, not even close to 2.5 or 3 semitones.

Baffled...

PS The formula at this stackexchange thread is even worse -- 440 gets about a P4 difference at 48 kHz, and it varies with frequency.

a = {
	var freq = 440;
	var toneFactor = 2000000 / 16;
	var tonemap = { |freq| (toneFactor / freq).round };
	var tone = tonemap.(freq); // AY.freqtotone(freq).postln;
	[AY.ar(tone, tone, tone), LFTri.ar(freq)] * 0.1
}.play;

a.free;

@ahihi
Copy link

ahihi commented Mar 27, 2024

the emulator uses a default clock frequency of 1773400 rather than 2MHz. accordingly, i tried

(
a.free;
a = {
	var freq = 440;
	var toneFactor = 1773400 / 16;
	var tonemap = { |freq| (toneFactor / freq).floor };
	var tone = tonemap.(freq); // AY.freqtotone(freq).postln;
	[AY.ar(tone, tone, tone), LFTri.ar(freq)] * 0.1
}.play;
)

(in addition to the toneFactor, i also changed the round to floor)

at 44.1kHz, this sounds to me even closer than the original freqtotone, but i didnt measure yet. still not sure what is happening at 48kHz though..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants