C# Class javazoom.jl.converter.WaveFile

Class allowing WaveFormat Access
Inheritance: RiffFile
Show file Open project: RHY3756547/FreeSO Class Usage Examples

Public Methods

Method Description
BitsPerSample ( ) : short
Close ( ) : int

Read 16-bit audio. * public int ReadData (short[] data, int numData) {return super.Read ( data, numData * 2);}

Write 8-bit audio. * public int WriteData ( byte[] data, int numData ) { pcm_data.ckSize += numData; return super.Write ( data, numData ); }

Read 8-bit audio. * public int ReadData ( byte[] data, int numData ) {return super.Read ( data, numData );}

* * public int ReadSamples (int num, int [] WaveFileSample) {

}

* * public int WriteMonoSample ( short[] SampleData ) { switch ( wave_format.data.nBitsPerSample ) { case 8: pcm_data.ckSize += 1; return Write ( SampleData, 1 );

case 16: pcm_data.ckSize += 2; return Write ( SampleData, 2 ); } return DDC_INVALID_CALL; }

* * public int WriteStereoSample ( short[] LeftSample, short[] RightSample ) { int retcode = DDC_SUCCESS; switch ( wave_format.data.nBitsPerSample ) { case 8: retcode = Write ( LeftSample, 1 ); if ( retcode == DDC_SUCCESS ) { retcode = Write ( RightSample, 1 ); if ( retcode == DDC_SUCCESS ) { pcm_data.ckSize += 2; } } break;

case 16: retcode = Write ( LeftSample, 2 ); if ( retcode == DDC_SUCCESS ) { retcode = Write ( RightSample, 2 ); if ( retcode == DDC_SUCCESS ) { pcm_data.ckSize += 4; } } break;

default: retcode = DDC_INVALID_CALL; } return retcode; }

* * public int ReadMonoSample ( short[] Sample ) { int retcode = DDC_SUCCESS; switch ( wave_format.data.nBitsPerSample ) { case 8: byte[] x = {0}; retcode = Read ( x, 1 ); Sample[0] = (short)(x[0]); break;

case 16: retcode = Read ( Sample, 2 ); break;

default: retcode = DDC_INVALID_CALL; } return retcode; }

* * public int ReadStereoSample ( short[] LeftSampleData, short[] RightSampleData ) { int retcode = DDC_SUCCESS; byte[] x = new byte[2]; short[] y = new short[2]; switch ( wave_format.data.nBitsPerSample ) { case 8: retcode = Read ( x, 2 ); L[0] = (short) ( x[0] ); R[0] = (short) ( x[1] ); break;

case 16: retcode = Read ( y, 4 ); L[0] = (short) ( y[0] ); R[0] = (short) ( y[1] ); break;

default: retcode = DDC_INVALID_CALL; } return retcode; }

*

Close ( bool justWriteLengthBytes ) : int
CurrentFilePosition ( ) : long

*

NumChannels ( ) : short
NumSamples ( ) : int
OpenForWrite ( System Filename, System stream, int SamplingRate, short BitsPerSample, short NumChannels ) : int

* * public int OpenForRead (String Filename) { // Verify filename parameter as best we can... if (Filename == null) { return DDC_INVALID_CALL; } int retcode = Open ( Filename, RFM_READ );

if ( retcode == DDC_SUCCESS ) { retcode = Expect ( "WAVE", 4 );

if ( retcode == DDC_SUCCESS ) { retcode = Read(wave_format,24);

if ( retcode == DDC_SUCCESS && !wave_format.VerifyValidity() ) { // This isn't standard PCM, so we don't know what it is! retcode = DDC_FILE_ERROR; }

if ( retcode == DDC_SUCCESS ) { pcm_data_offset = CurrentFilePosition();

Figure out number of samples from // file size, current file position, and // WAVE header. retcode = Read (pcm_data, 8 ); num_samples = filelength(fileno(file)) - CurrentFilePosition(); num_samples /= NumChannels(); num_samples /= (BitsPerSample() / 8); } } } return retcode; }

Pass in either a FileName or a Stream.

OpenForWrite ( System Filename, WaveFile OtherWave ) : int

Open for write using another wave file's parameters...

SamplingRate ( ) : int
WaveFile ( ) : System

Constructs a new WaveFile instance.

WriteData ( short data, int numData ) : int

* * public int ReadSample ( short[] Sample ) {

}

* * public int WriteSample( short[] Sample ) { int retcode = DDC_SUCCESS; switch ( wave_format.data.nChannels ) { case 1: switch ( wave_format.data.nBitsPerSample ) { case 8: pcm_data.ckSize += 1; retcode = Write ( Sample, 1 ); break;

case 16: pcm_data.ckSize += 2; retcode = Write ( Sample, 2 ); break;

default: retcode = DDC_INVALID_CALL; } break;

case 2: switch ( wave_format.data.nBitsPerSample ) { case 8: retcode = Write ( Sample, 1 ); if ( retcode == DDC_SUCCESS ) { // &Sample[1] retcode = Write (Sample, 1 ); if ( retcode == DDC_SUCCESS ) { pcm_data.ckSize += 2; } } break;

case 16: retcode = Write ( Sample, 2 ); if ( retcode == DDC_SUCCESS ) { // &Sample[1] retcode = Write (Sample, 2 ); if ( retcode == DDC_SUCCESS ) { pcm_data.ckSize += 4; } } break;

default: retcode = DDC_INVALID_CALL; } break;

default: retcode = DDC_INVALID_CALL; }

return retcode; }

* * public int SeekToSample ( long SampleIndex ) { if ( SampleIndex >= NumSamples() ) { return DDC_INVALID_CALL; } int SampleSize = (BitsPerSample() + 7) / 8; int rc = Seek ( pcm_data_offset + 8 + SampleSize * NumChannels() * SampleIndex ); return rc; }

Write 16-bit audio

Method Details

BitsPerSample() public method

public BitsPerSample ( ) : short
return short

Close() public method

Read 16-bit audio. * public int ReadData (short[] data, int numData) {return super.Read ( data, numData * 2);} Write 8-bit audio. * public int WriteData ( byte[] data, int numData ) { pcm_data.ckSize += numData; return super.Write ( data, numData ); } Read 8-bit audio. * public int ReadData ( byte[] data, int numData ) {return super.Read ( data, numData );} * * public int ReadSamples (int num, int [] WaveFileSample) { } * * public int WriteMonoSample ( short[] SampleData ) { switch ( wave_format.data.nBitsPerSample ) { case 8: pcm_data.ckSize += 1; return Write ( SampleData, 1 ); case 16: pcm_data.ckSize += 2; return Write ( SampleData, 2 ); } return DDC_INVALID_CALL; } * * public int WriteStereoSample ( short[] LeftSample, short[] RightSample ) { int retcode = DDC_SUCCESS; switch ( wave_format.data.nBitsPerSample ) { case 8: retcode = Write ( LeftSample, 1 ); if ( retcode == DDC_SUCCESS ) { retcode = Write ( RightSample, 1 ); if ( retcode == DDC_SUCCESS ) { pcm_data.ckSize += 2; } } break; case 16: retcode = Write ( LeftSample, 2 ); if ( retcode == DDC_SUCCESS ) { retcode = Write ( RightSample, 2 ); if ( retcode == DDC_SUCCESS ) { pcm_data.ckSize += 4; } } break; default: retcode = DDC_INVALID_CALL; } return retcode; } * * public int ReadMonoSample ( short[] Sample ) { int retcode = DDC_SUCCESS; switch ( wave_format.data.nBitsPerSample ) { case 8: byte[] x = {0}; retcode = Read ( x, 1 ); Sample[0] = (short)(x[0]); break; case 16: retcode = Read ( Sample, 2 ); break; default: retcode = DDC_INVALID_CALL; } return retcode; } * * public int ReadStereoSample ( short[] LeftSampleData, short[] RightSampleData ) { int retcode = DDC_SUCCESS; byte[] x = new byte[2]; short[] y = new short[2]; switch ( wave_format.data.nBitsPerSample ) { case 8: retcode = Read ( x, 2 ); L[0] = (short) ( x[0] ); R[0] = (short) ( x[1] ); break; case 16: retcode = Read ( y, 4 ); L[0] = (short) ( y[0] ); R[0] = (short) ( y[1] ); break; default: retcode = DDC_INVALID_CALL; } return retcode; } *
public Close ( ) : int
return int

Close() public method

public Close ( bool justWriteLengthBytes ) : int
justWriteLengthBytes bool
return int

CurrentFilePosition() public method

*
public CurrentFilePosition ( ) : long
return long

NumChannels() public method

public NumChannels ( ) : short
return short

NumSamples() public method

public NumSamples ( ) : int
return int

OpenForWrite() public method

* * public int OpenForRead (String Filename) { // Verify filename parameter as best we can... if (Filename == null) { return DDC_INVALID_CALL; } int retcode = Open ( Filename, RFM_READ ); if ( retcode == DDC_SUCCESS ) { retcode = Expect ( "WAVE", 4 ); if ( retcode == DDC_SUCCESS ) { retcode = Read(wave_format,24); if ( retcode == DDC_SUCCESS && !wave_format.VerifyValidity() ) { // This isn't standard PCM, so we don't know what it is! retcode = DDC_FILE_ERROR; } if ( retcode == DDC_SUCCESS ) { pcm_data_offset = CurrentFilePosition(); Figure out number of samples from // file size, current file position, and // WAVE header. retcode = Read (pcm_data, 8 ); num_samples = filelength(fileno(file)) - CurrentFilePosition(); num_samples /= NumChannels(); num_samples /= (BitsPerSample() / 8); } } } return retcode; } Pass in either a FileName or a Stream.
public OpenForWrite ( System Filename, System stream, int SamplingRate, short BitsPerSample, short NumChannels ) : int
Filename System
stream System
SamplingRate int
BitsPerSample short
NumChannels short
return int

OpenForWrite() public method

Open for write using another wave file's parameters...
public OpenForWrite ( System Filename, WaveFile OtherWave ) : int
Filename System
OtherWave WaveFile
return int

SamplingRate() public method

public SamplingRate ( ) : int
return int

WaveFile() public method

Constructs a new WaveFile instance.
public WaveFile ( ) : System
return System

WriteData() public method

* * public int ReadSample ( short[] Sample ) { } * * public int WriteSample( short[] Sample ) { int retcode = DDC_SUCCESS; switch ( wave_format.data.nChannels ) { case 1: switch ( wave_format.data.nBitsPerSample ) { case 8: pcm_data.ckSize += 1; retcode = Write ( Sample, 1 ); break; case 16: pcm_data.ckSize += 2; retcode = Write ( Sample, 2 ); break; default: retcode = DDC_INVALID_CALL; } break; case 2: switch ( wave_format.data.nBitsPerSample ) { case 8: retcode = Write ( Sample, 1 ); if ( retcode == DDC_SUCCESS ) { // &Sample[1] retcode = Write (Sample, 1 ); if ( retcode == DDC_SUCCESS ) { pcm_data.ckSize += 2; } } break; case 16: retcode = Write ( Sample, 2 ); if ( retcode == DDC_SUCCESS ) { // &Sample[1] retcode = Write (Sample, 2 ); if ( retcode == DDC_SUCCESS ) { pcm_data.ckSize += 4; } } break; default: retcode = DDC_INVALID_CALL; } break; default: retcode = DDC_INVALID_CALL; } return retcode; } * * public int SeekToSample ( long SampleIndex ) { if ( SampleIndex >= NumSamples() ) { return DDC_INVALID_CALL; } int SampleSize = (BitsPerSample() + 7) / 8; int rc = Seek ( pcm_data_offset + 8 + SampleSize * NumChannels() * SampleIndex ); return rc; } Write 16-bit audio
public WriteData ( short data, int numData ) : int
data short
numData int
return int