Experiments in 1-Bit Sound on the BBC Micro and Acorn Electron

new graphics/music demos - bitshifters, 0xc0de, The Master + others
Post Reply
User avatar
Negative Charge
Posts: 93
Joined: Sat Jan 16, 2021 1:35 pm
Contact:

Experiments in 1-Bit Sound on the BBC Micro and Acorn Electron

Post by Negative Charge »

I’ve been experimenting with porting the 6502 SquatM 1-Bit Beeper Engine from the Atari 800/XL to the Electron.

In its early stages, and requires a Turbo Board (Slogger or equivalent) enabled for it to run at the required speed at the moment…. but it does work. Take a look here:

https://m.youtube.com/watch?v=5NdfpzJMO ... e=youtu.be

If you’re interested in the source, or have suggestions on how to reduce the cycle count (it’s very processor intensive!), take a look here: https://github.com/NegativeCharge/Acorn ... atM-Player
User avatar
Negative Charge
Posts: 93
Joined: Sat Jan 16, 2021 1:35 pm
Contact:

Re: Experiments in 1-Bit Sound on the BBC Micro and Acorn Electron

Post by Negative Charge »

If anyone’s interested, I’ve uploaded a version of the SquatM 1-Bit Beeper Engine for the BBC Micro here:

https://github.com/NegativeCharge/BBC-M ... atM-Player

Any help improving the performance of the CONSUL routine (named after the original Atari register) would be greatly appreciated. Alternating volumes really is the bottleneck in this engine.
User avatar
Negative Charge
Posts: 93
Joined: Sat Jan 16, 2021 1:35 pm
Contact:

Re: Experiments in 1-Bit Sound on the BBC Micro and Acorn Electron

Post by Negative Charge »

Here’s an example on the Acorn Electron with a Slogger Turbo Board enabled on the emulator.

It includes multi-channel tones, drums and sample playback using the ULA to create a toggle speaker.

Click on the image to watch:

Image
User avatar
kieranhj
Posts: 1103
Joined: Sat Sep 19, 2015 11:11 pm
Location: Farnham, Surrey, UK
Contact:

Re: Experiments in 1-Bit Sound on the BBC Micro and Acorn Electron

Post by kieranhj »

Negative Charge wrote: Mon Nov 14, 2022 7:52 pm If anyone’s interested, I’ve uploaded a version of the SquatM 1-Bit Beeper Engine for the BBC Micro here:

https://github.com/NegativeCharge/BBC-M ... atM-Player

Any help improving the performance of the CONSUL routine (named after the original Atari register) would be greatly appreciated. Alternating volumes really is the bottleneck in this engine.
This is all fantastic work - I love how un-Beeb and un-Electron it all sounds. =D>

For optimising the Beeb CONSUL routine:

Code: Select all

.CONSOL                  
    lsr     a                  ;2                     
    lsr     a                  ;2 
    lsr     a                  ;2
    lsr     a                  ;2 Only 4-bit volumes supported on tone channels 0, 1 and 2
    ora     #%10010000         ;2 bit-7 (latch/data), bits-6/5 (channel - 0), bit 4 (type - latch volume)
    
    sta     SYSVIA_ORAS        ;4 Write reg/data to SN76489

    lda     #%00000000         ;2
    sta     SYSVIA_REGB        ;4

    ; Sound write held low for 8us
    ; Seems to work at 6us, not 5us on an issue 3 beeb
    nop                        ;2
    nop                        ;2
    nop                        ;2
    nop                        ;2

    lda     #%00001000         ;2
    sta     SYSVIA_REGB        ;4

    rts                        ;6
My usual suggestions would be (a) inline the routine via MACRO (saves 12c removing JSR/RTS) (b) replace the 4x lsr a and ora with a lookup table (tax:lda table,x) would save another 4c but looks like X is used in the outer loop, which is annoying (c) can you shave off a NOP or replace this with useful work from the outer loop?
Bitshifters Collective | Retro Code & Demos for BBC Micro & Acorn computers | https://bitshifters.github.io/
User avatar
Negative Charge
Posts: 93
Joined: Sat Jan 16, 2021 1:35 pm
Contact:

Re: Experiments in 1-Bit Sound on the BBC Micro and Acorn Electron

Post by Negative Charge »

Thanks Kieran. Very useful advice! I thought about in-lining the sound output code as this is clearly wasting 6 cycles for the JSR and another 6 for the RTS. This works in one location, but in the other I start running into the issue of branch distance being greater than 127 (I think by 5). I can certainly use a macro for the SN76489 write though as I duplicate that code.

I've managed to actually drop the 4 LSR A's, as they were only necessary as the outer loop was setting max volume to &FF for the Atari rather than &0F needed for the Beeb.

I've also managed to get some speed up simply by not outputting anything to screen and dropping a few PHA/PLA instances that were unnecessary. It's closer to the original playback speed now, but not quite.

Thanks!
User avatar
Arcadian
Site Admin
Posts: 4223
Joined: Fri Nov 24, 2000 12:16 pm
Contact:

Re: Experiments in 1-Bit Sound on the BBC Micro and Acorn Electron

Post by Arcadian »

The Electron demos are out of this world, so impressed!

Please keep on doing what you're doing! :)
Please subscribe to the ABug YouTube channel!
User avatar
MartinB
Posts: 5635
Joined: Mon Mar 31, 2008 10:04 pm
Location: Obscurity
Contact:

Re: Experiments in 1-Bit Sound on the BBC Micro and Acorn Electron

Post by MartinB »

That Elk demo is just every shade of awesome! =D> 8)
User avatar
Negative Charge
Posts: 93
Joined: Sat Jan 16, 2021 1:35 pm
Contact:

Re: Experiments in 1-Bit Sound on the BBC Micro and Acorn Electron

Post by Negative Charge »

Arcadian wrote: Tue Nov 15, 2022 3:24 pm The Electron demos are out of this world, so impressed!

Please keep on doing what you're doing! :)
Thanks :) I'm enjoying getting this working. I've always thought the Electron was capable of more in terms of audio, but it's only really the appearance of Shiru's 6502 port of a 1-Bit beeper engine to the Atari that made me look at this area again. I'd love to port more engines, but most are Z80-based, and my Z80 is even worse than my 6502 :D

I'm hoping I can get the Electron version working at least to a level where the output is acceptable without requiring a turbo board, but instruction cycle optimisation isn't my strong point - I'm hoping the collective knowledge of the Stardot folk will be able to assist in that respect.
User avatar
Negative Charge
Posts: 93
Joined: Sat Jan 16, 2021 1:35 pm
Contact:

Re: Experiments in 1-Bit Sound on the BBC Micro and Acorn Electron

Post by Negative Charge »

MartinB wrote: Tue Nov 15, 2022 4:16 pm That Elk demo is just every shade of awesome! =D> 8)
Thank you. I was pretty impressed the first time I got this working as you can imagine.
User avatar
tricky
Posts: 7698
Joined: Tue Jun 21, 2011 9:25 am
Contact:

Re: Experiments in 1-Bit Sound on the BBC Micro and Acorn Electron

Post by tricky »

You can use PHP, PLP for A7 cycle delay in two bytes saving a byte at the cost of a cycle or maybe two bytes depending on cycle stretching - I don't know the rules.
User avatar
Negative Charge
Posts: 93
Joined: Sat Jan 16, 2021 1:35 pm
Contact:

Re: Experiments in 1-Bit Sound on the BBC Micro and Acorn Electron

Post by Negative Charge »

tricky wrote: Tue Nov 15, 2022 11:01 pm You can use PHP, PLP for A7 cycle delay in two bytes saving a byte at the cost of a cycle or maybe two bytes depending on cycle stretching - I don't know the rules.
Thanks Tricky! The general rule is I’m trying to save as many cycles as possible in the sound loop, while balancing the instruction cycle count between branches taken/not taken. I’m not too worried if I waste bytes through lookup tables etc.

The biggest reduction so far has been to inline subroutines via macros, as suggested by Kieran. JSR/RTS wastes 12 cycles and JSR/JMP 9, so it’s a pretty good reduction.

The only issue I’ve had is that the main sound loop is now over 127 bytes long and branching requires trampolines to jump back to the loop start. That wastes a minimum of 3 cycles (often 6), but is better than the 12 I was wasting through subroutines.

There may be a possibility to replace the SN76489 output code with something with a smaller cycle count, such as the code from Exile… going to investigate that next.
User avatar
tricky
Posts: 7698
Joined: Tue Jun 21, 2011 9:25 am
Contact:

Re: Experiments in 1-Bit Sound on the BBC Micro and Acorn Electron

Post by tricky »

You said that you needed 5 bytes to inline one of the uses and with the 4 you saved removing the nops, the extra byte daven would allow you to inline and save more than the extra cycle.
It may even be that swapping and removing an extra nop saves another cycle if it still works.
User avatar
Negative Charge
Posts: 93
Joined: Sat Jan 16, 2021 1:35 pm
Contact:

Re: Experiments in 1-Bit Sound on the BBC Micro and Acorn Electron

Post by Negative Charge »

Thanks Tricky. Yes, I see what you mean. Removing one of the nops still allows playback, so that’s only 6 cycles now and saves a byte. I’ll see if I can remove at least one of the two trampolines where I’ve inlined the sound_write_slow code.
Post Reply

Return to “new projects and releases: demoscene”