public class IrSequence extends Object implements Cloneable, Serializable
Intrinsically, it "is" an array of doubles, each representing a gap (for odd indices) or flash (for even indices). The duration of each flash or gap is the absolute value of the entry in micro seconds. Negative values are thus accepted, and preserved, but the sign ignored. An application program is free to interpret the sign as it wishes. The sign can therefore be viewed as "application specific information."
The length of the IrSequence (as reported by getLength()) is therefore always even. To get the "length in bursts", divide by 2.
The class is (almost) immutable: it can only be constructed and then read from. Also note that there is no modulation frequency herein.
ModulatedIrSequence
,
Serialized FormModifier and Type | Field and Description |
---|---|
protected double[] |
data
Duration data, possibly with signs, which are ignored (by this class).
|
Constructor and Description |
---|
IrSequence()
Constructs an empty IrSequence,
|
IrSequence(ArrayList<Double> list)
Constructs an IrSequence from the parameter data.
|
IrSequence(double[] data)
Constructs an IrSequence from the parameter data.
|
IrSequence(int[] idata)
Constructs an IrSequence from the parameter data.
|
IrSequence(int[] idata,
boolean acceptOdd)
Constructs an IrSequence from the parameter data.
|
IrSequence(int[] idata,
int offset,
int length)
Constructs an IrSequence from the parameter data.
|
IrSequence(IrSequence src)
Constructs an IrSequence from the parameter data, by cloning.
|
IrSequence(PrimaryIrStream irStream)
Constructs an IrSequence from input parameter.
|
IrSequence(String str)
Constructs an IrSequence from the parameter data.
|
IrSequence(String str,
boolean fixOddSequences)
Constructs an IrSequence from the parameter data.
|
Modifier and Type | Method and Description |
---|---|
IrSequence |
addToFlashes(double amount)
Adds an amount to all flashes.
|
IrSequence |
addToGaps(double amount)
Adds an amount to all flashes, and subtract it from all gaps.
|
IrSequence |
append(double delay)
Appends a delay to the end of the IrSequence.
|
IrSequence |
append(IrSequence tail)
Returns an IrSequence consisting of this sequence, with one
copy of the argument appended.
|
IrSequence |
append(IrSequence tail,
int repetitions)
Returns an IrSequence consisting of this sequence, with repetitions
copies of the first argument appended.
|
IrSequence[] |
chop(double threshold)
Chops a IrSequence in parts.
|
IrSequence |
clone()
Creates and returns a copy of this object.
|
static IrSequence |
concatenate(Collection<IrSequence> sequences)
Concatenates the elements in the argument.
|
boolean |
containsZeros()
Returns true if and only if the sequence contains durations of zero length.
|
IrSequence |
flashExcess(double amount)
Adds an amount to all flashes, and subtract it from all gaps.
|
double |
get(int i)
Returns the i'th value, a duration in micro seconds.
|
double |
getDuration()
Computes the total duration of the IR sequence modeled.
|
double |
getDuration(int begin,
int length)
Computes the total duration of a subsequence of the IR sequence modeled.
|
double |
getGap()
Return last entry, of -1 of empty.
|
int |
getLength()
Returns the number of gaps and flashes.
|
int |
getNumberBursts()
Returns the number of bursts, half of the length.
|
int |
iget(int i)
Returns the i'th value, the duration in micro seconds, rounded to integer.
|
boolean |
isEmpty() |
boolean |
isEqual(int beginning,
int compareStart,
int length,
double absoluteTolerance,
double relativeTolerance)
Compares two segments of the current IrSequences for (approximate) equality.
|
boolean |
isEqual(int beginning,
int compareStart,
int length,
double absoluteTolerance,
double relativeTolerance,
double lastLimit)
Compares two segments of the current IrSequences for (approximate) equality.
|
boolean |
isEqual(IrSequence irSequence)
Compares two IrSequences for equality.
|
boolean |
isEqual(IrSequence irSequence,
double absoluteTolerance,
double relativeTolerance)
Compares two IrSequences for (approximate) equality.
|
static void |
main(String[] args)
Just for testing.
|
IrSequence |
noisify(double max)
Adds a random number in the interval [-max, max) to each flash, and
subtract it from the next gap.
|
boolean |
replaceZeros(double replacement)
Replace all zero durations.
|
IrSequence |
subSequence(int start,
int length)
Returns a new IrSequence consisting of the length durations.
|
double[] |
toDoubles()
Returns an array of doubles of durations.
|
int[] |
toInts()
Returns an array of integers of durations.
|
int[] |
toInts(boolean alternatingSigns)
Returns an array of integers of durations.
|
String |
toPrintString()
Formats IR signal as sequence of durations, by preserving signs.
|
String |
toPrintString(boolean alternatingSigns)
Formats IR signal as sequence of durations, with alternating signs or by preserving signs.
|
String |
toPrintString(boolean alternatingSigns,
boolean noSigns)
Formats IR signal as sequence of durations, with alternating signs or by preserving signs.
|
String |
toPrintString(boolean alternatingSigns,
boolean noSigns,
String separator)
Formats IR signal as sequence of durations, with alternating signs, ignoring all signs, or by preserving signs.
|
int[] |
toPulses(double frequency)
For the frequency given as argument, computes an array of durations in number of periods in the given frequency.
|
String |
toString()
Generates a pretty string representing the object.
|
String |
toString(boolean alternatingSigns)
Generates a pretty string representing the object.
|
IrSequence |
truncate(int length)
Returns a new IrSequence consisting of the first length durations.
|
protected double[] data
public IrSequence()
public IrSequence(double[] data) throws IncompatibleArgumentException
data
- Array of durations. Is copied.IncompatibleArgumentException
- If data is not of even length.public IrSequence(int[] idata) throws IncompatibleArgumentException
idata
- Array of durations. Data is copied.IncompatibleArgumentException
- If data is not of even length.public IrSequence(int[] idata, boolean acceptOdd) throws IncompatibleArgumentException
idata
- Array of durations. Data is copied.acceptOdd
- If odd length: if true, force length even by ignoring the last, otherwise throw exception.IncompatibleArgumentException
- If data is not of even length.public IrSequence(String str, boolean fixOddSequences) throws IncompatibleArgumentException, NumberFormatException
str
- String of durations, possibly using signed numbers.fixOddSequences
- it true, odd sequences (ending with space) are silently fixed by adding a dummy gap.IncompatibleArgumentException
- If last duration is not a gap, and fixOddSequences false.NumberFormatException
public IrSequence(String str) throws IncompatibleArgumentException, NumberFormatException
str
- String of durations, possibly using signed numbers.IncompatibleArgumentException
- If last duration is not a gap.NumberFormatException
public IrSequence(int[] idata, int offset, int length)
idata
- Dataoffset
- First index to be usedlength
- Length of used subset of the idata array.public IrSequence(ArrayList<Double> list) throws IncompatibleArgumentException
list
- List of durations as Double, containing signs.IncompatibleArgumentException
- If data ens with a flash, not a gap.public IrSequence(PrimaryIrStream irStream) throws IncompatibleArgumentException, UnassignedException
irStream
- IncompatibleArgumentException
UnassignedException
public IrSequence(IrSequence src)
src
- Originalpublic final double get(int i)
i
- indexpublic final int iget(int i)
i
- indexpublic final int[] toInts()
public final int[] toInts(boolean alternatingSigns)
alternatingSigns
- if true, all the durations with odd index are negative, otherwise, all are positive.public final double[] toDoubles()
public final int[] toPulses(double frequency)
frequency
- Frequency in Hz.public static IrSequence concatenate(Collection<IrSequence> sequences)
sequences
- public IrSequence append(IrSequence tail, int repetitions)
tail
- IrSequence to be appended.repetitions
- Number of copies to append.public IrSequence append(IrSequence tail)
tail
- IrSequence to be appended.public IrSequence append(double delay) throws IncompatibleArgumentException
delay
- microseconds of silence to be appended to the IrSequence.IncompatibleArgumentException
public IrSequence clone() throws CloneNotSupportedException
clone
in class Object
CloneNotSupportedException
public IrSequence subSequence(int start, int length) throws IncompatibleArgumentException
start
- Index of first durationlength
- Length of new sequenceIncompatibleArgumentException
- if length or start are not even.public IrSequence truncate(int length) throws IncompatibleArgumentException
length
- Length of new sequenceIncompatibleArgumentException
- if length not even.public IrSequence[] chop(double threshold)
threshold
- minimal gap in microseconds to cause a cut.public IrSequence addToFlashes(double amount)
amount
- Amount to add in microsecods.public IrSequence addToGaps(double amount)
amount
- Amount (positive or negative) to add in microseconds.public IrSequence flashExcess(double amount)
amount
- Amount (positive or negative) to add in microseconds.public IrSequence noisify(double max)
max
- max amount to add/subtract, in microseconds.public boolean isEqual(IrSequence irSequence)
irSequence
- to be compared against this.public boolean isEqual(IrSequence irSequence, double absoluteTolerance, double relativeTolerance)
irSequence
- to be compared against this.absoluteTolerance
- tolerance threshold in microseconds.relativeTolerance
- relative threshold, between 0 and 1.public boolean isEqual(int beginning, int compareStart, int length, double absoluteTolerance, double relativeTolerance, double lastLimit)
beginning
- start of first subsequencecompareStart
- start of second subsequencelength
- length to be comparedabsoluteTolerance
- tolerance threshold in microseconds.relativeTolerance
- relative threshold, between 0 and 1.lastLimit
- public boolean isEqual(int beginning, int compareStart, int length, double absoluteTolerance, double relativeTolerance)
beginning
- start of first subsequencecompareStart
- start of second subsequencelength
- length to be comparedabsoluteTolerance
- tolerance threshold in microseconds.relativeTolerance
- relative threshold, between 0 and 1.public final int getLength()
public double getGap()
public final boolean isEmpty()
public final boolean containsZeros()
public final boolean replaceZeros(double replacement)
replacement
- Duration in micro seconds to replace zero durations with.public final int getNumberBursts()
public double getDuration()
public double getDuration(int begin, int length)
begin
- start of subsequence.length
- length of subsequence.public String toPrintString(boolean alternatingSigns, boolean noSigns, String separator)
alternatingSigns
- if true, generate alternating signs (ignoring original signs).noSigns
- remove all signs.separator
- public String toPrintString(boolean alternatingSigns, boolean noSigns)
alternatingSigns
- if true, generate alternating signs (ignoring original signs), otherwise preserve signs.noSigns
- public String toPrintString(boolean alternatingSigns)
alternatingSigns
- if true, generate alternating signs (ignoring original signs), otherwise preserve signs.public String toPrintString()
public String toString()
public String toString(boolean alternatingSigns)
alternatingSigns
- if true, generate alternating signs, otherwise remove signs.public static void main(String[] args)
args
- the command line argumentsCopyright © 2016. All rights reserved.