Class WavSoundSampleWriter

All Implemented Interfaces:
AutoCloseable, BitsPerSampleAccessor, BitsPerSampleAccessor.BitsPerSampleBuilder<WavSoundSampleWriter>, BitsPerSampleAccessor.BitsPerSampleMutator, BitsPerSampleAccessor.BitsPerSampleProperty, SampleWriter<SoundSample,WavSoundSampleWriter>, SamplingRateAccessor, SamplingRateAccessor.SamplingRateBuilder<WavSoundSampleWriter>, SamplingRateAccessor.SamplingRateMutator, SamplingRateAccessor.SamplingRateProperty, SoundSampleWriter<WavSoundSampleWriter>, WavSampleWriter<SoundSample,WavSoundSampleWriter>, org.refcodes.io.RowWriter<SoundSample>

The WavSoundSampleWriter 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".
  • Constructor Details

    • WavSoundSampleWriter

      public WavSoundSampleWriter(File aFile) throws FileNotFoundException
      Constructs the WavSoundSampleWriter for writing sound samples to a WAV file or stream.
      Parameters:
      aFile - The File 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.
    • WavSoundSampleWriter

      public WavSoundSampleWriter(OutputStream aOutputStream)
      Constructs the WavSoundSampleWriter for writing sound samples to a WAV file or stream.
      Parameters:
      aOutputStream - The OutputStream where to write the CSV records to.
  • Method Details

    • withBitsPerSample

      public WavSoundSampleWriter withBitsPerSample(BitsPerSample aBitsPerSample)
      Sets the bits/sample per channel for the bits/sample per channel property.
      Specified by:
      withBitsPerSample in interface BitsPerSampleAccessor.BitsPerSampleBuilder<WavSoundSampleWriter>
      Parameters:
      aBitsPerSample - The bits/sample per channel to be stored by the sampling rate property.
      Returns:
      The builder for applying multiple build operations.
    • writeNext

      public void writeNext(double... aSampleData) throws IOException
      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 interface SoundSampleWriter<WavSoundSampleWriter>
      Parameters:
      aSampleData - The samples, one for each channel.
      Throws:
      IOException - thrown in case writing the sample caused an I/O related problem.
    • writeNext

      public void writeNext(SoundSample aSample) throws IOException
      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 interface org.refcodes.io.RowWriter<SoundSample>
      Specified by:
      writeNext in interface SampleWriter<SoundSample,WavSoundSampleWriter>
      Specified by:
      writeNext in interface SoundSampleWriter<WavSoundSampleWriter>
      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 interface SamplingRateAccessor
      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 interface SamplingRateAccessor.SamplingRateMutator
      Parameters:
      aSamplingRate - The sampling rate to be stored by the sampling rate property.
    • withSamplingRate

      public WavSoundSampleWriter withSamplingRate(int aSamplingRate)
      Sets the sampling rate for the sampling rate property.
      Specified by:
      withSamplingRate in interface SamplingRateAccessor.SamplingRateBuilder<WavSoundSampleWriter>
      Parameters:
      aSamplingRate - The sampling rate to be stored by the sampling rate property.
      Returns:
      The builder for applying multiple build operations.