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 theSampleWriter
implementation is to operate on.B
- TheWavSampleWriter
implementing thisAbstractWavSampleWriter
.
- All Implemented Interfaces:
AutoCloseable
,BitsPerSampleAccessor
,BitsPerSampleAccessor.BitsPerSampleBuilder<S>
,BitsPerSampleAccessor.BitsPerSampleMutator
,BitsPerSampleAccessor.BitsPerSampleProperty
,SampleWriter<S,B>
,SamplingRateAccessor
,SamplingRateAccessor.SamplingRateBuilder<S>
,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>
TheAbstractWavSampleWriter
provides 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
_bitsPerSample
protected File
_file
protected BufferedOutputStream
_outputStream
static String
DATA
static String
FORMAT
protected static long
MAX_16_BIT
protected static long
MAX_8_BIT
static String
RIFF
static String
WAVE
-
Constructor Summary
Constructors Constructor Description AbstractWavSampleWriter(File aFile)
Constructs theAbstractWavSampleWriter
for writing sound samples to a WAV file or stream.AbstractWavSampleWriter(OutputStream aOutputStream)
Constructs theAbstractWavSampleWriter
for writing sound samples to a WAV file or stream.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
BitsPerSample
getBitsPerSample()
Retrieves the bits/sample per channel from the bits/sample per channel property.void
setBitsPerSample(BitsPerSample aBitsPerSample)
Sets the bits/sample per channel for the bits/sample per channel property.protected long
toWavSample(double eSampleData)
protected void
writeHeader(int aSamplingRate, int aChannelNumber)
-
Methods inherited from interface org.refcodes.audio.BitsPerSampleAccessor.BitsPerSampleBuilder
withBitsPerSample
-
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.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
-
-
-
-
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 theAbstractWavSampleWriter
for writing sound samples to a WAV file or stream.- Parameters:
aFile
- TheFile
where 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 theAbstractWavSampleWriter
for writing sound samples to a WAV file or stream.- Parameters:
aOutputStream
- TheOutputStream
where 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:
setBitsPerSample
in 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:
getBitsPerSample
in interfaceBitsPerSampleAccessor
- Returns:
- The bits/sample per channel stored by the bits/sample per channel property.
-
close
public void close() throws IOException
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in 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
-
-