From 629b9b9c80a726118985eeafc6d66f9b40e9c661 Mon Sep 17 00:00:00 2001 From: Samuel Gomes <47574584+a740g@users.noreply.github.com> Date: Sat, 20 Aug 2022 00:11:06 +0530 Subject: [PATCH] Mimic QB45 behavior - Sound() frequency 20KHz or above produces silence --- internal/c/parts/audio/out/audio.cpp | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/internal/c/parts/audio/out/audio.cpp b/internal/c/parts/audio/out/audio.cpp index 6430d70b0..b10c77da8 100644 --- a/internal/c/parts/audio/out/audio.cpp +++ b/internal/c/parts/audio/out/audio.cpp @@ -692,9 +692,22 @@ static ma_uint8 *GenerateWaveform(double frequency, double length, double volume samplesi = 1; *soundwave_bytes = samplesi * SAMPLE_FRAME_SIZE(ma_int16, 2); - data = (ma_uint8 *)malloc(*soundwave_bytes); + + // Frequency equal to or above 20000 will produce silence + // This is per QuickBASIC 4.5 behavior + if (frequency < 20000) + { + data = (ma_uint8 *)malloc(*soundwave_bytes); + } + else + { + data = (ma_uint8 *)calloc(*soundwave_bytes, sizeof(ma_uint8)); + return data; + } + if (!data) return nullptr; + sp = (ma_int16 *)data; direction = 1; @@ -744,7 +757,7 @@ static ma_uint8 *GenerateWaveform(double frequency, double length, double volume if (waveend) *soundwave_bytes = waveend * SAMPLE_FRAME_SIZE(ma_int16, 2); - return (ma_uint8 *)data; + return data; } ///