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.
|
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 |
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(IrSequence irSequence)
Compares two IrSequences for equality.
|
boolean |
isEqual(IrSequence irSequence,
double tolerance)
Compares two IrSequences for 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.
|
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.
|
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) throws IncompatibleArgumentException
str
- String of durations, possibly using signed numbers.IncompatibleArgumentException
- If last duration is not a gap.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 double get(int i)
i
- indexpublic int iget(int i)
i
- indexpublic int[] toInts()
public int[] toInts(boolean alternatingSigns)
alternatingSigns
- if true, all the durations with odd index are negative, otherwise, all are positive.public double[] toDoubles()
public 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[] 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 tolerance)
irSequence
- to be compared against this.tolerance
- tolerance threshold in microseconds.public int getLength()
public double getGap()
public boolean isEmpty()
public boolean containsZeros()
public boolean replaceZeros(double replacement)
replacement
- Duration in micro seconds to replace zero durations with.public int getNumberBursts()
public double getDuration()
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 © 2015. All rights reserved.