Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 07:40 21 Oct 2026 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : blocks with the new BBC Sound Engine

Author Message
homa

Guru

Joined: 05/11/2021
Location: Germany
Posts: 715
Posted: 09:19pm 21 Sep 2026
Copy link to clipboard 
Print this post

Hello, community,

I was so impressed by the new BBC sound engine that I decided to create sounds for Geoff's game blocks.
The engine not only generates the melody but also uses various sound envelopes to make the playback more varied. I also tried to replicate the game’s tempo. It’s best to try it out for yourself. You can toggle the debug output on and off with the “s” key. The gameplay has been adjusted so that it now progresses in the old GB style.

Peter, I’m still hoping for a real fuel gauge with a numerical value. Unfortunately, you didn’t respond to my suggestion in the “PicoMite V6.03.02 Betas” thread. I think that would have simplified the implementation here.

Have fun! If you hear any incorrect output, the debug values will help me troubleshoot.

I’m keen to hear your views.

Matthias


Blocks_1.0_PC3_sound_v0.36.zip
 
Volhout

Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 6184
Posted: 07:07am 22 Sep 2026
Copy link to clipboard 
Print this post

Hi Matthias,

It runs on a 2040VGA. But the bass is very distorted. Thursday I can get to my PC3 and check if it is similar there. Tested on V60400rc0.

It is not CPU speed related (when I run 378MHz, it is the same as 252MHz).

Regards,

Volhout
Edited 2026-09-22 17:14 by Volhout
PicomiteVGA PETSCII ROBOTS
 
homa

Guru

Joined: 05/11/2021
Location: Germany
Posts: 715
Posted: 08:43pm 22 Sep 2026
Copy link to clipboard 
Print this post

Hi Vollhout,

Yes, I’ve only tried it on the PC3. Thanks very much for your feedback.
  Volhout said  Tested on V60400rc0
I ‘only’ used V60302b12!

I’ll have a go at testing it myself on an RP2040 this weekend. Perhaps there’s still something that can be done.

Matthias
Edited 2026-09-23 06:47 by homa
 
homa

Guru

Joined: 05/11/2021
Location: Germany
Posts: 715
Posted: 06:53pm 23 Sep 2026
Copy link to clipboard 
Print this post

Vollhout,
Could you help me narrow down the distortion a bit?

Does it happen only on the bass, or on the melody/comping too?
Does it happen even at low intensity (quiet passages, no "punch" kick on the bass), or mainly when the bass is loud/punchy?

One thing worth knowing: the VGA board's audio path isn't digital (I2S) like the HDMI board's — it goes through PWM and an analog RC filter, which clips and colors the sound quite differently. So this may well be a hardware/level issue specific to that board rather than a bug, and the answers above would help me figure out whether it's the bass amplitude/punch effect that needs toning down for that path.

Matthias
 
Volhout

Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 6184
Posted: 05:58am 24 Sep 2026
Copy link to clipboard 
Print this post

Hi Matthias,

The distortion happens in the following section (your debug info)

Free 18 16%
zone 0 int 0
120>120 BPM
P2 Bridge 5/8
Bass orig left
Comp harmony
punch 0 bld 0
fx 0/0 L274
d0 s0 m0.9

Since it is the first melody section that uses the Bass, I estimated it is caused by the bass. But would need some analyzer to see exactly what is going on.

Regards,

Volhout
PicomiteVGA PETSCII ROBOTS
 
homa

Guru

Joined: 05/11/2021
Location: Germany
Posts: 715
Posted: 07:51pm 12 Oct 2026
Copy link to clipboard 
Print this post


' ============================================================
' BBC LEVEL / DISTORTION TEST  (works on b6 or newer, no V7 needed)
' Purpose: find out whether the distortion heard in the bass
' section comes from the analog output stage (PWM, amp, speaker)
' or from the digital mix.
'
' Plays one held A-minor sound: noise bass (ch0, tuned by silent
' ch1) + melody (ch2) + harmony (ch3), with the same base levels
' as the game: bass -7, melody -5, harmony -6.
'
' Keys:
'   1 = bass on/off      2 = melody on/off      3 = harmony on/off
'   + = all louder (1 step)    - = all quieter (1 step)
'   v = PLAY VOLUME down 10    V = PLAY VOLUME up 10
'   b = bass tuner pitch: 141 -> 161 -> 181 -> 41 -> 141 ...
'       (game uses ~141..190 = about 120-250 Hz; 41 = 29 Hz is far
'       too low, only for comparison: it sounds like rattling clicks)
'   ESC = quit
' ============================================================
OPTION EXPLICIT
OPTION BASE 0

CONST BASS_AMP = -7
CONST MEL_AMP  = -5
CONST HARM_AMP = -6
CONST MEL_PITCH = 117   ' E5
CONST HARM_PITCH = 101  ' C5

DIM INTEGER on_bass, on_mel, on_harm
DIM INTEGER shift, vol, bass_tune
DIM STRING k$

on_bass = 1 : on_mel = 1 : on_harm = 1
shift = 0 : vol = 100
bass_tune = 161   ' game range is about 141..190 (note pitch + 140)

PLAY VOLUME vol, vol
Apply

DO
   k$ = INKEY$
   IF k$ <> "" THEN
       SELECT CASE k$
           CASE "1" : on_bass = 1 - on_bass : Apply
           CASE "2" : on_mel  = 1 - on_mel  : Apply
           CASE "3" : on_harm = 1 - on_harm : Apply
           CASE "+" : shift = shift - 1 : Apply     ' more negative = louder
           CASE "-" : shift = shift + 1 : Apply
           CASE "v" : vol = vol - 10 : IF vol < 0 THEN vol = 0
                      PLAY VOLUME vol, vol : Report
           CASE "b" : bass_tune = bass_tune + 20
                      IF bass_tune = 201 THEN bass_tune = 41
                      IF bass_tune = 61 THEN bass_tune = 141
                      Apply
           CASE "V" : vol = vol + 10 : IF vol > 100 THEN vol = 100
                      PLAY VOLUME vol, vol : Report
           CASE CHR$(27) : EXIT DO
       END SELECT
   ENDIF
   PAUSE 20
LOOP

PLAY BBC SOUND &H10, 0, 0, 0
PLAY BBC SOUND &H11, 0, 0, 0
PLAY BBC SOUND &H12, 0, 0, 0
PLAY BBC SOUND &H13, 0, 0, 0
PRINT "Done."
END

' Clamp an amplitude to -15..-1 (louder = more negative)
FUNCTION Lv(base AS INTEGER) AS INTEGER
   LOCAL INTEGER a
   a = base + shift
   IF a < -15 THEN a = -15
   IF a > -1 THEN a = -1
   Lv = a
END FUNCTION

SUB Apply
   ' flush all four channels, then restart the ones that are on
   PLAY BBC SOUND &H10, 0, 0, 0
   PLAY BBC SOUND &H11, 0, 0, 0
   PLAY BBC SOUND &H12, 0, 0, 0
   PLAY BBC SOUND &H13, 0, 0, 0
   IF on_bass THEN
       PLAY BBC SOUND 1, 0, bass_tune, 255      ' silent tuner for the noise
       PLAY BBC SOUND 0, Lv(BASS_AMP), 3, 255   ' noise rate taken from ch1
   ENDIF
   IF on_mel  THEN PLAY BBC SOUND 2, Lv(MEL_AMP), MEL_PITCH, 255
   IF on_harm THEN PLAY BBC SOUND 3, Lv(HARM_AMP), HARM_PITCH, 255
   Report
END SUB

SUB Report
   PRINT "bass=";on_bass;" mel=";on_mel;" harm=";on_harm;
   PRINT "  levels: ";Lv(BASS_AMP);" ";Lv(MEL_AMP);" ";Lv(HARM_AMP);
   PRINT "  PLAY VOLUME=";vol;"  bass tuner=";bass_tune
END SUB


Hi Volhout,

thanks for the detailed report, that debug line helps a lot. d0 s0 m0.9 means no dropouts and no slow PLAY calls, so I don’t think it’s timing. My current guess is the analog side, with the bass making it worse. On my PC3 board (I²S, digital) I can’t hear it, and a recording of my output shows the mix is clean and linear even with all three voices at maximum.

Why I suspect the bass: it uses the noise channel in periodic mode. That gives a very narrow pulse train (about 6 % duty), and the pulses are as high as a full square wave but much quieter in loudness. They also all point in the same direction. A weak output stage, coupling capacitor or small speaker can clip those peaks first, and only when all three voices play together. That fits your observation that it starts in the first section with the bass. It is a hypothesis, not proven.

So I wrote a small test program (bbc_pegel_test.bas) that plays one held A-minor sound with the same levels as the game. It runs on the same firmware as the game and doesn’t need the full game.

Keys:

1 / 2 / 3 – bass / melody / harmony on or off
+ / - – everything one step louder / quieter
v / V – PLAY VOLUME down / up by 10
b – switch the bass pitch (141 / 161 / 181 are the range the game uses; 41 is only for comparison and will sound like rattling clicks, ignore that one)
ESC – quit

What I’d love to know:

With all three on, is it distorted? Does it get clean when you press - two or three times?
Does it get clean with v (lower PLAY VOLUME, e.g. 50)? If yes, the analog stage is overloaded.
Bass only, then bass + melody, then bass + harmony: where does it start?
What are you listening on (headphones, speaker, amplifier board)? Does it happen on both?
If you can record the analog output (line-in or audio interface), send me a short WAV or MP3 of the bass-only and the all-three case. I can check whether the positive peaks are flattened.

If it turns out to be the output stage, I can lower the bass level or change the balance in the next version.

Thanks for testing!
Matthias
 
homa

Guru

Joined: 05/11/2021
Location: Germany
Posts: 715
Posted: 08:02pm 12 Oct 2026
Copy link to clipboard 
Print this post

Blocks Sound Engine V0.37

Main change: this version needs MMBasic firmware V7.00 or newer. Older firmware is no longer supported, so the code got leaner. The engine now uses the new MM.INFO(BBC BUFFER) to check the queue, so it no longer has to track every queued note itself. That made the engine about 60 lines shorter. On older firmware the game stops at once with “Needs firmware V7.00 or newer”.

The music itself (arrangement, tempo and intensity control, line effects, jingles) should sound exactly the same as in V0.36. If you hear a difference, please tell me.

If something sounds odd, please post the debug line (fx, d s m). d0 s0 and an m value below 1 ms mean the engine is running smoothly.

Have fun testing on the PC3 with the new firmware V7.0 and above!

Matthias

Blocks_1.0_PC3_sound_v0.37.zip
 
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2026