stevesims / agon-vdp

Official AGON QUARK Firmware: ESP32 VDP
MIT License
0 stars 0 forks source link

Create some examples #11

Open stevesims opened 1 year ago

stevesims commented 1 year ago

We need some examples to demonstrate these advanced audio features. Ideally they should be in BBC BASIC, as that code is most approachable for newcomers.

Sample playback examples will take some work, especially with samples of a reasonable size. The sample rate of 16khz means that for 8-bit samples we're using 16kb per second, so a 10s sample will take 160kb, which obviously can't fit inside BASICs 64kb address space. Preliminary example code read a file using a simple loop like so:

REM VDU commands to set up sample transfer to VDP
infill = OPENIN "sample.raw"
REPEAT
  VDU BGET#infile
UNTIL EOF#infile

Unfortunately this takes about 90s to execute. That sucks. Just reading the file without the VDU call to send to the VDP takes 70s. A plain REPEAT loop counting to 160,000 takes 30s... In principle as there is 1mbit of bandwidth between the z80 and the VDP it should be possible to transfer a 160kb sample in 1.5s. Loading a 160kb file in from an SD card seems to take about 2s, making for a total time of about 4s...

Ideally one would load the entire sample into memory and then directly transfer the whole thing across. That can't be done directly from BASIC, in large part because it's natively restricted to 64kb, and there's no facility available there to directly load part of a file into memory. MOS appears to offer some calls that may help to load parts of the file (like ffs_open and ffs_read via RST #08) and RST #18 allows chunks of data to be sent to the VDP rather than a byte at a time. In principle a few relatively simple assembly routines could be written as part of a BASIC program, but that will need some more research.

Another item of note here that may be useful is is the agon512k library which allows for larger areas of RAM be used from BASIC.