[Vorbis] What's the value range of float samples?

Nikos Chantziaras realnc at gmail.com
Fri Jan 11 07:41:51 PST 2013


On 10/01/13 18:10, Paul Martin wrote:
> On Mon, Jan 07, 2013 at 11:50:20PM +0200, Nikos Chantziaras wrote:
>> On 07/01/13 23:23, Paul Martin wrote:
>>> On Mon, Jan 07, 2013 at 08:53:56PM +0200, Nikos Chantziaras wrote:
>>>
>>>> Apparently, there are Vorbis streams that use float samples with values
>>>> in the range of [-32768, 32767]?
>>>
>>> GIGO.
>>
>> So the answer is no?  Vorbis float values always have a nominal range of
>> [-1,1) and I can always clamp/clip to that?
>
> If you feed in "normalized to full scale" values to any lossy encoder,
> you are likely to get overshoots on decoding.  It's good to be aware
> that this might happen and to do your volume scaling (playback gain)
> in the floating point domain before you convert to integers.

I currently simply clip the integer result (for any integer of type 'T') 
and then convert by assuming [-1,1):

     if (src >= 1.f) {
         // Overflow. Clip to max.
         dst = std::numeric_limits<T>::max();
     } else if (src < -1.f) {
         // Underflow. Clip to min.
         dst = std::numeric_limits<T>::min();
     } else {
         dst = src * (float)(1UL << (sizeof(T) * 8 - 1))
                 + ((float)(1UL << (sizeof(T) * 8 - 1))
                    + (float)std::numeric_limits<T>::min());
     }

This is for realtime decoding and playback, so it's not possible to 
decode the whole file first and then scale the entire range according to 
the max/min peak.  Are there any smarter strategies for doing this?  I 
thought of searching the current playback buffer to find the peak, but 
it seems to me that this would result in an uneven result as playback 
progresses.

I suppose ReplayGain could help here for files that do have that 
information in them?



More information about the Vorbis mailing list