Sound on RISC OS 5.21
Chris Hall (132) 3558 posts |
A game I have written has worked satisfactorily since 1994 using a sound module to simulate bell sounds (generated by something called ‘KeySound’ – a BASIC programme featured in ‘BBC Micro User’ in August 1990 that allows voices to be designed and generates a sound module with those defined voices for bells, harpsichords, etc.). It still works on all but recent roms for the Pandaboard ES, where it is (i) too high-pitched [see other forum posts] and (ii) not correctly timed [see bug ticket 347]. Any suggestions please? The relevant lines are:
followed by SOUND commands from BASIC. Repeated such sounds are generated by SoundTest – is this ‘helium behaviour’ easy to fix please (SoundTest itself is not the culprit here)? Alternatively can someone suggest a tweak to ‘KeySound’ to make it work on modern hardware that cannot emulate earlier behaviour (although it seems this was a deliberate decision by the programmers rather than a change forced by the hardware!). For the OMAP4 port a HAL change in April 2013 (version 1.14) is probably to blame for this bug: s/Audio: but as there is a separate timing problem, then working out a fix at this stage is not suitable. I am pleased to say that the stable build of 5.20 (10-Jun-2013) for the ARMini works correctly and does not suffer from this behaviour. I assume that the 5.20 builds for Risc PC and Iyonix will also be OK. Meanwhile I recommend that users on the Pi and on the Pandaboard stay with RC8 and RISC OS 5.19 as this needs to be fixed in RISC OS 5.21. |
Chris Hall (132) 3558 posts |
A work around the problem where BASIC expects a sample period of 1cs but where the hardware behaves differently is as follows:
… replace
with
to get duration and delay timing right
In voice handlers: MOV R2,R2,ASL #8 For envelope control where tremelo and/or envelope control is applied
Hope this helps. |
Chris Hall (132) 3558 posts |
The updated ‘KEYSOUND’ voice generator provides a Bell, Harpsicord and other effects, allowing the haronic content, amplitude envelope and tremelo to be edited and played at 90kHz Edit correction: |
jim lesurf (2082) 1438 posts |
Can I suggest that people explictly say either ‘96k’ or ‘’88.2k’ in such cases? It does make a difference to various related issues. And because most audio CD derived and mp3 material tends to be 44.1k, having a system rate of 88.2k has some practical advantages over 96k. Jim |
Chris Hall (132) 3558 posts |
I would do, but the Pandaboard explicitly reports 90.9090909 kHz.
Edited: |
Jeffrey Lee (213) 6048 posts |
Sound_Configure is a bad choice to use for reading the sample rate on anything above RISC OS 3.1, due to Acorn’s short-sightedness in making it return a sample period measured in microseconds. In fact, in some cases it was even a bad choice to use on RISC OS 3.1 (e.g. if you’re using a monitor type that uses a different VIDC clock rate to the default. Sound_Configure doesn’t return an adjusted value, and even if it did return an adjusted value it would probably have been inaccurate still). Instead, you should be using Sound_SampleRate, which returns the sample rate in units of 1/1024Hz: SYS "Sound_SampleRate",1 TO ,,r2% PRINT "Sample rate=";r2%/1024;"Hz" Of course, Sound_SampleRate isn’t perfect either, as some VIDC rates aren’t integer values (e.g. 48us is 20833.3Hz recurring). But for modern hardware it’s a lot more accurate than Sound_Configure will be. |
Chris Hall (132) 3558 posts |
Which one does BASIC use to decide the value of the phase accumulator increment (R9+4 in the SCCB) to send to voice handlers to get the desired pitch correct please (which I am glad to say it does)? For example SOUND 1,-15,pitch,duration,delay for middle C (pitch=53, freq=261.6Hz) sends &C2 on the Pandaboard where I worked out &BC would be correct, using 90.9kHz Edited: |
jim lesurf (2082) 1438 posts |
FWIW in !SoundCheck I use the following to get rate details rin.r0=1; _kernel_swi(0×40146,&rin,&rout); index=rout.r1; current_rate=rout.r2 / 1024; printf(“Current rate index = %4d => rate %d samples per sec\n\n”,index,current_rate);(Sorry the above is a mess. Struggling with ‘textile’. How the devil do you get a block of code to come out right?) which supports what Jeffrey says. So I’d echo his suggestion. Occurs to me to try and remember to add a ‘deprecated’ warning to the ROSS document about this and advising people to avoid the unreliable swi. Jim |
Dave Higton (1515) 3534 posts |
Surround it with pre and /pre tags inside angle brackets. |
jim lesurf (2082) 1438 posts |
Ok, I’ll try that. I’d tried ‘code’ and ‘notextile’ in angle brackets because I’d read that should work, but nope… Was wondering about trying TT…. However: rin.r[0]=1; _kernel_swi(mumble,&rin,&rout); index=rout.r[1]; Let’s see… Yes! :-) Thanks, Jim BTW Now seen the “90kHz sound” description appear on c.s.a.announce. Hope it doesn’t spread as confusion may result. :-/ |
Chris Hall (132) 3558 posts |
Default sound on the Pandaboard is 88.2kHz using the SYS “Sound_SampleRate” to get the accurate figure. 96kHz is also available. Some earlier posts edited. |
Chris Hall (132) 3558 posts |
For a bit more accuracy replace
with
The problem is that you really need a sample time rather than a sample frequency. |
Chris Hall (132) 3558 posts |
When BASIC uses the SOUND command in the form SOUND 1,-15,pitch,duration it should send a pitch increment value in the SCCB to the voice handler that specifies 256 times the number of 1/256ths of a cycle that would correspond to the intended pitch at the prevailing sample rate. On the Pandaboard it gets it right. For example to sound middle C (261.6Hz) at a sample rate of 96kHz then you need to skip &B2/&100 of the 1/256 of a 261Hz cycle samples (because 261.6*256*256/96000 = &B2) whereas the corresponding value at 88.2kHz is &C2. On some other platforms (e.g. Iyonix running RISC OS 5.16 and VRPC Adjust) BASIC seems to assume a 20.8kHz sample rate. A simple test utility can be downloaded here which provides a keyboard simulating several different instruments and offering the user the choice of all the available sample rates to try it at. Sounds quite good on the Pandaboard at 88.2kHz. |
Jeffrey Lee (213) 6048 posts |
BASIC’s SOUND command is just a wrapper for the Sound_Control SWI, which was indeed ‘broken’ ever since its inception as it was (a) assuming sound interrupts/buffer fills occur every centisecond (if a different buffer fill rate was used the sounds would have the wrong duration), and (b) relying on the user to manually adjust the *TUNING value in order to get the correct pitch for the current system sample rate (the default TUNING value assumed 48us sample period, i.e. 20.8kHz). I fixed both of these issues by adding support for the ‘*TUNING AUTO’ option, which defaults to on. However as you’ve already noted there are still problems in other areas of the sound system where a 1cs buffer fill rate is assumed. |
jim lesurf (2082) 1438 posts |
Ah-ha! Hadn’t known about that. I must add it to the ROSS document! :-) Yup. *help tun. shows it. FWIW I’m currently struggling with all the different documents on SharedSound. These conflict (mainly due to age, etc) and sometimes contain gems that would alarm the Plain English Campaign people. ;→ Jim |