|
Forum Index : Microcontroller and PC projects : blocks with the new BBC Sound Engine
| Author | Message | ||||
| homa Guru Joined: 05/11/2021 Location: GermanyPosts: 760 |
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: NetherlandsPosts: 6254 |
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: GermanyPosts: 760 |
Hi Vollhout, Yes, I’ve only tried it on the PC3. Thanks very much for your feedback. 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: GermanyPosts: 760 |
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: NetherlandsPosts: 6254 |
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: GermanyPosts: 760 |
' ============================================================ ' 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: GermanyPosts: 760 |
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 |
||||
| Volhout Guru Joined: 05/03/2018 Location: NetherlandsPosts: 6254 |
Hi Matthias, I tried the small program you used to test levels and bass pitch. As you indicated bass pitch 41 is really stuttering, 141 sounded nicest in my ears, 181 the least. But appart from that (to the ear) all volumes, balances between harmony/bass/melody sound very similar at all volume levels (up to -15-15-15 ... note: -15 is louder than -3 ...???). So I think my remark about the bass distortion was more related to the noise channel being used for bass, where I expected a square wave or sine wave. What has improved in 0.37 is that the music is played at more stable pace on a 2040. The original complaint was about bass distortion -and- notes not played at the moment they should appear in the score. And the latter is solved in 0.37. Much better. Tested on V70000rc8 - Game*Mite 2350 by commenting "mode 2" out, and using keyboard. - VGA 2040 (both Blocks 0.37 as well as the test program) Both systems use PWM audio. It is a pity that you did not use the Game*Mite version of blocks as a basis. It is different in that it supports the Game*Mite buttons for controls when it detects the platform is Game*Mite. But I can make these changes if you desire. Regards, Volhout Edited 2026-11-12 20:25 by Volhout PicomiteVGA PETSCII ROBOTS |
||||
| homa Guru Joined: 05/11/2021 Location: GermanyPosts: 760 |
Hi Volhout, thanks a lot for testing on both boards, that helps a lot! Good to hear that V0.37 fixes the timing on the 2040. I think two things came together here. The new firmware has a bigger BBC queue (16 notes instead of 8). It also has MM.INFO(BBC BUFFER), which tells the program how many slots are free. Up to V0.36 the engine had to track every queued note itself, with its own list of end times per channel. That bookkeeping probably cost noticeable time on the slower 2040. Now the firmware gives us that number directly, so the code is gone and the engine is leaner. About the bass: you’re right, it comes from the noise channel. That is a limit of the BBC engine. There is no sine wave, and the square channels don’t go low enough for the deep bass notes. So the low notes are only possible with periodic noise tuned by channel 1. Your ears match the numbers: 141 is the lower end of the range the game uses, 181 the upper end. One possible alternative is a square-wave bass, one octave higher. It would sound rounder but less like a real bass. I may try that as an extra bass style in a later version. About the Game*Mite version: could you send me your Game*Mite Blocks code? If I base the next version on it, the button support would be there from the start. My build script puts the sound engine into the game at a few fixed places, so I only need to adapt those to your file. Thanks again! Matthias |
||||
| The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2026 |