[vorbis-dev] Suggestion for libvorbisfile: scaling

Brian Olson locke at mac.com
Thu Jan 3 06:16:00 PST 2002



ov_read and ov_read_float both call:
int      vorbis_synthesis_pcmout(vorbis_dsp_state *v,float ***pcm);

for ov_read() the data is then coerced into int form.

I think ov_read() is  the right place to do the scaling. Doing it inside 
the decoding in block.c might make that code yet more complex. 
ov_read_float doesn't need to be scaled because very little is lost if 
you scale the float data outside that function. It makes a big 
difference to scale before coercing into integer data if you're unlucky 
enough to have a signal quiet enough to otherwise only use 1% of the 
encoding, or worse so loud that it clips.
  (or is normalizing taken care of elsewhere that I haven't found yet? if 
not, gain-on-input is another feature I'd like to see)

if the prototype for ov_read() is now writ in stone, how about:
long ov_read_gain(OggVorbis_File *vf,char *buffer,int length,
                     int bigendianp,int word,int sgned,float gain,int 
*bitstream)

ov_read() could internally call ov_read_gain(..., 1, ...);
that would save on code, but there _might_ be a speed issue, and maybe 
some processor's floating point will be unlucky enough to lose a bit of 
accuracy by multiplying everything by 1.0000000...

perhaps a little C-style preprocessor templating, remove the body of 
ov_read() into ov_read.h (or .ic if you like)
(I'll make a patch to implement this if I'm not flamed off the list for 
it being a gross hack.)
change several lines in ov_read like this one:
val=vorbis_ftoi(src[j]*32768.f);
to this:
val=vorbis_ftoi(src[j]*32768.f TIMES_GAIN);

#define TIMES_GAIN * gain
ov_read_gain(...) {
#include "ov_read.h"
}
#undefine TIMES_GAIN
#define TIMES_GAIN
ov_read(...) {
#include "ov_read.h"
}
#undefine TIMES_GAIN

On Thursday, January 3, 2002, at 05:03  AM, Paul Martin wrote:

> I've been experimenting with the ideas of Replay Gain[1] and find that
> ogg123 doesn't have a way of specifying the scaling applied to
> replayed samples (like -f in mpg123).
>
> Looking at libvorbisfile, I see no function exactly matching this
> possibly desirable behaviour.
>
> ov_read() scales by either 128 (byte output) or 32768 (word output),
> but there's nothing in between.
>
> ov_read_float() outputs floats, which is OK, but means more work in the
> frontend program.
>
> My suspicion is that floats are not used internally by ov_read(), and
> there would be a speed penalty for using ov_read_float().
>
> Anyone have further thoughts on this?
>
> [1] http://privatewww.essex.ac.uk/~djmrob/replaygain/
> --
> Paul Martin
>
>

[insert clever signoff here]
Brian Olson http://bolson.org/

<p>--- >8 ----
List archives:  http://www.xiph.org/archives/
Ogg project homepage: http://www.xiph.org/ogg/
To unsubscribe from this list, send a message to 'vorbis-dev-request at xiph.org'
containing only the word 'unsubscribe' in the body.  No subject is needed.
Unsubscribe messages sent to the list will be ignored/filtered.



More information about the Vorbis-dev mailing list