be.hogent.tarsos.midi
Class ToneSequenceBuilder

java.lang.Object
  extended by be.hogent.tarsos.midi.ToneSequenceBuilder

public final class ToneSequenceBuilder
extends java.lang.Object

Create a sequence of tones. Tones are in this case a sine wave of a certain frequency (in Hertz) starting at a certain time (in seconds) the current tone stops when another tone starts: this class generates only one tone at the time (monophonic).

Author:
Joren Six

Nested Class Summary
static class ToneSequenceBuilder.AnnotationCVSFileHandlers
           
static interface ToneSequenceBuilder.CSVFileHandler
           
 
Constructor Summary
ToneSequenceBuilder()
          Initializes the lists of frequencies and times.
 
Method Summary
 void addTone(double frequency, double realTime)
          Add a tone with a certain frequency (in Hertz) starting at a certain time (seconds).
 void addTone(double frequency, double realTime, double power)
           
 void clear()
          Clears the frequencies and times.
 int getNumberOfExpectedColumn()
           
 java.lang.String getSeparator()
           
 void handleRow(ToneSequenceBuilder builder, java.lang.String[] row)
           
 void playAnnotations(int smootFilterWindowSize)
           
static void saveAsWav(java.lang.String csvFileName, ToneSequenceBuilder.CSVFileHandler handler, int smootFilterWindowSize)
          Read data from a CSV-File, handle it with the handler, smooth it and save it to the generated audio folder.
 void setExtractor(SignalPowerExtractor extractor)
           
 void writeFile(java.lang.String fileName, int smootFilterWindowSize, java.lang.String sourceFile)
          Write a stereo WAV-file (sample rate 44.1 kHz) with frequencies and their respective durations (start times).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ToneSequenceBuilder

public ToneSequenceBuilder()
Initializes the lists of frequencies and times.

Method Detail

addTone

public void addTone(double frequency,
                    double realTime)
Add a tone with a certain frequency (in Hertz) starting at a certain time (seconds).

The tone stops when the next tone starts. The last tone has a duration of 0 seconds. The entries should be added chronologically! Strange things will happen if you ignore this rule.

Parameters:
frequency - the frequency in Hertz of the tone to add
realTime - the starttime in seconds of the tone. The tone stops when the next one starts. The last tone is never played.

addTone

public void addTone(double frequency,
                    double realTime,
                    double power)

clear

public void clear()
Clears the frequencies and times. When this method finishes the object is in the same state as a new instance of ToneSequenceBuilder.


playAnnotations

public void playAnnotations(int smootFilterWindowSize)

writeFile

public void writeFile(java.lang.String fileName,
                      int smootFilterWindowSize,
                      java.lang.String sourceFile)
               throws java.io.IOException,
                      javax.sound.sampled.UnsupportedAudioFileException,
                      javax.sound.sampled.LineUnavailableException
Write a stereo WAV-file (sample rate 44.1 kHz) with frequencies and their respective durations (start times). If the fileName is null the file played. If sourceFile is given the source file is written on the left ch

Parameters:
fileName - The name of the file to render. e.g. "out.wav".
smootFilterWindowSize - To prevent (very) sudden changes in the frequency of tones a smoothing function can be applied. The window size of the smoothing function defines what an unexpected value is and if it is smoothed. When no smoothing is required set it to zero. Otherwise a value between 5 and 50 is normal. ( 50 x 10 ms = 500 ms = 0.5 seconds). A median filter is used.
sourceFile - The source file used
Throws:
java.io.IOException - When something goes awry.
javax.sound.sampled.UnsupportedAudioFileException
javax.sound.sampled.LineUnavailableException
SinkIsFullException
java.lang.InterruptedException
BufferNotAvailableException

saveAsWav

public static void saveAsWav(java.lang.String csvFileName,
                             ToneSequenceBuilder.CSVFileHandler handler,
                             int smootFilterWindowSize)
Read data from a CSV-File, handle it with the handler, smooth it and save it to the generated audio folder.

Parameters:
csvFileName - the CSV-file to process
handler - the handler
smootFilterWindowSize - the window size for the smoothing function (Median filter).

handleRow

public void handleRow(ToneSequenceBuilder builder,
                      java.lang.String[] row)

getSeparator

public java.lang.String getSeparator()

getNumberOfExpectedColumn

public int getNumberOfExpectedColumn()

setExtractor

public void setExtractor(SignalPowerExtractor extractor)