Class Wave

java.lang.Object
org.harctoolbox.harchardware.ir.Wave

public class Wave extends Object
This class generates (or analyzes) a wave audio file that can be played on standard audio equipment and fed to a pair of anti-parallel double IR sending diodes, which can thus control IR equipment.
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
    Wave(double freq, double[] data, int sampleFrequency, int sampleSize, int channels, boolean bigEndian, boolean omitTail, boolean square, boolean divide)
    Generates a wave audio file from its arguments.
    Wave(File file)
    Reads a wave file into a Wave object.
    Wave(org.harctoolbox.ircore.ModulatedIrSequence irSequence, int sampleFrequency, int sampleSize, int channels, boolean bigEndian, boolean omitTail, boolean square, boolean divide)
    Generates a wave audio file from its arguments.
    Wave(org.harctoolbox.ircore.ModulatedIrSequence irSequence, AudioFormat audioFormat, boolean omitTail, boolean square, boolean divide)
    Generates a wave audio file from its arguments.
  • Method Summary

    Modifier and Type
    Method
    Description
    org.harctoolbox.ircore.ModulatedIrSequence
    analyze(PrintStream stream, boolean divide)
    Analyzes the data and computes a ModulatedIrSequence.
    void
    dump(File dumpfile)
    Print the channels to a tab separated text file, for example for debugging purposes.
    void
    export(File file)
    Write the signal to the file given as argument.
    getLine(AudioFormat audioFormat)
    Returns a line to the audio mixer on the local machine, suitable for sound with the parameter values given.
    static void
    main(String[] args)
    Provides a command line interface to the export/import functions.
    void
    Sends the generated wave to the local machine's audio system, if possible.
    void
    Sends the generated wave to the line in argument, if possible.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Wave

      public Wave(File file) throws UnsupportedAudioFileException, IOException
      Reads a wave file into a Wave object.
      Parameters:
      file - Wave file as input.
      Throws:
      UnsupportedAudioFileException
      IOException
    • Wave

      public Wave(double freq, double[] data, int sampleFrequency, int sampleSize, int channels, boolean bigEndian, boolean omitTail, boolean square, boolean divide) throws org.harctoolbox.ircore.InvalidArgumentException
      Generates a wave audio file from its arguments.
      Parameters:
      freq - Carrier frequency in Hz.
      data - double array of durations in micro seconds.
      sampleFrequency - Sample frequency of the generated wave file.
      sampleSize - Sample size (8 or 16) in bits of the samples.
      channels - If == 2, generates two channels in perfect anti-phase.
      bigEndian - if true, use bigendian byte order for 16 bit samples.
      omitTail - If true, the last trailing gap will be omitted.
      square - if true, use a square wave for modulation, otherwise a sine.
      divide - If true, divides the carrier frequency by 2, to be used with full-wave rectifiers, e.g. a pair of IR LEDs in anti-parallel.
      Throws:
      org.harctoolbox.ircore.InvalidArgumentException
    • Wave

      public Wave(org.harctoolbox.ircore.ModulatedIrSequence irSequence, int sampleFrequency, int sampleSize, int channels, boolean bigEndian, boolean omitTail, boolean square, boolean divide) throws org.harctoolbox.ircore.InvalidArgumentException
      Generates a wave audio file from its arguments.
      Parameters:
      irSequence - ModulatedIrSequence to be used.
      sampleFrequency - Sample frequency of the generated wave file.
      sampleSize - Sample size (8 or 16) in bits of the samples.
      channels - If == 2, generates two channels in perfect anti-phase.
      bigEndian - if true, use bigendian byte order for 16 bit samples.
      omitTail - If true, the last trailing gap will be omitted.
      square - if true, use a square wave for modulation, otherwise a sine.
      divide - If true, divides the carrier frequency by 2, to be used with full-wave rectifiers, e.g. a pair of IR LEDs in anti-parallel.
      Throws:
      org.harctoolbox.ircore.InvalidArgumentException
    • Wave

      public Wave(org.harctoolbox.ircore.ModulatedIrSequence irSequence, AudioFormat audioFormat, boolean omitTail, boolean square, boolean divide) throws org.harctoolbox.ircore.InvalidArgumentException
      Generates a wave audio file from its arguments.
      Parameters:
      irSequence - ModulatedIrSequence to be used.
      audioFormat - AudioFormat bundling sampleFrequency, sample size, channels, and bigEndian together.
      omitTail - If true, the last trailing gap will be omitted.
      square - if true, use a square wave for modulation, otherwise a sine.
      divide - If true, divides the carrier frequency by 2, to be used with full-wave rectifiers, e.g. a pair of IR LEDs in anti-parallel.
      Throws:
      org.harctoolbox.ircore.InvalidArgumentException
  • Method Details

    • getLine

      public static SourceDataLine getLine(AudioFormat audioFormat) throws LineUnavailableException
      Returns a line to the audio mixer on the local machine, suitable for sound with the parameter values given. When not needed, the user should close the line with its close()-function.
      Parameters:
      audioFormat -
      Returns:
      open audio line
      Throws:
      LineUnavailableException
    • main

      public static void main(String[] args)
      Provides a command line interface to the export/import functions.
      Parameters:
      args -
    • analyze

      public org.harctoolbox.ircore.ModulatedIrSequence analyze(PrintStream stream, boolean divide)
      Analyzes the data and computes a ModulatedIrSequence. Generates some messages on stderr.
      Parameters:
      stream -
      divide - consider the carrier as having its frequency halved or not?
      Returns:
      ModulatedIrSequence computed from the data.
    • dump

      public void dump(File dumpfile) throws FileNotFoundException
      Print the channels to a tab separated text file, for example for debugging purposes. This file can be imported in a spreadsheet.
      Parameters:
      dumpfile - Output file.
      Throws:
      FileNotFoundException
    • export

      public void export(File file)
      Write the signal to the file given as argument.
      Parameters:
      file - Output File.
    • play

      public void play(SourceDataLine line) throws LineUnavailableException, IOException
      Sends the generated wave to the line in argument, if possible.
      Parameters:
      line - Line to used. Should be open, and remains open. User must make sure AudioFormat is compatible.
      Throws:
      LineUnavailableException
      IOException
    • play

      public void play() throws LineUnavailableException, IOException
      Sends the generated wave to the local machine's audio system, if possible.
      Throws:
      LineUnavailableException
      IOException