tapeutils.impl.zx81
Class ZX81SampleGenerator

java.lang.Object
  extended bytapeutils.impl.zx81.ZX81SampleGenerator
All Implemented Interfaces:
SampleGenerator

public class ZX81SampleGenerator
extends java.lang.Object
implements SampleGenerator

This class provides a utility to generate a sound sample from the contents of a .P file.

Author:
hldswrth

Constructor Summary
ZX81SampleGenerator(byte[][] programData, byte[][] programNameBytes, int[] programGaps)
          Construct the sample generator from a .TZX file.
ZX81SampleGenerator(java.util.List blocks)
          Constructor from a sequence of TZX Generic blocks that represent ZX81 programs.
ZX81SampleGenerator(PFile pFile, java.lang.String programName)
          Construct the sample generator from a .P file.
 
Method Summary
 byte[] convertToSample(double rate, boolean squareWave)
          Convert the .P file to a sample.
 void play(float frequency, boolean squareWave)
          Play the data as a sample.
 void write(float frequency, boolean squareWave, java.io.File sampleFile)
          Write the .P file as a sample file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ZX81SampleGenerator

public ZX81SampleGenerator(PFile pFile,
                           java.lang.String programName)
Construct the sample generator from a .P file.

The program name is required as this is the first part of the sample, and is not in the .P file itself.

Parameters:
pFile - The P file.
programName - The program name.

ZX81SampleGenerator

public ZX81SampleGenerator(byte[][] programData,
                           byte[][] programNameBytes,
                           int[] programGaps)
Construct the sample generator from a .TZX file.

The program names is required as this is the first part of the sample, and is not in the data file itself.

Parameters:
programData - The program data.
programNameBytes - The program names.
programGaps - The program gaps.

ZX81SampleGenerator

public ZX81SampleGenerator(java.util.List blocks)
Constructor from a sequence of TZX Generic blocks that represent ZX81 programs.

Parameters:
blocks - The blocks.
Method Detail

play

public void play(float frequency,
                 boolean squareWave)
          throws javax.sound.sampled.LineUnavailableException
Play the data as a sample.

Specified by:
play in interface SampleGenerator
Parameters:
frequency - The frequency for the sample.
squareWave - Indicates whether to use a square wave.
Throws:
javax.sound.sampled.LineUnavailableException - An audio line could not be opened.

write

public void write(float frequency,
                  boolean squareWave,
                  java.io.File sampleFile)
           throws java.io.IOException
Write the .P file as a sample file.

Specified by:
write in interface SampleGenerator
Parameters:
frequency - The frequency for the sample.
sampleFile - The file to contain the sample.
squareWave - Indicates whether to use a square wave.
Throws:
java.io.IOException - An error occurred writing to a file.

convertToSample

public byte[] convertToSample(double rate,
                              boolean squareWave)
                       throws java.lang.IllegalArgumentException
Convert the .P file to a sample.

Parameters:
rate - The sample rate.
squareWave - Indicates whether to use a square wave.
Returns:
The sample bytes.
Throws:
java.lang.IllegalArgumentException - The program name is invalid.