Module org.refcodes.audio
Package org.refcodes.audio
Class AbstractWavSampleWriter<S extends SoundSample,B extends WavSampleWriter<S,B>>
- java.lang.Object
-
- org.refcodes.audio.AbstractWavSampleWriter<S,B>
-
- Type Parameters:
S- TheSoundSample(sub-)type on which theSampleWriterimplementation is to operate on.B- TheWavSampleWriterimplementing thisAbstractWavSampleWriter.
- All Implemented Interfaces:
AutoCloseable,BitsPerSampleAccessor,BitsPerSampleAccessor.BitsPerSampleBuilder<B>,BitsPerSampleAccessor.BitsPerSampleMutator,BitsPerSampleAccessor.BitsPerSampleProperty,SampleWriter<S,B>,SamplingRateAccessor,SamplingRateAccessor.SamplingRateBuilder<B>,SamplingRateAccessor.SamplingRateMutator,SamplingRateAccessor.SamplingRateProperty,WavSampleWriter<S,B>,org.refcodes.io.RowWriter<S>
- Direct Known Subclasses:
WavMonoSampleWriter,WavSoundSampleWriter
public abstract class AbstractWavSampleWriter<S extends SoundSample,B extends WavSampleWriter<S,B>> extends Object implements WavSampleWriter<S,B>
TheAbstractWavSampleWriterprovides a foundation means to write sound samples to a WAV file. Information on the WAV file format has been taken from the following article: "https://web.archive.org/web/20120113025807/http://technology.niagarac.on.ca:80/courses/ctec1631/WavFileFormat.html".
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.refcodes.audio.BitsPerSampleAccessor
BitsPerSampleAccessor.BitsPerSampleBuilder<B extends BitsPerSampleAccessor.BitsPerSampleBuilder<B>>, BitsPerSampleAccessor.BitsPerSampleMutator, BitsPerSampleAccessor.BitsPerSampleProperty
-
Nested classes/interfaces inherited from interface org.refcodes.audio.SamplingRateAccessor
SamplingRateAccessor.SamplingRateBuilder<B extends SamplingRateAccessor.SamplingRateBuilder<B>>, SamplingRateAccessor.SamplingRateMutator, SamplingRateAccessor.SamplingRateProperty
-
-
Field Summary
Fields Modifier and Type Field Description protected BitsPerSample_bitsPerSampleprotected File_fileprotected BufferedOutputStream_outputStreamstatic StringDATAstatic StringFORMATprotected static longMAX_16_BITprotected static longMAX_8_BITstatic StringRIFFstatic StringWAVE
-
Constructor Summary
Constructors Constructor Description AbstractWavSampleWriter(File aFile)Constructs theAbstractWavSampleWriterfor writing sound samples to a WAV file or stream.AbstractWavSampleWriter(OutputStream aOutputStream)Constructs theAbstractWavSampleWriterfor writing sound samples to a WAV file or stream.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()BitsPerSamplegetBitsPerSample()Retrieves the bits/sample per channel from the bits/sample per channel property.voidsetBitsPerSample(BitsPerSample aBitsPerSample)Sets the bits/sample per channel for the bits/sample per channel property.protected longtoWavSample(double eSampleData)protected voidwriteHeader(int aSamplingRate, int aChannelNumber)-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.refcodes.audio.BitsPerSampleAccessor.BitsPerSampleBuilder
withBitsPerSample
-
Methods inherited from interface org.refcodes.audio.BitsPerSampleAccessor.BitsPerSampleProperty
letBitsPerSample
-
Methods inherited from interface org.refcodes.audio.SampleWriter
writeNext
-
Methods inherited from interface org.refcodes.audio.SamplingRateAccessor
getSamplingRate
-
Methods inherited from interface org.refcodes.audio.SamplingRateAccessor.SamplingRateBuilder
withSamplingRate
-
Methods inherited from interface org.refcodes.audio.SamplingRateAccessor.SamplingRateMutator
setSamplingRate
-
Methods inherited from interface org.refcodes.audio.SamplingRateAccessor.SamplingRateProperty
letSamplingRate
-
-
-
-
Field Detail
-
RIFF
public static String RIFF
-
WAVE
public static String WAVE
-
FORMAT
public static String FORMAT
-
DATA
public static String DATA
-
MAX_16_BIT
protected static final long MAX_16_BIT
- See Also:
- Constant Field Values
-
MAX_8_BIT
protected static final long MAX_8_BIT
- See Also:
- Constant Field Values
-
_outputStream
protected BufferedOutputStream _outputStream
-
_file
protected File _file
-
_bitsPerSample
protected BitsPerSample _bitsPerSample
-
-
Constructor Detail
-
AbstractWavSampleWriter
public AbstractWavSampleWriter(File aFile) throws FileNotFoundException
Constructs theAbstractWavSampleWriterfor writing sound samples to a WAV file or stream.- Parameters:
aFile- TheFilewhere to write the CSV records to.- Throws:
FileNotFoundException- If the given file object does not denote an existing, writable regular file and a new regular file of that name cannot be created, or if some other error occurs while opening or creating the file.
-
AbstractWavSampleWriter
public AbstractWavSampleWriter(OutputStream aOutputStream)
Constructs theAbstractWavSampleWriterfor writing sound samples to a WAV file or stream.- Parameters:
aOutputStream- TheOutputStreamwhere to write the CSV records to.
-
-
Method Detail
-
setBitsPerSample
public void setBitsPerSample(BitsPerSample aBitsPerSample)
Sets the bits/sample per channel for the bits/sample per channel property.- Specified by:
setBitsPerSamplein interfaceBitsPerSampleAccessor.BitsPerSampleMutator- Parameters:
aBitsPerSample- The bits/sample per channel to be stored by the sampling rate property.
-
getBitsPerSample
public BitsPerSample getBitsPerSample()
Retrieves the bits/sample per channel from the bits/sample per channel property.- Specified by:
getBitsPerSamplein interfaceBitsPerSampleAccessor- Returns:
- The bits/sample per channel stored by the bits/sample per channel property.
-
close
public void close() throws IOException- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceSampleWriter<S extends SoundSample,B extends WavSampleWriter<S,B>>- Throws:
IOException
-
toWavSample
protected long toWavSample(double eSampleData)
-
writeHeader
protected void writeHeader(int aSamplingRate, int aChannelNumber) throws IOException- Throws:
IOException
-
-