Class IrSignal

java.lang.Object
org.harctoolbox.ircore.IrSignal
All Implemented Interfaces:
Serializable, Cloneable

public final class IrSignal extends Object implements Cloneable, Serializable
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:
  • Field Details

    • EMPTY

      public static final IrSignal 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

      public IrSignal(IrSequence introSequence, Double frequency, Double dutyCycle)
      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

      public IrSignal(ModulatedIrSequence introSequence)
      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 sequence
      repeatLength - Length of the repeat sequence
      noRepeats - 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 default
      dutyCycle - 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

      public IrSignal(IrSignal irSignal, Double newFrequency)
  • Method Details

    • getFrequency

      public Double getFrequency()
    • getFrequencyWithDefault

      public Double getFrequencyWithDefault()
    • getDutyCycle

      public Double getDutyCycle()
    • clone

      public IrSignal clone()
      Overrides:
      clone in class Object
    • 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

      public double getDouble(IrSignal.Pass pass, int i)
    • getLength

      public int getLength(IrSignal.Pass pass)
    • introOnly

      public boolean introOnly()
    • repeatOnly

      public boolean repeatOnly()
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • toString

      public String toString(boolean alternatingSigns)
      Generates nice string. Generate alternating signs according to the parameter.
      Parameters:
      alternatingSigns - if true generate alternating signs, otherwise remove signs.
      Returns:
      nice string.
    • getFrequencyAsString

      public 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

      public ModulatedIrSequence toModulatedIrSequence()
      Returns a ModulatedIrSequence consisting of one intro sequence, one repeat sequence, followed by one ending sequence.
      Returns:
      ModulatedIrSequence.
    • toModulatedIrSequence

      public ModulatedIrSequence 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.
      Parameters:
      count - Number of times to send signal. Must be > 0.
      Returns:
      ModulatedIrSequence.
    • toModulatedIrSequence

      public ModulatedIrSequence 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.
      Parameters:
      intro - inclusion of intro sequence?
      repetitions - number of repetitions (repeat semantic)
      ending - inclusion of ending sequence.
      Returns:
      ModulatedIrSequence.
    • toIrSequences

      public List<IrSequence> toIrSequences()
    • toOneShot

      public IrSignal toOneShot(int count)
      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

      public boolean approximatelyEquals(IrSignal irSignal)
      Compares two ModulatedIrSequences for (approximate) equality.
      Parameters:
      irSignal - to be compared against this.
      Returns:
      equality within tolerance.
    • getIntroSequence

      public ModulatedIrSequence getIntroSequence()
      Returns:
      the intro sequence, as ModulatedIrSequence
    • getRepeatSequence

      public ModulatedIrSequence getRepeatSequence()
      Returns:
      the repeat sequence, as ModulatedIrSequence
    • getEndingSequence

      public ModulatedIrSequence getEndingSequence()
      Returns:
      the ending sequence, as ModulatedIrSequence
    • toIntArray

      public int[] toIntArray(int i)