List of usage examples for org.apache.commons.lang.math Fraction getDenominator
public int getDenominator()
Gets the denominator part of the fraction.
From source file:com.castlabs.dash.helpers.ManifestHelper.java
/** * Creates a representation and AudioChannelConfiguration if appropriate. *///from ww w . j av a 2s .c o m public static RepresentationType createRepresentation(AdaptationSetType adaptationSet, Track track) { RepresentationType representation = adaptationSet.addNewRepresentation(); if (track.getHandler().equals("vide")) { long videoHeight = (long) track.getTrackMetaData().getHeight(); long videoWidth = (long) track.getTrackMetaData().getWidth(); double framesPerSecond = (double) (track.getSamples().size() * track.getTrackMetaData().getTimescale()) / track.getDuration(); Fraction fraction = Fraction.getFraction((int) videoWidth, (int) videoHeight).reduce(); adaptationSet.setPar("" + fraction.getNumerator() + ":" + fraction.getDenominator()); //representation.setMimeType("video/mp4"); representation.setCodecs(DashHelper.getRfc6381Codec(track.getSampleDescriptionBox().getSampleEntry())); representation.setWidth(videoWidth); representation.setHeight(videoHeight); representation.setFrameRate(convertFramerate(framesPerSecond)); representation.setSar("1:1"); // too hard to find it out. Ignoring even though it should be set according to DASH-AVC-264-v2.00-hd-mca.pdf } if (track.getHandler().equals("soun")) { AudioSampleEntry ase = (AudioSampleEntry) track.getSampleDescriptionBox().getSampleEntry(); //representation.setMimeType("audio/mp4"); representation.setCodecs(DashHelper.getRfc6381Codec(ase)); representation.setAudioSamplingRate("" + DashHelper.getAudioSamplingRate(ase)); DescriptorType audio_channel_conf = representation.addNewAudioChannelConfiguration(); DashHelper.ChannelConfiguration cc = DashHelper.getChannelConfiguration(ase); audio_channel_conf.setSchemeIdUri(cc.schemeIdUri); audio_channel_conf.setValue(cc.value); } return representation; }
From source file:com.castlabs.dash.helpers.ManifestHelper.java
public static String convertFramerate(double vrate) { Fraction f1 = Fraction.getFraction((int) (vrate * 1001), 1001); Fraction f2 = Fraction.getFraction((int) (vrate * 1000), 1000); double d1 = Math.abs(f1.doubleValue() - vrate); double d2 = Math.abs(f2.doubleValue() - vrate); if (d1 < d2) { return f1.getNumerator() + "/" + f1.getDenominator(); } else {/* w w w . j av a 2 s . com*/ return f2.getNumerator() + "/" + f2.getDenominator(); } }
From source file:pcgen.cdom.facet.analysis.ChallengeRatingFacet.java
public int getXPAward(CharID id) { Map<String, Integer> xpAwardsMap = SettingsHandler.getGame().getXPAwards(); if (xpAwardsMap.size() > 0) { Float cr = getCR(id);/*from w w w .j a v a 2s. c om*/ if (cr.isNaN() || cr == 0) { return 0; } String crString = ""; String crAsString = Float.toString(cr); String decimalPlaceValue = crAsString.substring(crAsString.length() - 2); // If the CR is a fractional CR then we convert to a 1/x format if (cr > 0 && cr < 1) { Fraction fraction = Fraction.getFraction(cr);// new Fraction(CR); int denominator = fraction.getDenominator(); int numerator = fraction.getNumerator(); crString = numerator + "/" + denominator; } else if (cr >= 1 || cr == 0) { int newCr = -99; if (decimalPlaceValue.equals(".0")) { newCr = (int) cr.floatValue(); } if (newCr > -99) { crString = crString + newCr; } else { crString = crString + cr; } } return xpAwardsMap.get(crString); } return 0; }
From source file:plugin.exporttokens.CRToken.java
/** * @see pcgen.io.exporttoken.Token#getToken(java.lang.String, pcgen.core.PlayerCharacter, pcgen.io.ExportHandler) *///from w w w . jav a 2 s . c o m @Override public String getToken(String tokenSource, CharacterDisplay display, ExportHandler eh) { String retString = ""; Float cr = display.calcCR(); String crAsString = Float.toString(cr); String decimalPlaceValue = crAsString.substring(crAsString.length() - 2); if (cr > 0 && cr < 1) { // If the CR is a fractional CR then we convert to a 1/x format Fraction fraction = Fraction.getFraction(cr);// new Fraction(CR); int denominator = fraction.getDenominator(); int numerator = fraction.getNumerator(); retString = numerator + "/" + denominator; } else if (cr >= 1 || cr == 0) { int newCr = -99; if (decimalPlaceValue.equals(".0")) { newCr = (int) cr.floatValue(); } if (newCr > -99) { retString = retString + newCr; } else { retString = retString + cr; } } else if (cr.isNaN()) { retString = "0"; } return retString; }