Overview | Package | Class | Use | Tree | Serialized | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## tapeutils
Class Sample

    java.lang.Object
      tapeutils.Sample

All Implemented Interfaces:
  java.lang.Runnable

public class Sample
extends java.lang.Object
implements java.lang.Runnable

This class provides the representation of a sampled sound.

Author:
  hldswrth

Constructor Summary
`Sample(javax.sound.sampled.AudioInputStream input, boolean invert, int channel)` Construct the sample from a file.

Method Summary
`void` | `endModification()` End a modification.
`javax.sound.sampled.AudioFormat` | `getAudioFormat()` Get the audio format for this sample.
`int` | `getBytesPerSample()` Get the number of bytes per sample.
`int` | `getRange()` Get the possible range of values for this sample.
`double` | `getRateMultiplier()` Get the sample rate multiplier.
`double` | `getSamplesPerSecond()` Return the number of samples per second.
`int` | `getSampleValue(int index)` Get the sample value at the given position.
`int` | `numSamples()` Get the number of samples.
`void` | `play(int index, boolean newThread)` Play the sample.
`int` | `redo()` Redo a modification.
`void` | `run()` Play the sample.
`void` | `save(java.io.OutputStream out)` Save the sample data to the given output stream.
`void` | `setChannel(int channel)` Set the selected channel.
`void` | `setInvert(boolean invert)` Set the inversion.
`void` | `setSampleValue(int index, int value)` Set the sample value at the given position.
`void` | `startModification(int index, int length)` Start a modification.
`void` | `stopPlaying()` Stop playing the sample.
`int` | `undo()` Undo a modification.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### Sample

    public Sample(javax.sound.sampled.AudioInputStream input,
                  boolean invert,
                  int channel)
           throws java.io.IOException

  Construct the sample from a file.

  A particular channel must be selected.

  The data within the sample can be inverted.

Parameters:
  `input` - The audio input stream.
  `invert` - Indicates whether to invert values.
  `channel` - The selected channel.
Throws:
  `java.io.IOException` - An error occurred reading the stream.

Method Detail

### getSampleValue

    public int getSampleValue(int index)

  Get the sample value at the given position.

  Parameters:
    `index` - The index of the sample.
  Returns:
    The sample value.

### setSampleValue

    public void setSampleValue(int index,
                               int value)

  Set the sample value at the given position.

  Parameters:
    `index` - The index of the sample.
    `value` - The value of the sample.

### numSamples

    public int numSamples()

  Get the number of samples.

  Returns:
    The number of samples.

### getBytesPerSample

    public int getBytesPerSample()

  Get the number of bytes per sample.

  Returns:
    The number of bytes per sample.

### getRange

    public int getRange()

  Get the possible range of values for this sample.

  Returns:
    The possible range.

### getAudioFormat

    public javax.sound.sampled.AudioFormat getAudioFormat()

  Get the audio format for this sample.

  Returns:
    The audio format.

### getRateMultiplier

    public double getRateMultiplier()

  Get the sample rate multiplier.

  This is used to restore wavelength information back to the default sample rate.

  Returns:
    The sample rate multiplier.

### getSamplesPerSecond

    public double getSamplesPerSecond()

  Return the number of samples per second.

  Returns:
    The number of samples per second.

### save

    public void save(java.io.OutputStream out)
              throws java.io.IOException

  Save the sample data to the given output stream.

  Parameters:
    `out` - THe output stream.
  Throws:
    `java.io.IOException`

### play

    public void play(int index,
                     boolean newThread)
              throws javax.sound.sampled.LineUnavailableException

  Play the sample.

  Parameters:
    `index` - The starting index.
    `newThread` - Indicates whether to start playing on a new thread.
  Throws:
    `javax.sound.sampled.LineUnavailableException`

### run

    public void run()

  Play the sample.

  Specified by:
    `run` in interface `java.lang.Runnable`

### stopPlaying

    public void stopPlaying()

  Stop playing the sample.

### startModification

    public void startModification(int index,
                                  int length)

  Start a modification.

  Parameters:
    `index` -
    `length` -

### endModification

    public void endModification()

  End a modification.

### undo

    public int undo()

  Undo a modification.

  Returns:
    The index of the modification.

### redo

    public int redo()

  Redo a modification.

  Returns:
    The index of the modification.

### setChannel

    public void setChannel(int channel)

  Set the selected channel.

  Parameters:
    `channel` - The new value.

### setInvert

    public void setInvert(boolean invert)

  Set the inversion.

  Parameters:
    `invert` - The new value.

Overview | Package | Class | Use | Tree | Serialized | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD