Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

WAVImport Class Reference

Inheritance diagram for WAVImport:

Inheritance graph
[legend]
Collaboration diagram for WAVImport:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 WAVImport ()
virtual ~WAVImport ()
bool Open (char *input)
int GetChannels ()
int GetFrequency ()
int GetBytesPerSample ()
long GetNumberOfSamples ()
bool Seek (off_t offset)
bool Get (int16_t *data, int length)
bool Close ()

Private Attributes

WAVStructType wav
long start
int channels
int frequency
int bytespersample
long length

Constructor & Destructor Documentation

WAVImport::WAVImport  ) 
 

Definition at line 204 of file kino_av_pipe.cc.

References WAVStructType::file, and wav.

00205 {
00206     wav.file = NULL;
00207 }

WAVImport::~WAVImport  )  [virtual]
 

Definition at line 209 of file kino_av_pipe.cc.

References Close().

00210 {
00211     Close( );
00212 }


Member Function Documentation

bool WAVImport::Close  )  [virtual]
 

Implements KinoAudioInput.

Definition at line 263 of file kino_av_pipe.cc.

References WAVStructType::data, WAVStructType::file, WAVStructType::format, WAVStructType::riff, and wav.

Referenced by ~WAVImport().

00264 {
00265     if ( wav.file != NULL )
00266     {
00267         fclose( wav.file );
00268         free( wav.riff );
00269         free( wav.format );
00270         free( wav.data );
00271         wav.file = NULL;
00272     }
00273     return true;
00274 }

bool WAVImport::Get int16_t *  data,
int  length
[virtual]
 

Implements KinoAudioInput.

Definition at line 258 of file kino_av_pipe.cc.

References WAVStructType::file, and wav.

00259 {
00260     return fread( data, 1, length, wav.file ) == ( unsigned ) length;
00261 }

int WAVImport::GetBytesPerSample  )  [inline, virtual]
 

Implements KinoAudioInput.

Definition at line 191 of file kino_av_pipe.cc.

References bytespersample.

00192     {
00193         return bytespersample;
00194     }

int WAVImport::GetChannels  )  [inline, virtual]
 

Implements KinoAudioInput.

Definition at line 183 of file kino_av_pipe.cc.

References channels.

00184     {
00185         return channels;
00186     }

int WAVImport::GetFrequency  )  [inline, virtual]
 

Implements KinoAudioInput.

Definition at line 187 of file kino_av_pipe.cc.

References frequency.

00188     {
00189         return frequency;
00190     }

long WAVImport::GetNumberOfSamples  )  [inline, virtual]
 

Implements KinoAudioInput.

Definition at line 195 of file kino_av_pipe.cc.

References bytespersample, channels, and length.

00196     {
00197         return length / channels / bytespersample;
00198     }

bool WAVImport::Open char *  input  )  [virtual]
 

Implements KinoAudioInput.

Definition at line 214 of file kino_av_pipe.cc.

References bytespersample, channels, WAVStructType::data, WAVStructType::file, WAVStructType::format, frequency, length, WAVStructType::riff, start, and wav.

00215 {
00216     bool iswav = false;
00217 
00218     wav.file = fopen( input, "r" );
00219 
00220     if ( wav.file != NULL )
00221     {
00222         wav.riff = ( RIFFChunk ) malloc( sizeof( RIFFChunkType ) );
00223         wav.format = ( FORMATChunk ) malloc( sizeof( FORMATChunkType ) );
00224         wav.data = ( DATAChunk ) malloc( sizeof( DATAChunkType ) );
00225 
00226         // Bad... temporary code
00227         fread( wav.riff, sizeof( RIFFChunkType ), 1, wav.file );
00228         fread( wav.format, sizeof( FORMATChunkType ), 1, wav.file );
00229         int remainder = wav.format->length - sizeof( FORMATChunkType );
00230         if ( remainder > 0 )
00231             fseek( wav.file, remainder, SEEK_CUR );
00232         fread( wav.data, sizeof( DATAChunkType ), 1, wav.file );
00233         if ( strncasecmp( wav.data->data, "JUNK", 4 ) == 0 )
00234         {
00235             fseek( wav.file, wav.data->length, SEEK_CUR );
00236             fread( wav.data, sizeof( DATAChunkType ), 1, wav.file );
00237         }
00238 
00239         if ( !strncmp( wav.riff->riff, "RIFF", 4 ) && !strncmp( wav.riff->type, "WAVE", 4 ) )
00240         {
00241             iswav = true;
00242             channels = wav.format->channels;
00243             frequency = wav.format->rate;
00244             bytespersample = wav.format->bytespersample / channels;
00245             start = ftell( wav.file );
00246             length = wav.data->length;
00247         }
00248     }
00249 
00250     return iswav;
00251 }

bool WAVImport::Seek off_t  offset  )  [virtual]
 

Implements KinoAudioInput.

Definition at line 253 of file kino_av_pipe.cc.

References WAVStructType::file, start, and wav.

00254 {
00255     return fseek( wav.file, offset + start, SEEK_SET ) == 0;
00256 }


Member Data Documentation

int WAVImport::bytespersample [private]
 

Definition at line 177 of file kino_av_pipe.cc.

Referenced by GetBytesPerSample(), GetNumberOfSamples(), and Open().

int WAVImport::channels [private]
 

Definition at line 175 of file kino_av_pipe.cc.

Referenced by GetChannels(), GetNumberOfSamples(), and Open().

int WAVImport::frequency [private]
 

Definition at line 176 of file kino_av_pipe.cc.

Referenced by GetFrequency(), and Open().

long WAVImport::length [private]
 

Definition at line 178 of file kino_av_pipe.cc.

Referenced by GetNumberOfSamples(), and Open().

long WAVImport::start [private]
 

Definition at line 174 of file kino_av_pipe.cc.

Referenced by Open(), and Seek().

WAVStructType WAVImport::wav [private]
 

Definition at line 173 of file kino_av_pipe.cc.

Referenced by Close(), Get(), Open(), Seek(), and WAVImport().


The documentation for this class was generated from the following file:
Generated on Sun Mar 11 22:13:28 2007 for Kino by  doxygen 1.4.2