#include "WAVDatei.h" #include #include #include #include bool istGleich(char* a, char* b, int l) { bool ret = 1; for (; l > 0; --l, ++a, ++b) ret &= *a == *b; return ret; } // Inhalt der WAVDatei Klasse aus WAVDatei.h // Konstruktor WAVDatei::WAVDatei() : ReferenceCounter() {} // nicht constant bool WAVDatei::lade(const 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; } // zum Speichern 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; }