Skip to content

ref_struct_VDXFraction

shekh edited this page Apr 15, 2018 · 1 revision

VirtualDub Plugin SDK 1.2

VDXFraction structure

Declares a fraction of two 32-bit integers.

Definition

struct VDXFraction {
    uint32 mNumerator;
    uint32 mDenominator;
};

Fields

mNumerator
The numerator of the fraction. This normally may not be zero.

mDenominator
The denominator of the fraction. This normally may not be zero.

Remarks

The value of the fraction is, as expected, equal to the numerator divided by the denominator. A fraction object is used instead of a floating-point number to exactly represent common frame rates, most notably NTSC's field rate of 60000/1001 = ~59.94 fields/sec.

A fraction need not be reduced to lowest terms, either on the host or plugin side. 30/1 and 30000/1000 should always be treated exactly the same. If you have a frame rate stored as a period in microseconds in your plugin, feel free to return 1000000/period as the fraction.

Unless specified otherwise in a structure or API, the denominator should never be zero, as that indicates a division by zero. A numerator of zero is less troublesome but should also not be used unless allowed; a frame rate of zero in a video stream is also nonsensical.

When a fraction must be multiplied or divided, one approach is to attempt to multiply either the numerator or denominator as appropriate, and if an overflow would occur, divide the other term instead as an approximation. This should be done carefully, as the full range of either term is possible — in particular, expect FFFFFFFF to show up occasionally in the numerator.

If you want to get fancy, you can use Euclid's algorithm to compute the greatest common denominator (GCD) for reducing fractions and continued fractions to determine the best possible approximation for fractions that don't reduce into 32/32 bits. This may be overkill for most cases, though. To convert a floating-point value to a fraction, simply break the floating-point representation into mantissa and exponent and reduce.


Copyright (C) 2007-2012 Avery Lee.

Clone this wiki locally