- All Implemented Interfaces:
AudioClip,LoopableAudioClip
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 Summary
FieldsModifier and TypeFieldDescriptionstatic final intstatic final intstatic final intstatic final intstatic final intFields inherited from interface org.monte.media.eightsvx.LoopableAudioClip
LOOP_CONTINUOUSLY -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic doublecomputeStereoVolumeCorrection(byte[] stereo) This finds the volume correction needed when converting this stereo sample to mono.createAudioClip(int sampleRate, int volume, float pan) createJDK13AudioClip(int sampleRate, int volume, float pan) byte[]protected Stringprotected StringintgetName()longprotected Stringlongintlonglongintintstatic byte[]linear16ToULaw(int[] linear16) Converts a buffer of signed 8bit samples to uLaw.static byte[]linear8StereoToMono(byte[] stereo, double volumeCorrection) This converts a stereo sample to mono.static byte[]linear8ToULaw(byte[] linear8) Converts a buffer of signed 8bit samples to uLaw.voidloop()Starts playing this audio clip in a loop.voidloop(int count) Starts looping playback from the current position.voidplay()Starts playing this audio clip.voidprepare()Make this clip ready for playback.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.voidset8SVXBody(byte[] value) protected voidprotected voidsetCopyright(String value) voidsetCtOctave(int value) protected voidvoidsetOneShotHiSamples(long value) protected voidvoidsetRepeatHiSamples(long value) voidsetSampleRate(int value) voidsetSamplesPerHiCycle(long value) voidsetSampleType(int value) voidsetSCompression(int value) voidsetVolume(int value) voidstop()Stops playing this audio clip.byte[]Gets the audio data in 8-bit linear PCM.toString()static byte[]unpackFibonacciDeltaCompression(byte[] source) Unpack Fibonacci-delta encoded data from n byte source buffer into 2*(n-2) byte dest buffer.static voidwriteSunAudioHeader(OutputStream outfile, int dataSize, int sampleRate, int sampleType) Write a "standard" sun header.static voidwrulong(OutputStream outfile, int ulong) Write an unsigned long (Motorola 68000 CPU format).
-
Field Details
-
S_CMP_NONE
public static final int S_CMP_NONE- See Also:
-
S_CMP_FIB_DELTA
public static final int S_CMP_FIB_DELTA- See Also:
-
RIGHT
public static final int RIGHT- See Also:
-
LEFT
public static final int LEFT- See Also:
-
STEREO
public static final int STEREO- See Also:
-
-
Constructor Details
-
EightSVXAudioClip
public EightSVXAudioClip()
-
-
Method Details
-
setName
-
getName
-
setAuthor
-
getAuthor
-
setCopyright
-
getCopyright
-
setRemark
-
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
-
createAudioClip
-
createAudioClip
-
to8BitLinearPcm
public byte[] to8BitLinearPcm()Gets the audio data in 8-bit linear PCM.- Returns:
- the audio data as 8-bit linear PCM
-
createJDK13AudioClip
-
play
public void play()Description copied from interface:AudioClipStarts playing this audio clip. Each time this method is called, the clip is restarted from the beginning. -
loop
public void loop()Description copied from interface:AudioClipStarts playing this audio clip in a loop. -
stop
public void stop()Description copied from interface:AudioClipStops playing this audio clip. -
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 dataoutputSampleRate- 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
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 pointcounttimes, 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
countvalue 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:
loopin interfaceLoopableAudioClip- Parameters:
count- the number of times playback should loop back from the loop's end position to the loop's start position, orto indicate that looping should continue until interruptedLoopableAudioClip.LOOP_CONTINUOUSLY
-