[vorbis-dev] Libvorbis suggestion & floating point exception
Jan Lellmann
Jan.Lellmann at web.de
Wed Sep 25 16:30:41 PDT 2002
Since nobody likes to reply, I'll do it myself :)
The floating point exception is a "divide by zero", which happens quite
often (and in several places) in libvorbis, the most prominent place being
fit_line called with one or zero points to fit.
I figured this does not affect some (most) people because of the floating
point exception handling turned off by their compilers/on their systems, so
I tried to just disable it and it actually seems to work.
So for anyone having the same problem, I inserted these two functions:
---snip---
unsigned short FPU_Disable_Exceptions()
{
unsigned short cw, cwnew;
asm { FSTCW cw };
cwnew = cw | 0x0005; // Disable divide by zero/invalid operation
exceptions
asm { FLDCW cwnew };
return cw;
}
void FPU_Restore_Exceptions(unsigned short cw)
{
asm { FCLEX; FLDCW cw };
}
--- snip ---
Then just put
unsigned short fpucw = FPU_Disable_Exceptions();
at the beginning and
FPU_Restore_Exceptions(fpucw);
at the end of the function calling vorbis_analysis(). This will disable
exception handling and just return NaN when dividing by zero. The encoded
streams seem to be correct and flawless, though.
Note this is just a workaround and in no way portable code, I tested it only
under W2K, with Borland C++ Builder 5.
Greetings,
Jan
<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