Jan Lellmann
2002-Sep-23 15:50 UTC
[vorbis-dev] Libvorbis suggestion & floating point exception
Hello, I'm not quite sure if this is the right list for my questions, please excuse if it isn't. 1. While using vorbislib (Win2K/Borland C++ Builder 5), I'm getting reproducible floating point exceptions at lots of sample rate/bit rate combinations. For example, the original encoder_example.c, with just the initialization line changed to vorbis_encode_init(&vi,2,22050,48000,48000,48000); generates a "floating point exception 0xc0000090" in psy.c / bark_noise_hybridmp (line 642). The code reads: D = tN * tXX - tX * tX; R = (A + fi * B) / D; Before the crash, tXX and tX are both 0, thus D == 0. This causes a "divide by zero". As said, it is reproducible every single time. At higher sample rates it works at 48kbps, but crashes at higher bit rates. I tested the 1.0 build (static as well as the pre-built DLL from the distribution) and the CVS snapshot, same result. However, at 44.1kHz all bit rates seem to work. Any ideas? <p>2. In vorbisenc.c / vorbis_encode_setup_managed, there's a piece that reads: if(nominal_bitrate<=0.){ if(max_bitrate>0.){ nominal_bitrate=max_bitrate*.875; }else{ ... If only min_bitrate and max_bitrate are passed, and nominal_bitrate set to zero for "auto" mode, nominal_bitrate might actually end lower than min_bitrate (e.g. if min_bitrate == max_bitrate for "CBR" emulation). I think it should be something like: if(nominal_bitrate<=0.){ if(max_bitrate>0.){ nominal_bitrate=max(min_bitrate, max_bitrate*.875); }else{ ... 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@xiph.org' containing only the word 'unsubscribe' in the body. No subject is needed. Unsubscribe messages sent to the list will be ignored/filtered.
Jan Lellmann
2002-Sep-25 16:30 UTC
[vorbis-dev] Libvorbis suggestion & floating point exception
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@xiph.org' containing only the word 'unsubscribe' in the body. No subject is needed. Unsubscribe messages sent to the list will be ignored/filtered.
David K. Gasaway
2002-Sep-25 22:14 UTC
[vorbis-dev] Libvorbis suggestion & floating point exception
On 24 Sep 2002 at 0:50, Jan Lellmann wrote:> I'm not quite sure if this is the right list for my questions, please > excuse if it isn't. > > 1. While using vorbislib (Win2K/Borland C++ Builder 5), I'm getting > reproducible floating point exceptions at lots of sample rate/bit rate > combinations.Hello, Jan! I use BCB4, and shortly before the 1.0 release, I was having divide by zero exceptions in libvorbis. However, my problems were fixed by the 1.0 release, and I haven't had any trouble since. I'd be happy to test something for you, if you'd like. -- -:-:- David K. Gasaway -:-:- XNS : =David K Gasaway -:-:- Email: dave@gasaway.org -:-:- Web : dave.gasaway.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@xiph.org' containing only the word 'unsubscribe' in the body. No subject is needed. Unsubscribe messages sent to the list will be ignored/filtered.