Package org.xiph.speex
Class PcmWaveWriter
java.lang.Object
org.xiph.speex.AudioFileWriter
org.xiph.speex.PcmWaveWriter
Writes basic PCM wave files from binary audio data.
Here's an example that writes 2 seconds of silence
PcmWaveWriter s_wsw = new PcmWaveWriter(2, 44100);
byte[] silence = new byte[16*2*44100];
wsw.Open("C:\\out.wav");
wsw.WriteHeader();
wsw.WriteData(silence, 0, silence.length);
wsw.WriteData(silence, 0, silence.length);
wsw.Close();
- Version:
- $Revision: 1.2 $
- Author:
- Jim Lawrence, helloNetwork.com, Marc Gimpel, Wimba S.A. (mgimpel@horizonwimba.com)
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate intDefines the number of channels of the audio input (1=mono, 2=stereo).private booleanprivate intDefines the encoder mode (0=NB, 1=WB and 2-UWB).private intDefines the number of frames per speex packet.private intprivate RandomAccessFileprivate intDefines the sampling rate of the audio input.private intprivate booleanDefines whether or not to use VBR (Variable Bit Rate).static final int[][][]Table describing the number of bit per Speex frame, depending on its mode-1 (1=NB, 2=WB, 3=UWB), channels-1 (1=mono, 2=stereo) and the quality setting (0 to 10).static final shortWave type code of PCMstatic final shortWave type code of Speexstatic final int[][][]Table describing the number of frames per packet in a Speex Wave file, depending on its mode-1 (1=NB, 2=WB, 3=UWB), channels-1 (1=mono, 2=stereo) and the quality setting (0 to 10). -
Constructor Summary
ConstructorsConstructorDescriptionConstructor.PcmWaveWriter(int sampleRate, int channels) Constructor.PcmWaveWriter(int mode, int quality, int sampleRate, int channels, int nframes, boolean vbr) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionprivate static final intcalculateBlockSize(int mode, int channels, int quality) Calculates block size (considering padding).private static final intcalculateEffectiveBitrate(int mode, int channels, int quality) Calculates effective bitrate (considering padding).voidclose()Closes the output file.voidOpen the output file.voidOpen the output file.private voidsetPCMFormat(int sampleRate, int channels) Sets the output format for a PCM Wave file.private voidsetSpeexFormat(int mode, int quality, int sampleRate, int channels, int nframes, boolean vbr) Sets the output format for a Speex Wave file.voidwriteHeader(String comment) Writes the initial data chunks that start the wave file.voidwritePacket(byte[] data, int offset, int len) Writes a packet of audio.Methods inherited from class org.xiph.speex.AudioFileWriter
buildOggPageHeader, buildSpeexComment, buildSpeexHeader, writeInt, writeInt, writeInt, writeLong, writeLong, writeOggPageHeader, writeShort, writeShort, writeShort, writeSpeexComment, writeSpeexHeader, writeString
-
Field Details
-
WAVE_FORMAT_PCM
public static final short WAVE_FORMAT_PCMWave type code of PCM- See Also:
-
WAVE_FORMAT_SPEEX
public static final short WAVE_FORMAT_SPEEXWave type code of Speex- See Also:
-
WAVE_FRAME_SIZES
public static final int[][][] WAVE_FRAME_SIZESTable describing the number of frames per packet in a Speex Wave file, depending on its mode-1 (1=NB, 2=WB, 3=UWB), channels-1 (1=mono, 2=stereo) and the quality setting (0 to 10). See end of file for exerpt from SpeexACM code for more explanations. -
WAVE_BITS_PER_FRAME
public static final int[][][] WAVE_BITS_PER_FRAMETable describing the number of bit per Speex frame, depending on its mode-1 (1=NB, 2=WB, 3=UWB), channels-1 (1=mono, 2=stereo) and the quality setting (0 to 10). See end of file for exerpt from SpeexACM code for more explanations. -
raf
-
mode
private int modeDefines the encoder mode (0=NB, 1=WB and 2-UWB). -
quality
private int quality -
sampleRate
private int sampleRateDefines the sampling rate of the audio input. -
channels
private int channelsDefines the number of channels of the audio input (1=mono, 2=stereo). -
nframes
private int nframesDefines the number of frames per speex packet. -
vbr
private boolean vbrDefines whether or not to use VBR (Variable Bit Rate). -
size
private int size -
isPCM
private boolean isPCM
-
-
Constructor Details
-
PcmWaveWriter
public PcmWaveWriter()Constructor. -
PcmWaveWriter
public PcmWaveWriter(int sampleRate, int channels) Constructor.- Parameters:
sampleRate- the number of samples per second.channels- the number of audio channels (1=mono, 2=stereo, ...).
-
PcmWaveWriter
public PcmWaveWriter(int mode, int quality, int sampleRate, int channels, int nframes, boolean vbr) Constructor.- Parameters:
mode- the mode of the encoder (0=NB, 1=WB, 2=UWB).quality-sampleRate- the number of samples per second.channels- the number of audio channels (1=mono, 2=stereo, ...).nframes- the number of frames per speex packet.vbr-
-
-
Method Details
-
setPCMFormat
private void setPCMFormat(int sampleRate, int channels) Sets the output format for a PCM Wave file. Must be called before WriteHeader().- Parameters:
sampleRate- the number of samples per second.channels- the number of audio channels (1=mono, 2=stereo, ...).
-
setSpeexFormat
private void setSpeexFormat(int mode, int quality, int sampleRate, int channels, int nframes, boolean vbr) Sets the output format for a Speex Wave file. Must be called before WriteHeader().- Parameters:
mode- the mode of the encoder (0=NB, 1=WB, 2=UWB).quality-sampleRate- the number of samples per second.channels- the number of audio channels (1=mono, 2=stereo, ...).nframes- the number of frames per speex packet.vbr-
-
close
Closes the output file. MUST be called to have a correct stream.- Specified by:
closein classAudioFileWriter- Throws:
IOException- if there was an exception closing the Audio Writer.
-
open
Open the output file.- Specified by:
openin classAudioFileWriter- Parameters:
file- - file to open.- Throws:
IOException- if there was an exception opening the Audio Writer.
-
open
Open the output file.- Specified by:
openin classAudioFileWriter- Parameters:
filename- filename to open.- Throws:
IOException- if there was an exception opening the Audio Writer.
-
writeHeader
Writes the initial data chunks that start the wave file. Prepares file for data samples to written.- Specified by:
writeHeaderin classAudioFileWriter- Parameters:
comment- ignored by the WAV header.- Throws:
IOException
-
writePacket
Writes a packet of audio.- Specified by:
writePacketin classAudioFileWriter- Parameters:
data- audio dataoffset- the offset from which to start reading the data.len- the length of data to read.- Throws:
IOException
-
calculateEffectiveBitrate
private static final int calculateEffectiveBitrate(int mode, int channels, int quality) Calculates effective bitrate (considering padding). See end of file for exerpt from SpeexACM code for more explanations.- Parameters:
mode-channels-quality-- Returns:
- effective bitrate (considering padding).
-
calculateBlockSize
private static final int calculateBlockSize(int mode, int channels, int quality) Calculates block size (considering padding). See end of file for exerpt from SpeexACM code for more explanations.- Parameters:
mode-channels-quality-- Returns:
- block size (considering padding).
-