#ifndef DECODERS_H #define DECODERS_H #include "bytes.h" #include "sector.h" #include "record.h" #include "decoders/fluxmapreader.h" class Sector; class Fluxmap; class FluxmapReader; class RawRecord; class RawBits; class Track; class DecoderProto; typedef std::vector> RawRecordVector; typedef std::vector> SectorVector; extern void setDecoderManualClockRate(double clockrate_us); extern Bytes decodeFmMfm(std::vector::const_iterator start, std::vector::const_iterator end); extern void encodeMfm(std::vector& bits, unsigned& cursor, const Bytes& input, bool& lastBit); extern void encodeFm(std::vector& bits, unsigned& cursor, const Bytes& input); extern Bytes encodeMfm(const Bytes& input, bool& lastBit); static inline Bytes decodeFmMfm(const std::vector bits) { return decodeFmMfm(bits.begin(), bits.end()); } class AbstractDecoder { public: virtual ~AbstractDecoder() {} static std::unique_ptr create(const DecoderProto& config); public: enum RecordType { SECTOR_RECORD, DATA_RECORD, UNKNOWN_RECORD }; public: void decodeToSectors(Track& track); void pushRecord(const Fluxmap::Position& start, const Fluxmap::Position& end); std::vector readRawBits(unsigned count) { return _fmr->readRawBits(count, _sector->clock); } Fluxmap::Position tell() { return _fmr->tell(); } void seek(const Fluxmap::Position& pos) { return _fmr->seek(pos); } /* Returns a set of sectors required to exist on this track. If the reader * sees any missing, it will consider this to be an error and will retry * the read. */ virtual std::set requiredSectors(Track& track) const; protected: virtual void beginTrack() {}; virtual RecordType advanceToNextRecord() = 0; virtual void decodeSectorRecord() = 0; virtual void decodeDataRecord() {}; FluxmapReader* _fmr; Track* _track; Sector* _sector; }; #endif