1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- #include "WAVDatei.h"
- #include <Text.h>
- #include <mmsystem.h>
- #include <Bild.h>
- #include <DateiSystem.h>
- bool istGleich( char *a, char *b, int l )
- {
- bool ret = 1;
- for( ; l > 0; --l, ++a, ++b )
- ret &= *a == *b;
- return ret;
- }
- WAVDatei::WAVDatei()
- : ReferenceCounter()
- {}
- bool WAVDatei::lade( char *pfad )
- {
- d.setDatei( pfad );
- if( !d.open( Datei::Style::lesen ) )
- return 0;
- d.lese( (char *)&kpf, sizeof( kpf ) );
- if( !istGleich( kpf.riff, "RIFF", 4 ) )
- return 0;
- if( !istGleich( kpf.wav, "WAVE", 4 ) )
- return 0;
- d.lese( (char *)&fmt, sizeof( fmt ) );
- if( !istGleich( fmt.fmt, "fmt ", 4 ) )
- return 0;
- if( fmt.channels > 2 || fmt.channels < 1 )
- return 0;
- if( fmt.tag != 1 )
- return 0;
- if( fmt.bitsPerSample != 16 )
- return 0;
- if( fmt.blockAlign * fmt.sampleRate != fmt.bytesPerSec )
- return 0;
- d.lese( (char *)&dBeg, sizeof( dBeg ) );
- while( !istGleich( dBeg.data, "data", 4 ) )
- {
- d.setLPosition( 1 + d.getLPosition() - sizeof( dBeg ), 0 );
- d.lese( (char *)&dBeg, sizeof( dBeg ) );
- }
- pos = (int)d.getLPosition();
- d.close();
- return 1;
- }
- void WAVDatei::open()
- {
- d.open( Datei::Style::lesen );
- d.setLPosition( pos, 0 );
- }
- int WAVDatei::getDaten( char *buffer, int län )
- {
- if( d.getLPosition() + län > d.getSize() )
- län = (int)( d.getSize() - d.getLPosition() );
- if( !län )
- return -1;
- d.lese( buffer, län );
- return län;
- }
- void WAVDatei::close()
- {
- d.close();
- }
- bool WAVDatei::istMono() const
- {
- return fmt.channels == 1;
- }
- int WAVDatei::getSampleRate() const
- {
- return fmt.sampleRate;
- }
- __int64 WAVDatei::getDatLength() const
- {
- return d.getSize() - pos;
- }
|