Rockbox Technical Forums

Support and General Use => Plugins/Viewers => Topic started by: Adion on August 24, 2006, 01:27:46 PM

Title: Sound/DSP from within plugins?
Post by: Adion on August 24, 2006, 01:27:46 PM
Does anyone know if it's possible to play sound from within a plugin while music is playing, or if it is possible to alter the sound that is currently playing?

One of the things that I want to do with it is add a function to the stopwatch plugin to have it play a sound at regular intervals so that you don't have to look at the screen while jogging for example.
Other things that I can think of that may be interesting is that it would be easy of any kind of dsp functions could be done by creating a plugin that can alter the sound. (Compressors, equalizers, ... could all be written as plugins then)

It would be great if a plugin could get a callback from the audio system on each buffer to do this, but I haven't searched into the rockbox core yet to find out if this is possible, and if this could work for on all targets.
Maybe some developer with a bit more rockbox experience could point me in the right direction?
Title: Re: Sound/DSP from within plugins?
Post by: Adion on August 24, 2006, 03:50:11 PM
Ok, I have been looking into this a bit more, and I managed to create a first test plugin that alters the sound :)

To do this, I added a function pointer to dsp.c:
Code: [Select]
static void (*dsp_external)(int32_t* src[], int count);And I made dsp_process use this function if it is not NULL.
I also added a function to edit this pointer to dsp.h, and I then added this edit function to the plugin structure.
Finally I initialized the dsp callback function at the start of the plugin, and set it back to NULL when the plugin was finished.

For now I just tested a plugin that lowers the volume as a test, and this works, although there is a delay of a few seconds it seems between starting the plugin and hearing the volume drop (which is probably not that much of a problem for most plugins)

My suggestion if more people think this kind of functionality would be useful is to create an array of dsp function pointers, along with a function to add and remove dsp functions from that array.
That way you could even enable multiple sound plugins, and the current dsp functions (equalizer and crossfeed) could also be added by default to the same array.
Title: Re: Sound/DSP from within plugins?
Post by: xlarge on August 25, 2006, 06:00:05 AM
Glorious!

I'm thinking normalizing compressor/limiter. All tracks at the same percepted volume.
Title: Re: Sound/DSP from within plugins?
Post by: Llorean on August 25, 2006, 06:05:17 AM
Replaygain already pretty much does that... And since it's precalculated it'll be more battery efficient than trying to do it during playback.
Title: Re: Sound/DSP from within plugins?
Post by: xlarge on August 25, 2006, 06:22:56 AM
Replaygain already pretty much does that... And since it's precalculated it'll be more battery efficient than trying to do it during playback.

If i get my tracks tagged for it - true.
Title: Re: Sound/DSP from within plugins?
Post by: Llorean on August 25, 2006, 06:25:17 AM
Well, considering the speed of the processors on the players, you're going to get *much* better results pre-tagging for replaygain than attempting to do something similar realtime.
Title: Re: Sound/DSP from within plugins?
Post by: xlarge on August 25, 2006, 06:39:18 AM
If you say so sir.
Title: Re: Sound/DSP from within plugins?
Post by: Adion on August 25, 2006, 09:30:42 AM
There was a user (not sure if I read it on the forums or in the feature requests) that wanted a normalizer/compressor in real-time so that silent parts would get played louder for listening in a car for example.
Replaygain is very suited for volume differences between songs, but not for volume differences within a song.

Anyway I'm now working on my stopwatch update that will play beeps at regular intervals, and when you press a button, and it's beginning to work quite nice.
Title: Re: Sound/DSP from within plugins?
Post by: mborus on October 11, 2006, 11:06:51 AM
Code: [Select]
There was a user (not sure if I read it on the forums or in the feature requests) that
wanted a normalizer/compressor in real-time so that silent parts would get played louder for
listening in a car for example.

Replaygain is very suited for volume differences between songs, but not for volume
differences within a song.

This is a very late comment, but just to get the discussion going again:

A compressor might not be that useful for music, but it's essential, if you
want to play back recordings of lectures or other live recordings in a
noisy environment.

The original Archos jukeboxes have a hardware gain control.
There's a setting that adjusts the volume every 20ms (or so)

A fast reaction time like this ensures that the lecturer can be heard
clearly, but that coughs or other load audience noises don't damage your
speakers and/or hearing.