ciderpress/app/CassetteDialog.h
Andy McFadden 51b5f00f5c Large set of changes to restore CiderPress build.
CiderPress and MDC now compile, and execute far enough to open
their respective "about" boxes, but I doubt they'll do much
more than that.

* Switch from MBCS to UNICODE APIs

Microsoft switched to UTF-16 (by way of UCS-2) a long time ago,
and the support for MBCS seems to be getting phased out.  So it's
time to switch to wide strings.

This is a bit awkward for CiderPress because it works with disk
and file archives with 8-bit filenames, and I want NufxLib and
DiskImgLib to continue to work on Linux (which has largely taken
the UTF-8 approach to Unicode).  The libraries will continue to
work with 8-bit filenames, with CiderPress/MDC doing the
conversion at the appropriate point.

There were a couple of places where strings from a structure
handed back by one of the libraries were used directly in the UI,
or vice-versa, which is a problem because we have nowhere to
store the result of the conversion.  These currently have fixed
place-holder "xyzzy" strings.

All UI strings are now wide.

Various format strings now use "%ls" and "%hs" to explicitly
specify wide and narrow.  This doesn't play well with gcc, so
only the Windows-specific parts use those.

* Various updates to vcxproj files

The project-file conversion had some cruft that is now largely
gone.  The build now has a common output directory for the EXEs
and libraries, avoiding the old post-build copy steps.

* Added zlib 1.2.8 and nufxlib 2.2.2 source snapshots

The old "prebuilts" directory is now gone.  The libraries are now
built as part of building the apps.

I added a minimal set of files for zlib, and a full set for nufxlib.
The Linux-specific nufxlib goodies are included for the benefit of
the Linux utilities, which are currently broken (don't build).

* Replace symbols used for include guards

Symbols with a leading "__" are reserved.
2014-11-16 21:01:53 -08:00

161 lines
5.1 KiB
C++

/*
* CiderPress
* Copyright (C) 2007 by faddenSoft, LLC. All Rights Reserved.
* See the file LICENSE for distribution terms.
*/
/*
* Apple II cassette I/O functions.
*/
#ifndef APP_CASSETTEDIALOG_H
#define APP_CASSETTEDIALOG_H
/*
* The dialog box is primarily concerned with extracting the original data
* from a WAV file recording of an Apple II cassette tape.
*/
class CassetteDialog : public CDialog {
public:
CassetteDialog(CWnd* pParentWnd = NULL) :
CDialog(IDD_IMPORTCASSETTE, pParentWnd), fDirty(false)
{}
virtual ~CassetteDialog(void) {}
CString fFileName; // file to open
bool IsDirty(void) const { return fDirty; }
private:
virtual BOOL OnInitDialog(void);
//virtual void DoDataExchange(CDataExchange* pDX);
//virtual void OnOK(void);
//enum { WMU_DIALOG_READY = WM_USER+2 };
afx_msg void OnListChange(NMHDR* pNotifyStruct, LRESULT* pResult);
afx_msg void OnListDblClick(NMHDR* pNotifyStruct, LRESULT* pResult);
afx_msg void OnAlgorithmChange(void);
afx_msg void OnHelp(void);
afx_msg void OnImport(void);
/*
* This holds converted data from the WAV file, plus some meta-data
* like what type of file we think this is.
*/
class CassetteData {
public:
CassetteData(void) : fFileType(0x00), fOutputBuf(nil), fOutputLen(-1),
fStartSample(-1), fEndSample(-1), fChecksum(0x00),
fChecksumGood(false)
{}
virtual ~CassetteData(void) { delete[] fOutputBuf; }
/*
* Algorithm to use. This must match up with the order of the items
* in the dialog IDC_CASSETTE_ALG combo box.
*/
typedef enum Algorithm {
kAlgorithmMIN = -1,
kAlgorithmZero = 0,
kAlgorithmSharpPeak,
kAlgorithmRoundPeak,
kAlgorithmShallowPeak,
kAlgorithmMAX
} Algorithm;
bool Scan(SoundFile* pSoundFile, Algorithm alg, long* pSampleOffset);
unsigned char* GetDataBuf(void) const { return fOutputBuf; }
int GetDataLen(void) const { return fOutputLen; }
int GetDataOffset(void) const { return fStartSample; }
int GetDataEndOffset(void) const { return fEndSample; }
unsigned char GetDataChecksum(void) const { return fChecksum; }
bool GetDataChkGood(void) const { return fChecksumGood; }
long GetFileType(void) const { return fFileType; }
void SetFileType(long fileType) { fFileType = fileType; }
private:
typedef enum Phase {
kPhaseUnknown = 0,
kPhaseScanFor770Start,
kPhaseScanning770,
kPhaseScanForShort0,
kPhaseShort0B,
kPhaseReadData,
kPhaseEndReached,
// kPhaseError,
} Phase;
typedef enum Mode {
kModeUnknown = 0,
kModeInitial0,
kModeInitial1,
kModeInTransition,
kModeAtPeak,
kModeRunning,
} Mode;
typedef struct ScanState {
Algorithm algorithm;
Phase phase;
Mode mode;
bool positive; // rising or at +peak if true
long lastZeroIndex; // in samples
long lastPeakStartIndex; // in samples
float lastPeakStartValue;
float prevSample;
float halfCycleWidth; // in usec
long num770; // #of consecutive 770Hz cycles
long dataStart;
long dataEnd;
/* constants */
float usecPerSample;
} ScanState;
void ConvertSamplesToReal(const WAVEFORMATEX* pFormat,
const unsigned char* buf, long chunkLen, float* sampleBuf);
bool ProcessSample(float sample, long sampleIndex,
ScanState* pScanState, int* pBitVal);
bool ProcessSampleZero(float sample, long sampleIndex,
ScanState* pScanState, int* pBitVal);
bool ProcessSamplePeak(float sample, long sampleIndex,
ScanState* pScanState, int* pBitVal);
bool UpdatePhase(ScanState* pScanState, long sampleIndex,
float halfCycleUsec, int* pBitVal);
enum {
kMaxFileLen = 65535+2+1+1, // 64K + length + checksum + 1 slop
};
long fFileType; // 0x06, 0xfa, or 0xfc
unsigned char* fOutputBuf;
int fOutputLen;
long fStartSample;
long fEndSample;
unsigned char fChecksum;
bool fChecksumGood;
};
bool AnalyzeWAV(void);
void AddEntry(int idx, CListCtrl* pListCtrl, long* pFileType);
enum {
kMaxRecordings = 100, // max A2 files per WAV file
};
/* array with one entry per file */
CassetteData fDataArray[kMaxRecordings];
CassetteData::Algorithm fAlgorithm;
bool fDirty;
DECLARE_MESSAGE_MAP()
};
#endif /*APP_CASSETTEDIALOG_H*/