Package org.harctoolbox.ircore
Class IrSignal
java.lang.Object
org.harctoolbox.ircore.IrSignal
- All Implemented Interfaces:
Serializable
,Cloneable
This class models a numerical IR signals.
It consists of a frequency, a duty cycle, and an intro sequence,
a repeat sequence, and an ending sequence. Any of the latter three,
but not all, can be empty, but not null. If the ending sequence is non-empty,
the repeat sequence has to be non-empty too.
The "count" semantic: The "count" argument in functions like toModulatedIrSequece(int count) is interpreted like this: If the intro sequence is null, then "count" copies or the repeat sequence are used, otherwise count-1. It is believed that this interpretation is consistent with the heuristic meaning of 'sending a signal "count" times'.
The "repetitions" semantic: "repetition" number of copies of the repeat sequence are used.
This class is immutable.
- See Also:
-
Nested Class Summary
-
Field Summary
-
Constructor Summary
ConstructorDescriptionIrSignal()
Constructs an IrSignal of zero length.IrSignal
(int[] durations, int noIntro, int noRepeat, double frequency) Constructs an IrSignal from its arguments.Constructs an IrSignal from its arguments.IrSignal
(String introSequence, String repeatSequence, String endingSequence, Double frequency, Double dutyCycle) Constructs an IrSignal from its arguments.IrSignal
(IrSequence irSequence, int noIntro, int noRepeat, Double frequency, Double dutyCycle) IrSignal
(IrSequence introSequence, Double frequency, Double dutyCycle) Constructs an IrSignal from its arguments.IrSignal
(IrSequence introSequence, IrSequence repeatSequence, IrSequence endingSequence, Double frequency) Constructs an IrSignal from its arguments.IrSignal
(IrSequence introSequence, IrSequence repeatSequence, IrSequence endingSequence, Double frequency, Double dutyCycle) Constructs an IrSignal from its arguments.IrSignal
(ModulatedIrSequence introSequence) Convenience constructor for IrSignals having only an intro sequence.IrSignal
(ModulatedIrSequence sequence, int beginningLength, int repeatLength, int noRepeats) Constructs an IrSignal. -
Method Summary
Modifier and TypeMethodDescriptionboolean
approximatelyEquals
(IrSignal irSignal) Compares two ModulatedIrSequences for (approximate) equality.boolean
approximatelyEquals
(IrSignal irSignal, double absoluteTolerance, double relativeTolerance, double frequencyTolerance) Compares two ModulatedIrSequences for (approximate) equality.clone()
boolean
Returns true if and only if the sequence contains durations of zero length.double
getDouble
(IrSignal.Pass pass, int i) double
getDuration
(int count) Computes the duration in microseconds of the intro sequence, repetitions repeats of the repeat sequence, plus the ending sequence.double
getEndingDouble
(int i) int[]
int
int[]
Returns the data in the intro sequence, as a sequence of pulses in the used frequency.double
getGap()
Returns max gap of intro- and repeat sequences.double
getIntroDouble
(int i) Returns the i'th data in the intro sequence, as double.int[]
Returns the data in the intro sequence, as a sequence of microsecond durations.int
Returns length of Intro sequence, in number of flashes and gaps.int[]
Returns the data in the intro sequence, as a sequence of pulses in the used frequency.int
getLength
(IrSignal.Pass pass) double
getRepeatDouble
(int i) int[]
int
int[]
Returns the data in the intro sequence, as a sequence of pulses in the used frequency.double
Computes the duration in microseconds of the intro sequence, one repeat sequence, plus the ending sequence.boolean
boolean
isEmpty()
boolean
int
repeatsPerCountSemantic
(int count) Returns the number of repetitions according to the count semantics.void
replaceZeros
(double replacement) Replace all zero durations.void
replaceZeros
(int replacement) Replace all zero durations.int[]
toIntArray
(int i) Returns a ModulatedIrSequence consisting of one intro sequence, one repeat sequence, followed by one ending sequence.toModulatedIrSequence
(boolean intro, int repetitions, boolean ending) Returns a ModulatedIrSequence consisting of zero or one intro sequence, repetition number of repeat sequence, and zero or one ending sequence.toModulatedIrSequence
(int count) Returns a ModulatedIrSequence consisting of one intro sequence, count or count-1 number of repeat sequence, dependent on if intro is empty or not, followed by one ending sequence.toOneShot
(int count) Returns an IrSignal consisting of count repetitions (count semantic) as the intro sequence, while repeat and ending are empty.toString()
toString
(boolean alternatingSigns) Generates nice string.
-
Field Details
-
EMPTY
-
-
Constructor Details
-
IrSignal
public IrSignal(IrSequence introSequence, IrSequence repeatSequence, IrSequence endingSequence, Double frequency, Double dutyCycle) Constructs an IrSignal from its arguments.- Parameters:
frequency
-dutyCycle
-introSequence
-repeatSequence
-endingSequence
-
-
IrSignal
public IrSignal(String introSequence, String repeatSequence, String endingSequence, Double frequency, Double dutyCycle) throws OddSequenceLengthException Constructs an IrSignal from its arguments.- Parameters:
frequency
-dutyCycle
-introSequence
-repeatSequence
-endingSequence
-- Throws:
OddSequenceLengthException
-
IrSignal
Constructs an IrSignal from its arguments. The single sequence is made intro sequence.- Parameters:
introSequence
-frequency
-dutyCycle
-
-
IrSignal
public IrSignal(IrSequence introSequence, IrSequence repeatSequence, IrSequence endingSequence, Double frequency) Constructs an IrSignal from its arguments.- Parameters:
frequency
-introSequence
-repeatSequence
-endingSequence
-
-
IrSignal
Convenience constructor for IrSignals having only an intro sequence.- Parameters:
introSequence
-
-
IrSignal
public IrSignal(ModulatedIrSequence sequence, int beginningLength, int repeatLength, int noRepeats) throws InvalidArgumentException Constructs an IrSignal.- Parameters:
sequence
-beginningLength
- Length of the intro sequencerepeatLength
- Length of the repeat sequencenoRepeats
- Number of occurrences of the repeat sequence- Throws:
InvalidArgumentException
-
IrSignal
public IrSignal(int[] durations, int noIntro, int noRepeat, double frequency) throws InvalidArgumentException Constructs an IrSignal from its arguments.- Parameters:
durations
-noIntro
-noRepeat
-frequency
-- Throws:
InvalidArgumentException
-
IrSignal
public IrSignal(int[] durations, int noIntro, int noRepeat, Double frequency, Double dutyCycle) throws InvalidArgumentException Constructs an IrSignal from its arguments. The first noIntro durations belong to the Intro signal, the next noRepeat to the repetition part, and the remaining to the ending sequence.- Parameters:
durations
- Integer array of durations. Signs of the entries are ignored,noIntro
- Number of entries belonging to the intro sequence.noRepeat
- Number of entries belonging to the repeat sequence.frequency
- Modulation frequency in Hz. Use null for defaultdutyCycle
- Duty cycle of modulation pulse, between 0 and 1. Use null for not specified.- Throws:
InvalidArgumentException
-
IrSignal
public IrSignal(IrSequence irSequence, int noIntro, int noRepeat, Double frequency, Double dutyCycle) throws InvalidArgumentException - Throws:
InvalidArgumentException
-
IrSignal
public IrSignal()Constructs an IrSignal of zero length. -
IrSignal
-
-
Method Details
-
getFrequency
-
getFrequencyWithDefault
-
getDutyCycle
-
clone
-
getIntroLength
public int getIntroLength()Returns length of Intro sequence, in number of flashes and gaps.- Returns:
- length of intro
- See Also:
-
getIntroInts
public int[] getIntroInts()Returns the data in the intro sequence, as a sequence of microsecond durations.- Returns:
- integer sequence of durations in microseconds, possibly with sign.
- See Also:
-
getIntroDouble
public double getIntroDouble(int i) Returns the i'th data in the intro sequence, as double.- Parameters:
i
- index- Returns:
- duration, possibly with sign.
- See Also:
-
getIntroPulses
public int[] getIntroPulses()Returns the data in the intro sequence, as a sequence of pulses in the used frequency.- Returns:
- integer array of pulses
- See Also:
-
getRepeatLength
public int getRepeatLength() -
getRepeatInts
public int[] getRepeatInts() -
getRepeatDouble
public double getRepeatDouble(int i) -
getRepeatPulses
public int[] getRepeatPulses()Returns the data in the intro sequence, as a sequence of pulses in the used frequency.- Returns:
- integer array of pulses
- See Also:
-
getEndingLength
public int getEndingLength() -
getEndingInts
public int[] getEndingInts() -
getEndingDouble
public double getEndingDouble(int i) -
getEndingPulses
public int[] getEndingPulses()Returns the data in the intro sequence, as a sequence of pulses in the used frequency.- Returns:
- integer array of pulses
- See Also:
-
getTotalDuration
public double getTotalDuration()Computes the duration in microseconds of the intro sequence, one repeat sequence, plus the ending sequence.- Returns:
- duration in microseconds.
-
getDuration
public double getDuration(int count) Computes the duration in microseconds of the intro sequence, repetitions repeats of the repeat sequence, plus the ending sequence. Uses the count semantic.- Parameters:
count
- Uses count semantic.- Returns:
- duration in microseconds.
-
getDouble
-
getLength
-
introOnly
public boolean introOnly() -
repeatOnly
public boolean repeatOnly() -
toString
-
toString
Generates nice string. Generate alternating signs according to the parameter.- Parameters:
alternatingSigns
- if true generate alternating signs, otherwise remove signs.- Returns:
- nice string.
-
getFrequencyAsString
-
repeatsPerCountSemantic
public int repeatsPerCountSemantic(int count) Returns the number of repetitions according to the count semantics.- Parameters:
count
-- Returns:
- introSequence.isEmpty() ? count : count - 1
-
isEmpty
public boolean isEmpty()- Returns:
- Emptyness of the signal.
-
containsZeros
public boolean containsZeros()Returns true if and only if the sequence contains durations of zero length.- Returns:
- existence of zero durations.
-
replaceZeros
public void replaceZeros(double replacement) Replace all zero durations. Changes the signal in-place.- Parameters:
replacement
- Duration in micro seconds to replace zero durations with.
-
replaceZeros
public void replaceZeros(int replacement) Replace all zero durations. Changes the signal in-place.- Parameters:
replacement
- Duration in pulses to replace zero durations with. If frequency == 0, interpret as microseconds instead.
-
getGap
public double getGap()Returns max gap of intro- and repeat sequences.- Returns:
- max gap of intro- and repeat sequences.
-
toModulatedIrSequence
Returns a ModulatedIrSequence consisting of one intro sequence, one repeat sequence, followed by one ending sequence.- Returns:
- ModulatedIrSequence.
-
toModulatedIrSequence
Returns a ModulatedIrSequence consisting of one intro sequence, count or count-1 number of repeat sequence, dependent on if intro is empty or not, followed by one ending sequence.- Parameters:
count
- Number of times to send signal. Must be > 0.- Returns:
- ModulatedIrSequence.
-
toModulatedIrSequence
Returns a ModulatedIrSequence consisting of zero or one intro sequence, repetition number of repeat sequence, and zero or one ending sequence.- Parameters:
intro
- inclusion of intro sequence?repetitions
- number of repetitions (repeat semantic)ending
- inclusion of ending sequence.- Returns:
- ModulatedIrSequence.
-
toIrSequences
-
toOneShot
Returns an IrSignal consisting of count repetitions (count semantic) as the intro sequence, while repeat and ending are empty.- Parameters:
count
- Number of times to send signal. Must be > 0.- Returns:
- IrSignal consisting of count repetitions (count semantic) as the intro sequence.
-
approximatelyEquals
public boolean approximatelyEquals(IrSignal irSignal, double absoluteTolerance, double relativeTolerance, double frequencyTolerance) Compares two ModulatedIrSequences for (approximate) equality.- Parameters:
irSignal
- to be compared against this.absoluteTolerance
- tolerance threshold in microseconds.relativeTolerance
- relative threshold, between 0 and 1.frequencyTolerance
- tolerance (absolute) for frequency in Hz.- Returns:
- equality within tolerance.
-
approximatelyEquals
Compares two ModulatedIrSequences for (approximate) equality.- Parameters:
irSignal
- to be compared against this.- Returns:
- equality within tolerance.
-
getIntroSequence
- Returns:
- the intro sequence, as ModulatedIrSequence
-
getRepeatSequence
- Returns:
- the repeat sequence, as ModulatedIrSequence
-
getEndingSequence
- Returns:
- the ending sequence, as ModulatedIrSequence
-
toIntArray
public int[] toIntArray(int i)
-