A late Christmas present : The return of the SOUND and ENVELOPE commands...

Should be sharing an ‘alpha’ of the new RISC OS DSP sound module based on shared sound soon ( as I haven’t requested a SWI range yet + I’ve got quite a bit of testing to do & don’t really know what this will run on…).

This module enables playing both samples and synthesised sounds from BASIC via SOUND and ENVELOPE commands as well as new custom SWIs / * commands

I plan to add a compatibility mode to (at least partially) support the SOUND / ENVELOPE commands BBC micro type SN76489 sound that is selectable via a * command/SWI. As by default the ENVELOPE command has a different set of parameters geared toward the new engine.

I will supply a selection of BASIC programs to demo the types of sound that this can make.

The src code needs tidying and I don’t have a proper package or make file yet (just an obey script). The alpha will be public as this module is free with (src code included). Although I did some POCs in asssembly code, I decided to write this in C (very flat and inlined however).

n.b. This post concerns the ‘wavebox-esque’ option in the RISC OS awards.

Hi Greg, TimPlayer has different functionality as I understand it is focused on playing tracker files. Although I have used it as a sample player in my games. So it is possible that RDSP will perform better. I’ll have to find a good way to do a performance measurement and would welcome feedback on this. At the moment I’m trying to measure RDSP’s impact on the system by running a separate program and measuring its time to complete (as shared sound runs in the background off an interrupt).

I have tried this on an ARMX6, Raspberry pi 2, RPCEmu and an Iyonix (although I had to load shared sound manually as it was not in the expected location).

Source code and examples are included.

There are 7 examples:BBC – BBC Micro style SOUND command usageDRUMS – Sample playback for bass drum, snare and hi-hat in a simple loop from BASIC.
waves – An illustration of different wave types and chords from the synthesiser.BANG – An ENVELOPE command to do an explosionXOR-PWM – An illustration of XOR inter-channel modulation and pulse-width-modulation via a SOUND and ENVELOPE command
3CHORDS – A modulated sample and delay effectSTAR-COMMAND – An illustration of a slow tune like modulation and delay command via the supplied *commands-———————————————-

Please note that this is Alpha quality. No SWIs are included just OS WORD 7, 8 and *commands.

Testing::

Ran the example programs and tested that AMPlayer would play concurently on RPCEmu, Raspberry pi 2, ARMX6 and Iyonix.

Release notes:
n.b. 1) *RMLOAD rdsp
from the bin directory
2) Then set directory in the examples directory
3) Run the BASIC example programs.

A low pass filter with Q.
+ Pulse width modulation
+ A 3 stage envelope in the style of the BBC Micro 3 stage envelope
that can modulate : PWM or Filter or Pitch or Amplitude.
+ A 4 stage ADSR envelope that is locked to amplitude but can also
modulate : PWM or filter or Pitch.
+ Channel modes including:
– Oscillator synchronised tuning
– XOR (ring modulation) between adjacent channels.
– Channel muting.
> Sample playback features
+ Play back PCM samples through the oscillator of the synthesiser at one of
364 frequencies.

Up to 256 envelope commands

Up to 256 loaded 16 bit 44 khz samples via WAV format support.

SOUND and ENVELOPE command integrationSOUND command has some limited legacy support by defaultSOUND 1,-15,208,100 plays a square wave at the A above middle C
on channel 1.
n.b. Eqivalent to SOUND 1,-15,137,100 on the BBC Micro.SOUND 0,-15,0,100 plays a pulse wave of the same frequency as the BBC Micro
and noise and modulatable noise is mapped similarly.
n.b. This actually plays back on channel 8.

T = Tone : Waveform mask or Envelope number or Sample number
n.b. a waveform of 0xff is disallowed in order to support
legacy OS Word 7 behaviour.
The following waveforms may be selected via a bitmask.RDSP will AND the resulting WAVs together
&01 to &1f : Pulse wave from ~1% to a square wave
&20 : Saw wave i.e. a ‘ramp’.
&40 : Triangle wave
&80 : Modulatable noise

RE: code review – No problems Steve. However, I would be grateful if you have time to try RDSP out please let me know what you ran it on and if it worked. The alpha hasn’t crashed RISC OS for me yet…. But I’m going to try some soak and fuzzed input values to see if it does….

It changes the system beep because it hooks OS Word 7 i.e. as used by the SOUND command.

I could make the SOUND command integration user selectable (i.e. allow it to be disabled). Or optionally exclude (or re-map) the system beep as a feature – as this uses SOUND channel 1 at a specific frequency.

This does mean that you could change the system beep to a custom sample if you wished via RDSP (with a bit of tweaking).

Thanks Rob.
Cybertron mission will require the *legacy switch (assuming it still calls OS Word 8) as by default the RDSPENVELOPE command has very different parameters e.g. cut off, resonance and multiple modulation options other than pitch.

However, I may accept a default behaviour of SOUND 1,1,100,100 i.e. a positive value for envelope. Just realised that this will not conflict with any of the current sound options that I’ve specified.

game loads on Pi3 but no sound and some of the keys don’t work the left & right a& Z work but just lay him down then he dies tried some of the other games and they work with sound. BTW the Pi3 is running the beta rom from two days ago with all the latest changes.
Edit
I forgot to set the working Dirctory so sound to a point only the last sound played by the examples. I was wrong about the keys the keys work i thought that the left and right to the right cursor keys of the keyboard but they are the shifed commer and full stop on the keyboard next to the m.

This will be quite small (as amplification is effectively just a multiply and a divide).

Specifically – a downward compressor with threshold, ratio and attack and release.
i.e. implemented as a simple (signal * compressor) >> 8 where compressor processes signal level and is reduced or increased based on threshold, attack and release.

I’ll have to find a good way to do a performance measurement and would welcome feedback on this

For profiling fast code like this (i.e. anything where the monotonic timer won’t be fast enough) I’d recommend either using a HAL timer (most timers will be 32 bits wide and 1MHz or faster) or using the performance counters built into the CPU (I think any ARMv5+ system is guaranteed to have performance counters, not sure about earlier systems. For most cases the cycle counter will be all you need, and unlike the HAL timers they can be configured to be directly accessible from user mode. However you would have to check the relevant manuals to make sure you’re using the right setup/access instructions for the CPU – on ARMv7+ this should all be standardised but for ARMv6 and below the required operations may differ by either architecture or CPU).

Whatever method you’re using, it may also make sense to disable interrupts while profiling the code, so that you’re not measuring the cost of someone else’s interrupt handler. And forcing the CPU speed to its slowest may also help with accuracy (e.g. HAL timers)