Sanitising Sound_Control
Jeffrey Lee (213) 6048 posts |
One of the things that annoys me about sound on RISC OS is the way that changing the system sample rate results in the system beep and other sounds (e.g. Maestro) changing in pitch/duration. After investigating the issue today it looks like this is all down to the behaviour of Sound_Control, the SWI which ultimately gets used whenever something wants to play an 8-bit sound. Sound_Control is meant to play a sound at a given frequency (typically specified in octaves) and for a specified duration (specified in 5cs units). But the calculations it performs when converting those values to internal units are designed around the standard VIDC sample rate of 20833Hz and buffer period of 1cs. So if you’re using anything other than the default sound settings, chances are any standard 8-bit sounds will be wrong. As far as I know Sound_Control has been like this since the dawn of time, so it’s possible there’s some software out there which already contains workarounds for its quirks. But that shouldn’t be any reason for us not to fix it. So I’m proposing the following solution:
Any thoughts? |
Trevor Johnson (329) 1645 posts |
Sounds like this will be another brilliant improvement. Will the proposed buffer fill count calcs carry with them any significant FP implications? Does Sound_Control need to calculate this each time or can it use a value only recalculated (and stored elsewhere) whenever the settings are changed? |
Jeffrey Lee (213) 6048 posts |
Calculating the right buffer fill count is easily done in fixed point math; there shouldn’t be any performance penalty. |
Colin Ferris (399) 1814 posts |
I presume that the module “PlayIt” converts the various samples and the data code like SSound drive the various hardware. |
Andrew Rawnsley (492) 1445 posts |
Yes, we have it. We’ve made it open source, so please get in touch. I’m awaiting the latest changes from Willi and then it’ll be publicly downloadable somewhere. Future versions of !PlayIt should ship with source. |
Trevor Johnson (329) 1645 posts |
Is it possible this’ll be included in a future ROOL disc image? |
Keith Dunlop (214) 162 posts |
So that is why the sysem beep goes funny after using something like !DigitalCD or !MusicMan to play 44.1/16 tracks. Once the source is available !PlayIt needs to be permanently modified so that it talks straight to SharedSound so that Jeffrey’s program to do this isn’t required. |
Willi Theiss (541) 17 posts |
!PlayIt does not access any sound hardware by itself; this is solely done by the loaded driver. And therefore Jeffrey’s SharedSound driver should be part of !PlayIt distribution. |
Andrew Rawnsley (492) 1445 posts |
I am just awaiting Jeffrey’s approval on that point, Willi. I have sent him a proposed !PlayIt distribution with application and source. I also need to sanitise some of the docs, as Rick has asked that we (collectively) be the point of contact, rather than him in future. |
Jeffrey Lee (213) 6048 posts |
Yep – I saw your email last night but didn’t get round to replying to it. Getting back to Sound_Control: For this automatic tuning to work cleanly, I think we could do with extending Service_Sound with a few new reason codes:
The automatic *Tuning only needs reason 8, but since there’s currently no notification for when audio starts/stops I figured it would be a good idea to add some reason codes for those as well. The only problem is that I can’t think of an easy way for software to check if the version of SoundDMA in use provides the above service calls. They can’t just check the version number since we’ve got three different branches of SoundDMA in use (ick!), and we’d still end up with conflicts with ROL’s version(s) as well. There are plenty of SWIs spare, so we could add a new one for checking module features, or we could just tack an extra reason code onto Sound_Mode. |
Steve Revill (20) 1361 posts |
Sound_ReadSysInfo ? We have OS_ReadSysInfo and Wimp_ReadSysInfo after all… |
Jeffrey Lee (213) 6048 posts |
Makes sense to me. I guess adding an extra SWI was always going to be the best solution. There’s other information it might need to return in future, e.g. when we get the sound recording API sorted out we need a way of indicating whether the input and output sample rates must match (OMAP) or whether they can be different (Iyonix). |
Trevor Johnson (329) 1645 posts |
As I’ve failed to locate a more appropriate thread, I’m posting this here in case it’s of some interest to someone who’s not seen it before. If not, please ignore.
|
Jeffrey Lee (213) 6048 posts |
If you can’t find an appropriate thread, you can always create a new one. Back on topic – the auto tuning code is now mostly working, but there are a few issues remaining:
|
Jeffrey Lee (213) 6048 posts |
I managed to get this code checked in over the weekend. I haven’t tackled the remaining WaveSynth/string lib problems (deciphering how the voice generators work is a bit tricky), but I did have a quick look at the tempo problem. After checking the PRMs it looks like the tempo value is specified relative to a 100Hz base rate, so the problem is that SoundScheduler is assuming that a 100Hz buffer fill rate is in use. So when I get a chance I’ll probably update SoundScheduler to adapt its tempo rate if automatic tuning is enabled (I don’t think there’s much point having a seperate option for automatic tempo). |
Jeffrey Lee (213) 6048 posts |
Documentation for the new service calls here (pretty much the same as listed in this thread, except I inadvertently swapped R2 & R3 during implementation), Sound_ReadSysInfo SWI here, and updated Sound_Tuning SWI here (Not entirely sure why I chose to use a magic parameter instead of adding a new SWI. The fact that the sound modules don’t generate an error when you call unknown SWIs probably had something to do with it.) |