java.lang.Object
org.refcodes.audio.AbstractWavSampleWriter<MonoSample,WavMonoSampleWriter>
org.refcodes.audio.WavMonoSampleWriter
- All Implemented Interfaces:
AutoCloseable
,BitsPerSampleAccessor
,BitsPerSampleAccessor.BitsPerSampleBuilder<WavMonoSampleWriter>
,BitsPerSampleAccessor.BitsPerSampleMutator
,BitsPerSampleAccessor.BitsPerSampleProperty
,MonoSampleWriter<WavMonoSampleWriter>
,SampleWriter<MonoSample,
,WavMonoSampleWriter> SamplingRateAccessor
,SamplingRateAccessor.SamplingRateBuilder<WavMonoSampleWriter>
,SamplingRateAccessor.SamplingRateMutator
,SamplingRateAccessor.SamplingRateProperty
,WavSampleWriter<MonoSample,
,WavMonoSampleWriter> org.refcodes.io.RowWriter<MonoSample>
public class WavMonoSampleWriter
extends AbstractWavSampleWriter<MonoSample,WavMonoSampleWriter>
implements MonoSampleWriter<WavMonoSampleWriter>
The
WavMonoSampleWriter
provides 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 inherited from class org.refcodes.audio.AbstractWavSampleWriter
_bitsPerSample, _file, _outputStream, DATA, FORMAT, MAX_16_BIT, MAX_8_BIT, RIFF, WAVE
-
Constructor Summary
ConstructorDescriptionWavMonoSampleWriter
(File aFile) Constructs theWavMonoSampleWriter
for writing sound samples to a WAV file or stream.WavMonoSampleWriter
(OutputStream aOutputStream) Constructs theWavMonoSampleWriter
for writing sound samples to a WAV file or stream. -
Method Summary
Modifier and TypeMethodDescriptionint
Retrieves the sampling rate from the sampling rate property.void
setSamplingRate
(int aSamplingRate) Sets the sampling rate for the sampling rate property.withBitsPerSample
(BitsPerSample aBitsPerSample) Sets the bits/sample per channel for the bits/sample per channel property.withSamplingRate
(int aSamplingRate) Sets the sampling rate for the sampling rate property.void
writeNext
(double aSampleData) Writes the next samples, one sample for each channel.void
writeNext
(MonoSample aSample) Writes the next samples, one sample for each channel.Methods inherited from class org.refcodes.audio.AbstractWavSampleWriter
close, getBitsPerSample, setBitsPerSample, toWavSample, writeHeader
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.BitsPerSampleProperty
letBitsPerSample
Methods inherited from interface org.refcodes.audio.SampleWriter
close
Methods inherited from interface org.refcodes.audio.SamplingRateAccessor.SamplingRateProperty
letSamplingRate
-
Constructor Details
-
WavMonoSampleWriter
Constructs theWavMonoSampleWriter
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.
-
WavMonoSampleWriter
Constructs theWavMonoSampleWriter
for writing sound samples to a WAV file or stream.- Parameters:
aOutputStream
- TheOutputStream
where to write the CSV records to.
-
-
Method Details
-
withBitsPerSample
Sets the bits/sample per channel for the bits/sample per channel property.- Specified by:
withBitsPerSample
in interfaceBitsPerSampleAccessor.BitsPerSampleBuilder<WavMonoSampleWriter>
- Parameters:
aBitsPerSample
- The bits/sample per channel to be stored by the sampling rate property.- Returns:
- The builder for applying multiple build operations.
-
writeNext
Writes the next samples, one sample for each channel. Provide one sample for mono audio, two samples for stereo audio and so on. In case you provide more or less samples than channels being supported by the writer, then it is up to the writer whether to duplicate the samples or calculate an average or the like.- Specified by:
writeNext
in interfaceMonoSampleWriter<WavMonoSampleWriter>
- Parameters:
aSampleData
- The samples, one for each channel.- Throws:
IOException
- thrown in case writing the sample caused an I/O related problem.
-
writeNext
Writes the next samples, one sample for each channel. Provide one sample for mono audio, two samples for stereo audio and so on. In case you provide more or less samples than channels being supported by the writer, then it is up to the writer whether to duplicate the samples or calculate an average or the like.- Specified by:
writeNext
in interfaceorg.refcodes.io.RowWriter<MonoSample>
- Specified by:
writeNext
in interfaceSampleWriter<MonoSample,
WavMonoSampleWriter> - Parameters:
aSample
- The samples, one for each channel.- Throws:
IOException
- thrown in case writing the sample caused an I/O related problem.
-
getSamplingRate
public int getSamplingRate()Retrieves the sampling rate from the sampling rate property.- Specified by:
getSamplingRate
in interfaceSamplingRateAccessor
- Returns:
- The sampling rate stored by the sampling rate property.
-
setSamplingRate
public void setSamplingRate(int aSamplingRate) Sets the sampling rate for the sampling rate property.- Specified by:
setSamplingRate
in interfaceSamplingRateAccessor.SamplingRateMutator
- Parameters:
aSamplingRate
- The sampling rate to be stored by the sampling rate property.
-
withSamplingRate
Sets the sampling rate for the sampling rate property.- Specified by:
withSamplingRate
in interfaceSamplingRateAccessor.SamplingRateBuilder<WavMonoSampleWriter>
- Parameters:
aSamplingRate
- The sampling rate to be stored by the sampling rate property.- Returns:
- The builder for applying multiple build operations.
-