org.refcodes.audio.AbstractSvgSampleWriter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of refcodes-audio Show documentation
Show all versions of refcodes-audio Show documentation
Artifact providing audio provessing functionality such as generating
sine waves or writing raw audio samples to WAV files.
// /////////////////////////////////////////////////////////////////////////////
// REFCODES.ORG
// /////////////////////////////////////////////////////////////////////////////
// This code is copyright (c) by Siegfried Steiner, Munich, Germany, distributed
// on an "AS IS" BASIS WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, and licen-
// sed under the following (see "http://en.wikipedia.org/wiki/Multi-licensing")
// licenses:
// -----------------------------------------------------------------------------
// GNU General Public License, v3.0 ("http://www.gnu.org/licenses/gpl-3.0.html")
// -----------------------------------------------------------------------------
// Apache License, v2.0 ("http://www.apache.org/licenses/TEXT-2.0")
// -----------------------------------------------------------------------------
// Please contact the copyright holding author(s) of the software artifacts in
// question for licensing issues not being covered by the above listed licenses,
// also regarding commercial licensing models or regarding the compatibility
// with other open source licenses.
// /////////////////////////////////////////////////////////////////////////////
package org.refcodes.audio;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;
/**
* The {@link AbstractSvgSampleWriter} provides a foundation to write sound
* samples to a SVG file.
*
* @param The {@link SoundSample} (sub-)type on which the
* {@link SampleWriter} implementation is to operate on.
* @param The {@link SampleWriter} implementing this
* {@link AbstractSvgSampleWriter}.
*/
public abstract class AbstractSvgSampleWriter> implements SampleWriter {
// /////////////////////////////////////////////////////////////////////////
// CONSTANTS:
// /////////////////////////////////////////////////////////////////////////
// /////////////////////////////////////////////////////////////////////////
// VARIABLES:
// /////////////////////////////////////////////////////////////////////////
protected PrintStream _printStream;
// /////////////////////////////////////////////////////////////////////////
// CONSTRUCTORS:
// /////////////////////////////////////////////////////////////////////////
/**
* Constructs the {@link AbstractSvgSampleWriter} for writing sound samples
* to a SVG file or stream.
*
* @param aFile The {@link File} where to write the SVG 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.
*/
public AbstractSvgSampleWriter( File aFile ) throws FileNotFoundException {
this( new PrintStream( aFile ) );
}
/**
* Constructs the {@link AbstractSvgSampleWriter} for writing sound samples
* to a SVG file or stream.
*
* @param aOutputStream The {@link OutputStream} where to write the SVG
* records to.
*/
public AbstractSvgSampleWriter( OutputStream aOutputStream ) {
this( new PrintStream( aOutputStream ) );
}
/**
* Constructs the {@link AbstractSvgSampleWriter} for writing sound samples
* to a SVG file or stream.
*
* @param aPrintStream The {@link PrintStream} where to write the SVG
* records to.
*/
public AbstractSvgSampleWriter( PrintStream aPrintStream ) {
_printStream = aPrintStream;
}
// /////////////////////////////////////////////////////////////////////////
// METHODS:
// /////////////////////////////////////////////////////////////////////////
/**
* {@inheritDoc}
*/
@Override
public void close() throws IOException {
_printStream.println( "" );
_printStream.close();
}
// /////////////////////////////////////////////////////////////////////////
// HOOKS:
// /////////////////////////////////////////////////////////////////////////
protected double toYCoordinate( double aSampleData, double aFactor ) {
return aSampleData * aFactor / 2 + ( aFactor / 2 );
}
/**
* Writes the SVG file's header, the SVG's tail is written upon invoking
* {@link #close()}.
*/
protected void writeSvgHeader() {
_printStream.println( "
© 2015 - 2025 Weber Informatics LLC | Privacy Policy