mirror of
https://github.com/usatiuk/cardboy.git
synced 2025-10-28 15:17:48 +01:00
bad sound in correct place
This commit is contained in:
@@ -306,6 +306,34 @@ public:
|
|||||||
gb_run_frame(&gb);
|
gb_run_frame(&gb);
|
||||||
GB_PERF_ONLY(perf.runUs = nowMicros() - runStartUs;)
|
GB_PERF_ONLY(perf.runUs = nowMicros() - runStartUs;)
|
||||||
|
|
||||||
|
{
|
||||||
|
uint32_t freqHz = 0;
|
||||||
|
uint8_t loud = 0;
|
||||||
|
if (apu.computeEffectiveTone(freqHz, loud)) {
|
||||||
|
// Basic smoothing: if freq didn't change much, keep it; otherwise snap quickly
|
||||||
|
const uint32_t prev = lastFreqHz;
|
||||||
|
if (prev != 0 && freqHz != 0) {
|
||||||
|
const uint32_t diff = (prev > freqHz) ? (prev - freqHz) : (freqHz - prev);
|
||||||
|
if (diff < 15) {
|
||||||
|
freqHz = prev; // minor jitter suppression
|
||||||
|
++stableFrames;
|
||||||
|
} else {
|
||||||
|
stableFrames = 0;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
stableFrames = 0;
|
||||||
|
}
|
||||||
|
lastFreqHz = freqHz;
|
||||||
|
lastLoud = loud;
|
||||||
|
const uint32_t durMs = 16;
|
||||||
|
playTone(freqHz, durMs, 0);
|
||||||
|
} else {
|
||||||
|
lastFreqHz = 0;
|
||||||
|
lastLoud = 0;
|
||||||
|
// Don't enqueue anything; queue naturally drains and buzzer stops
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
GB_PERF_ONLY(const uint64_t renderStartUs = nowMicros();)
|
GB_PERF_ONLY(const uint64_t renderStartUs = nowMicros();)
|
||||||
renderGameFrame();
|
renderGameFrame();
|
||||||
GB_PERF_ONLY(perf.renderUs = nowMicros() - renderStartUs;)
|
GB_PERF_ONLY(perf.renderUs = nowMicros() - renderStartUs;)
|
||||||
@@ -1926,35 +1954,6 @@ private:
|
|||||||
drawLineOriginal(*self, pixels, static_cast<int>(line));
|
drawLineOriginal(*self, pixels, static_cast<int>(line));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Simple per-scanline hook: at end of last line, decide tone for the frame.
|
|
||||||
if (line + 1 == LCD_HEIGHT) {
|
|
||||||
uint32_t freqHz = 0;
|
|
||||||
uint8_t loud = 0;
|
|
||||||
if (self->apu.computeEffectiveTone(freqHz, loud)) {
|
|
||||||
// Basic smoothing: if freq didn't change much, keep it; otherwise snap quickly
|
|
||||||
const uint32_t prev = self->lastFreqHz;
|
|
||||||
if (prev != 0 && freqHz != 0) {
|
|
||||||
const uint32_t diff = (prev > freqHz) ? (prev - freqHz) : (freqHz - prev);
|
|
||||||
if (diff < 15) {
|
|
||||||
freqHz = prev; // minor jitter suppression
|
|
||||||
++self->stableFrames;
|
|
||||||
} else {
|
|
||||||
self->stableFrames = 0;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
self->stableFrames = 0;
|
|
||||||
}
|
|
||||||
self->lastFreqHz = freqHz;
|
|
||||||
self->lastLoud = loud;
|
|
||||||
const uint32_t durMs = 17;
|
|
||||||
self->playTone(freqHz, durMs, 0);
|
|
||||||
} else {
|
|
||||||
self->lastFreqHz = 0;
|
|
||||||
self->lastLoud = 0;
|
|
||||||
// Don't enqueue anything; queue naturally drains and buzzer stops
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char* initErrorToString(enum gb_init_error_e err) {
|
static const char* initErrorToString(enum gb_init_error_e err) {
|
||||||
|
|||||||
Reference in New Issue
Block a user