agon-bbc-basic
agon-bbc-basic copied to clipboard
Implement the ENVELOPE command for enhancing SOUND
BBC Basic provides the ENVELOPE command to compliment SOUND. Looks like there is a pull request in VDP to provide enhanced sound functionality, so perhaps it can be utilized for this request. Not sure the same syntax as BBC one can be provided, but it would make it easier to define the parameters compared to the long-winded VDU statements described in the pull request. Note up to 4 ENVELOPEs can be defined in BBC BASIC. As a site note on SOUND: BBC Basic uses channel 0 for noise and 1-3 for tunes where as Agon BASIC uses channels 0-2 for tunes. The volume parameter can be used for ENVELOPE numbers (1-4)
I've raised a new (alternate) PR on breakintoprogram/agon-vdp#76 which includes explicit commands for setting volume and frequency levels on individual channels. There are also commands to allow channel 0 to be (re-)assigned to be a noise channel, and to enable channel 3.
The facilities there at the time of writing would allow the ENVELOPE command to be implemented in full, if the envelope is driven by the BASIC implementation (i.e. from the z80).
There is support in there for applying a conventional/simple ADSR volume envelope to a channel. That however is not compatible with the style of volume envelope the ENVELOPE command describes, since Acorn's version implements a not-entirely-conventional ability for the volume level to gradually change during the "sustain" phase of a note. The code is designed to allow support for other envelope types to be added, so it could be extended to support a volume envelope in the Acorn mould.
The PR also includes a command to set a frequency envelope, but as of right now that's not yet implemented. My plan is to support an envelope type that should provide the style of frequency adjustment the ENVELOPE command specifies.
It should be noted that these envelopes are applied to a channel as a whole, like a synthesiser, rather than applied to the playback of an individual note.
Additionally the PR provides facilities for indefinite note duration, and getting the status of an audio channel. That should allow for the BASIC interpreter to fully implement the SOUND command.
(For added fun, the PR supports channel enable/disable commands - you can turn on up to 32 channels - the current BASIC SOUND command implementation is perfectly happy with playing sounds on channel number 31. If support gets added for the &HSFC version of the channel parameter though that would inevitably restrict the command to accessing a maximum 15 channels.)
FYI all of this functionality is now present and merged into the Agon Console8 VDP firmware, complete with frequency envelope support of a type that can fully emulate Acorn's stepped frequency envelopes. NB whilst this firmware is being developed for the Console8, it is fully compatible with other Agon Light machines.
The volume envelope style that's supported doesn't quite match Acorn's enhanced ADSR envelopes, so at this time it's not quite possible to fully implement the ENVELOPE command. As mentioned before, it would be possible to implement such a volume envelope by driving volume changes from the z80 side within the BASIC implementation.
There are also plans to add additional envelope types to the VDP, which would allow for envelopes to be defined that can emulate Acorn's enhanced ADSR style, but I can't give you a timescale on that - it's a lower priority than other areas of functionality at the moment.
Hi Steve, Thanks a lot for this work. I compiled the code from your PR (without frequency envelope) and all looks good. It will take some time to get used to the Volume Envelope as the parameters time-based but your additions will enhance the BBC BASIC sound system drastically. Keep up the good work.
Hey @leventp FYI I raised a PR yesterday after my initial sound enhancements got merged into the VDP that also does the frequency envelope stuff.
There are some further sound system enhancements merged into the Console8 VDP codebase, mostly around improving memory management and reducing the memory footprint. Those build on some major refactoring work that changes the overall structure of the VDP codebase, so it may be quite some time (if at all) before those improvements get merged in.
Coming very soon to the Console8 VDP codebase is a "buffered commands" enhancement. AgonConsole8/agon-vdp#30 This is rather handy when using sound samples, as the process of uploading a sample to the VDP takes a long time. The main issue with using samples from BBC BASIC is how long it takes to read samples from data files and send them over to the VDP - using buffered commands can't fix that, unfortunately, but it can mean that very large commands (like uploading a sound sample) can be split across multiple packets. Doing that at least means that in-between sending a data packet you can update the screen to show progress. 😀
(You can also potentially do lots more fun things with "buffered commands" - which will get even more fun with a few enhancements I'm planning on adding over the next few days.)
I will aim to raise a PR for the "buffered commands" enhancement against the main agon-vdp codebase too, however that relies on an extensive refactor of how the entire VDU command handling system works (AgonConsole8/agon-vdp#29), and in turn relies on the major restructuring work.