Class EightSVXAudioClip

java.lang.Object
org.monte.media.eightsvx.EightSVXAudioClip
All Implemented Interfaces:
AudioClip, LoopableAudioClip

public class EightSVXAudioClip extends Object implements LoopableAudioClip
Represents an audio sample of type IFF 8SVX.

Supported audio formats:
8 bit linear and fibonacci encoded data samples.
All sample rates
Stereo and Mono

Unsupported features:
Attack and Release information is ignored.
Multi octave samples are not handled.

Known Issues
This class has been implemented with JDK 1.1 in mind. JDK 1.1 does not have a public API for Sound. This class will thus work only on a small number of Java VMS.
Poor sound qualitiy: All data is being converted to U-Law 8000 Hertz, since this is the only kind of audio data that JDK 1.1 supports (As far as I know).
Stereo sound is converted to mono. As far as I know there is now stereo support built in JDK 1.1.

Author:
Werner Randelshofer, Hausmatt 10, CH-6405 Goldau, Switzerland
  • Field Details

  • Constructor Details

    • EightSVXAudioClip

      public EightSVXAudioClip()
  • Method Details

    • setName

      protected void setName(String value)
    • getName

      public String getName()
    • setAuthor

      protected void setAuthor(String value)
    • getAuthor

      protected String getAuthor()
    • setCopyright

      protected void setCopyright(String value)
    • getCopyright

      protected String getCopyright()
    • setRemark

      protected void setRemark(String value)
    • getRemark

      protected String getRemark()
    • set8SVXBody

      public void set8SVXBody(byte[] value)
    • get8SVXBody

      public byte[] get8SVXBody()
    • setOneShotHiSamples

      public void setOneShotHiSamples(long value)
    • setRepeatHiSamples

      public void setRepeatHiSamples(long value)
    • setSamplesPerHiCycle

      public void setSamplesPerHiCycle(long value)
    • setSampleType

      public void setSampleType(int value)
    • setSampleRate

      public void setSampleRate(int value)
    • setCtOctave

      public void setCtOctave(int value)
    • setSCompression

      public void setSCompression(int value)
    • setVolume

      public void setVolume(int value)
    • getOneShotHiSamples

      public long getOneShotHiSamples()
    • getRepeatHiSamples

      public long getRepeatHiSamples()
    • getSamplesPerHiCycle

      public long getSamplesPerHiCycle()
    • getSampleType

      public long getSampleType()
    • getSampleRate

      public int getSampleRate()
    • getCtOctave

      public int getCtOctave()
    • getVolume

      public int getVolume()
    • getSCompression

      public int getSCompression()
    • toString

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

      public LoopableAudioClip createAudioClip()
    • createAudioClip

      public LoopableAudioClip createAudioClip(int sampleRate, int volume, float pan)
    • to8BitLinearPcm

      public byte[] to8BitLinearPcm()
      Gets the audio data in 8-bit linear PCM.
      Returns:
      the audio data as 8-bit linear PCM
    • createJDK13AudioClip

      public LoopableAudioClip createJDK13AudioClip(int sampleRate, int volume, float pan)
    • play

      public void play()
      Description copied from interface: AudioClip
      Starts playing this audio clip. Each time this method is called, the clip is restarted from the beginning.
      Specified by:
      play in interface AudioClip
    • loop

      public void loop()
      Description copied from interface: AudioClip
      Starts playing this audio clip in a loop.
      Specified by:
      loop in interface AudioClip
    • stop

      public void stop()
      Description copied from interface: AudioClip
      Stops playing this audio clip.
      Specified by:
      stop in interface AudioClip
    • prepare

      public void prepare()
      Make this clip ready for playback.
    • computeStereoVolumeCorrection

      public static double computeStereoVolumeCorrection(byte[] stereo)
      This finds the volume correction needed when converting this stereo sample to mono.
      Parameters:
      stereo - Stereo data linear 8. The first half of the array contains the sound for the left speaker, the second half the sound for the right speaker.
      Returns:
      volumeCorrection Combining the two channels into one increases the sound volume. This can exceed the maximum volume that can be represented by the linear8 sample model. To avoid this, the volume must be corrected to fit into the sample model.
    • linear8StereoToMono

      public static byte[] linear8StereoToMono(byte[] stereo, double volumeCorrection)
      This converts a stereo sample to mono.
      Parameters:
      stereo - Stereo data linear 8. The first half of the array contains the sound for the left speaker, the second half the sound for the right speaker.
      volumeCorrection - Combining the two channels into one increases the sound volume. This can exceed the maximum volume that can be represented by the linear8 sample model. To avoid this, the volume must be corrected to fit into the sample model.
    • resample

      public static byte[] resample(byte[] input, int inputSampleRate, int outputSampleRate)
      Resamples audio data to match the given sample rate and applies a lowpass filter if necessary.
      Parameters:
      input - Linear8 encoded audio data.
      inputSampleRate - The sample rate of the input data
      outputSampleRate - The sample rate of the output data.
      Returns:
      Linear8 encoded audio data.
    • linear8ToULaw

      public static byte[] linear8ToULaw(byte[] linear8)
      Converts a buffer of signed 8bit samples to uLaw. The uLaw bytes overwrite the original 8 bit values. The first byte-offset of the uLaw bytes is byteOffset. It will be written sampleCount bytes.
    • linear16ToULaw

      public static byte[] linear16ToULaw(int[] linear16)
      Converts a buffer of signed 8bit samples to uLaw. The uLaw bytes overwrite the original 8 bit values. The first byte-offset of the uLaw bytes is byteOffset. It will be written sampleCount bytes.
    • unpackFibonacciDeltaCompression

      public static byte[] unpackFibonacciDeltaCompression(byte[] source)
      Unpack Fibonacci-delta encoded data from n byte source buffer into 2*(n-2) byte dest buffer. Source buffer has a pad byte, an 8-bit initial value, followed by n bytes comprising 2*(n) 4-bit encoded samples.
    • writeSunAudioHeader

      public static void writeSunAudioHeader(OutputStream outfile, int dataSize, int sampleRate, int sampleType) throws IOException
      Write a "standard" sun header.
      Parameters:
      sampleType - Specify STEREO, LEFT or RIGHT.
      Throws:
      IOException
    • wrulong

      public static void wrulong(OutputStream outfile, int ulong) throws IOException
      Write an unsigned long (Motorola 68000 CPU format).
      Throws:
      IOException
    • loop

      public void loop(int count)
      Starts looping playback from the current position. Playback will continue to the loop's end point, then loop back to the loop start point count times, and finally continue playback to the end of the clip.

      If the current position when this method is invoked is greater than the loop end point, playback simply continues to the end of the clip without looping.

      A count value of 0 indicates that any current looping should cease and playback should continue to the end of the clip. The behavior is undefined when this method is invoked with any other value during a loop operation.

      If playback is stopped during looping, the current loop status is cleared; the behavior of subsequent loop and start requests is not affected by an interrupted loop operation.

      Specified by:
      loop in interface LoopableAudioClip
      Parameters:
      count - the number of times playback should loop back from the loop's end position to the loop's start position, or LoopableAudioClip.LOOP_CONTINUOUSLY to indicate that looping should continue until interrupted