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

Calls to the YM Generate and Engine_Timer_Expired are out of sync #219

Open
Yazwh0 opened this issue Jan 27, 2024 · 2 comments
Open

Calls to the YM Generate and Engine_Timer_Expired are out of sync #219

Yazwh0 opened this issue Jan 27, 2024 · 2 comments

Comments

@Yazwh0
Copy link

Yazwh0 commented Jan 27, 2024

The call to engine_timer_expired is in update_clocks(), but as that is called with the number of samples before the stepped call to m_chip.generate, the results will probably not match hardware as apparently one timer is tied to Key Down.

		void update_clocks(int cycles) {
			m_busy_timer = std::max(0, m_busy_timer - (64 * cycles));
			for (int i = 0; i < 2; ++i) {
				if (m_timers[i] > 0) {
					m_timers[i] = std::max(0, m_timers[i] - (64 * cycles));
					if (m_timers[i] <= 0) {
						m_engine->engine_timer_expired(i);
					}
				}
			}	
		}
...
		void generate(int16_t* output, uint32_t numsamples) {
			int s = 0;
			int ls, rs;
			update_clocks(numsamples);
			for (uint32_t i = 0; i < numsamples; i++) {
				m_chip.generate(&opm_out);
				ls = opm_out.data[0];
				rs = opm_out.data[1];
				if (ls < -32768) ls = -32768;
				if (ls > 32767) ls = 32767;
				if (rs < -32768) rs = -32768;
				if (rs > 32767) rs = 32767;
				output[s++] = ls;
				output[s++] = rs;
			}
		}
@mooinglemur
Copy link
Contributor

Do you have a suggestion for how to change it?

@Yazwh0
Copy link
Author

Yazwh0 commented Feb 4, 2024

Best guess is call update_clock(1) in the loop within generate.

I don't know enough about the YM chip to really opine 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

2 participants