123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- #include "WAVDatei.h"
- #include <Bild.h>
- #include <DateiSystem.h>
- #include <mmsystem.h>
- #include <Text.h>
- bool istGleich(const char* a, const 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;
- }
|