RISC OS Open
Safeguarding the past, present and future of RISC OS for everyone
ROOL
Home | News | Downloads | Bugs | Bounties | Forum | Documents | Photos | Contact us
Account
Forums → General →

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

Subscribe to A late Christmas present : The return of the SOUND and ENVELOPE commands... 39 posts, 9 voices

Posts per page:

Pages: 1 2

 
Dec 30, 2016 12:58am
Avatar Anthony Vaughan Bartram (2454) 426 posts

Still metaphorically wrapping this at the moment….

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 now have working : 8 channel sound/sample playback (via variable speeds) a (slightly resonant) low pass filter, a delay effect, a modulatable noise generator, PWM, square, triangle and saw-wave oscillators + envelopes to modulate the sound.

I’ve linked the code to the SOUND command and am testing/writing the ENVELOPE command integration. Going to add the XOR inter-channel modulation feature soon.

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.

 
Dec 30, 2016 5:06am
Avatar Bryan Hogan (339) 498 posts

This sounds fantastic Anthony. I’m impressed with how far you’ve progressed in the few weeks since your talk at ROUGOL at the end of November.

I was always frustrated that Acorn didn’t implement sound and envelope on RISC OS (Arthur) in a backwards compatible way with the Beeb. Finally, 30 years later, we will finally have it!

Excellent work :-)

 
Dec 30, 2016 3:54pm
Avatar David Feugey (2125) 2594 posts

I just say: yeah!

 
Dec 31, 2016 1:25am
Avatar Patrick M (2888) 87 posts

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.

Brilliant!
The new features sound exciting as well. Looking forward to playing with this. Great stuff, thank you.

 
Dec 31, 2016 8:58am
Avatar Rob Heaton (274) 488 posts

Nice work, I’m looking forward to this too!

 
Dec 31, 2016 5:14pm
Avatar Greg (2474) 130 posts

I too am interested, glad too see this finally coming to fruition. How does this compare ( processor time ) with the likes of TimPlayer. Is it more efficient ?

 
Jan 2, 2017 4:40pm
Avatar Anthony Vaughan Bartram (2454) 426 posts

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).

 
Jan 2, 2017 4:49pm
Avatar Anthony Vaughan Bartram (2454) 426 posts

Thanks for your interest and I’m pleased I’ve finally managed to get this working.
I’m still only a few years into RISC OS and I know that will probably show when someone looks at my code.

The alpha is available from:
http://www.amcog-games.co.uk/downloads/rdsp-alpha1.zip

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 usage
DRUMS – 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 explosion
XOR-PWM – An illustration of XOR inter-channel modulation and pulse-width-modulation via a SOUND and ENVELOPE command
3CHORDS – A modulated sample and delay effect
STAR-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.

Release status: Alpha
Version: 0.17

Features:

  • 8 channel 16 bit audio
    > Each channel features:
    + Synthesiser & Sample playback.
    > Synthesiser features:
    + 364 playable frequencies
    + 4 wavetypes that can be AND’ed together:
    – Pulse wave between 1% and 50% duty cycle i.e. up to a square wave
    – Saw wave
    – Triangle wave
    – Modulatable noise
  • 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 integration
    SOUND command has some limited legacy support by default
    SOUND 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.
 
Jan 2, 2017 5:56pm
Avatar Anthony Vaughan Bartram (2454) 426 posts

In actual fact the RDSP sound command has the following fields:

SOUND PFIC,TTVV,FRNN,DDDD
  • P – Pan (not in current alpha)
  • F = Flags : &10 – Synchronise, &20 – Mute, &40 – XOR with previous channel
  • I = Instrument : &00 – Waveform, &10 – Envelope, &20 – Sample
  • C = Channel : 1 to 8 (or the BBC Micro noise 0 channel implemented above)
  • 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
  • V = Volume : 0 to 255 or -15 to -1
  • F = Low pass filter cut off : 0xf to 0×0
  • R = Resonance – bits 12,11,10
  • N = Note – Range 0 to 364
  • D = Duration of sound in 20ths of a second.
  • ENVELOPE command has different parameters for RDSP:
  • ENVELOPE N,W,F,O,T,S2,S13,D1,D2,D3,A,D,S,R
  • N = envelope number (1 to 127)
  • W = Same as sound command however 255 is allowed.
  • F = Most signficant 4 bits specify filter cut off
    where 0xf0 is fully open and 0×00 is closed
    Least signficant 4 bits specify Q
  • O = envelope modulation options :
    0×01 – ADSR pitch modulation
    0×02 – ADSR fiter modulation
    0×04 – ADSR PWM modulation
    0×08 – 3 stage envelope amplitude modulation
    0×10 – 3 stage envelope pitch modulation
    0×20 – 3 stage envelope filter modulation
    0×40 – 3 stage envelope pulse width modulation
    0×80 – Loop 3 stage envelope
  • T = time of 3 stage envelope in 100ths of a second
  • S2 = number of steps in stage 2 of 3 stage envelope
  • S13 = number of steps in stage 1 and 3 of 3 stage envelope
  • D1 = modulation of parameters selected by O for 3 stage envelope in stage 1
  • D2 = modulation of parameters selected by O for 3 stage envelope in stage 2
  • D3 = modulation of parameters selected by O for 3 stage envelope in stage 3
  • A = ADSR attack amount. Larger values are longer
  • D = Decay amount. Larger values relative to S are supposed to create a pluck
    effect.
  • S = Sustain volume proportion. The duration is set by the sound command ‘D’
    Larger values are lounder and sustain volume is proportional to ‘V’
    in the sound command.
  • R = Release time. Larger values are longer
  • Shared delay (echo) effect that can be mixed into individual channels

Pending features (planned for next alpha release):

  • Capability to link a looped sample as waveform in envelope commands
  • Improved legacy sound integration e.g. legacy envelope command integration
  • Capability to play back on hardware that does not support 44khz audio.
  • Master volume control
  • Stereo pan
  • Chorus effect
  • Overdrive effect
  • Warm effect

Known Alpha Bugs:

  • Whilst attack,sustain and release work correctly, decay has little effect and should probably be logarithmic.
  • Sample load errors are not reported correctly.
 
Jan 2, 2017 6:49pm
Avatar Steve Pampling (1551) 7104 posts

Nice work. Good to see people working on these things.

BTW. A few typos in the readme:

Typo: significant (missing “i”)
• F = Most signficant 4 bits specify filter cut off
where 0xf0 is fully open and 0×00 is closed
Least signficant 4 bits specify Q

Typo: filter (missing “l” )
• O = envelope modulation options :
0×01 – ADSR pitch modulation
0×02 – ADSR fiter modulation

Typo louder (extraneous “n”)
• S = Sustain volume proportion. The duration is set by the sound command ‘D’
Larger values are lounder and sustain volume is proportional to ‘V’

Typo: attack, sustain (missing space)
• Whilst attack,sustain and release work correctly, decay has little effect and should probably be logarithmic.

HTH.

 
Jan 3, 2017 2:41pm
Avatar Anthony Vaughan Bartram (2454) 426 posts

Thanks for checking the ‘readme’ Steve. I’ll get those typos fixed.

Don’t suppose I could persuade you to do a code review? (Sorry about the tabulation in DSP.c. I’ll remove the TABs in the next release).

Cheers,

Tony

 
Jan 3, 2017 3:09pm
Avatar Steve Pampling (1551) 7104 posts

Don’t suppose I could persuade you to do a code review?

You’d want a programmer to look over your code and much as I’d like to have those talents…
Hacking and twiddling with other peoples stuff occasionally is about my limit as it stands.

 
Jan 3, 2017 11:05pm
Avatar Anthony Vaughan Bartram (2454) 426 posts

Just wondering (once I’ve got the legacy Envelope mode running) if Cybertron Mission’s sound will work? I’m going to try this out later this week.
http://homepages.paradise.net.nz/mjfoot/riscos.htm


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….

Thanks for your input.

Tony

 
Jan 3, 2017 11:06pm
Avatar Anthony Vaughan Bartram (2454) 426 posts

Actually, David, Patrick, Rob, Greg – please, if you have time, would you try the module and examples supplied?

Apologies in advance if anything breaks… :-/

 
Jan 3, 2017 11:57pm
Avatar rob andrews (112) 200 posts

Hi Anthony just ran all exapmles on OPMAP5432EVM (home built rom 30 Dec 2016) with only one problem
it sets the system bleep the the last sound used if you kill the module it returns back to normal.

 
Jan 4, 2017 12:11am
Avatar Anthony Vaughan Bartram (2454) 426 posts

Thanks Rob. Much appreciated. Pleased it runs on OPMAP5432EVM

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).

 
Jan 4, 2017 12:26am
Avatar rob andrews (112) 200 posts

if it runs on my system it will run on any of the Cortex A15 ports titanium or rapido, have tested on Pi3 on problems, can’t test the game as i have no 256 colour mode availble on EVM

 
Jan 4, 2017 12:34am
Avatar Anthony Vaughan Bartram (2454) 426 posts

Thanks Rob.
Cybertron mission will require the *legacy switch (assuming it still calls OS Word 8) as by default the RDSP ENVELOPE 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.

 
Jan 4, 2017 12:50am
Avatar Anthony Vaughan Bartram (2454) 426 posts

Just for fun, I’ve tried a more effective demonstration of the XOR effect. Sounds a bit guitar like to me.

10 PRINT “Delay effect, pulse wave modulation filter and XOR channel modulation”
15 PRINT “Version 2: A bit of Sci-fi and Guitar”
20 *RSTART
30 *RDELAY 50 100
40 *RFXMIX 2 1
50 *RFX 8
60 ENVELOPE 1,&10,&40,&16,2,50,50,-2,-4,-8,40,40,40,40
65 REPEAT
70 SOUND &11,0140,RND ( 364 ) ,100:SOUND &412,&0140,RND ( 364 ) ,100
80 A%=INKEY ( 100 )
90 UNTIL FALSE
 
Jan 4, 2017 1:02am
Avatar Anthony Vaughan Bartram (2454) 426 posts

Just spotted a missing &. Sounds very different with that fixed:

70 SOUND &11,&0140,RND ( 364 ) ,100:SOUND &412,&0140,RND ( 364 ) ,100
 
Jan 4, 2017 1:03am
Avatar rob andrews (112) 200 posts

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.

 
Jan 4, 2017 10:12am
Avatar Greg (2474) 130 posts

Anthony I have ran the demos on my Iyonix and can confirm they play happily with AMPlayer playing an MP3. So thats good

3CHORDS : Plays very quiet until I press ESCAPE then plays much louder and appears perfect

BANG : Appears to play OK. Not what I thought of as a bang but that is probably just my interpretation so is probably doing exactly as it is supposed to be doing

BBC : No problems

DRUMS : Plays extremely quick

STAR-COMMAND : No Problems

WAVES : No problems

XOR-PWM : No problems

So far impressed

I also played some of the WAVs using PlaySound whilst playing the demos and found that :-

BANG BBC STAR-COMMAND

Introduced crackling into the effect they were trying to achieve. Also played some MP3s using PlaySound and did not get any crackling.

Hope this helps. I am looking forward to the progress towards a finished product.

Well done

 
Jan 4, 2017 1:09pm
Avatar Anthony Vaughan Bartram (2454) 426 posts

Thanks Greg.

My planned timescale is to finish this prior to the South West show in February.

I think the crackling when PlaySound plays the WAVs may be partly caused by RDSP using the full dynamic range (available volume) and it clipping.

The fast drums might have been caused by a key-press as I’m only using A%=INKEY() to set the tempo.

Given the testing performed so far, I think RDSP is running sufficiently fast that I could increase the channels to 16.
Only channels that are active run, so this provides a form of scalability.

Unfortunately, with 16 channels I’m going to be causing users a problem if I constantly ask them to reduce volume levels based on multiple channels playing together.

Therefore I will add a Dynamic Range Compressor (and maybe make it configurable).

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.

 
Jan 4, 2017 11:30pm
Avatar Jeffrey Lee (213) 5982 posts

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)

 
Jan 5, 2017 12:30am
Avatar Anthony Vaughan Bartram (2454) 426 posts

Thanks Jeffrey. I’ll try out performance counters once I’ve added my ASM veneer.

Next page

Pages: 1 2

Reply

To post replies, please first log in.

Forums → General →

Search forums

Social

Follow us on and

ROOL Store

Buy RISC OS Open merchandise here, including SD cards for Raspberry Pi and more.

Donate! Why?

Help ROOL make things happen – please consider donating!

RISC OS IPR

RISC OS is an Open Source operating system owned by RISC OS Developments Ltd and licensed primarily under the Apache 2.0 license.

Description

General discussions.

Voices

  • Anthony Vaughan Bartram (2454)
  • Bryan Hogan (339)
  • David Feugey (2125)
  • Patrick M (2888)
  • Rob Heaton (274)
  • Greg (2474)
  • Steve Pampling (1551)
  • rob andrews (112)
  • Jeffrey Lee (213)

Options

  • Forums
  • Login
Site design © RISC OS Open Limited 2018 except where indicated
The RISC OS Open Beast theme is based on Beast's default layout

Valid XHTML 1.0  |  Valid CSS

Powered by Beast © 2006 Josh Goebel and Rick Olson
This site runs on Rails

Hosted by Arachsys