ciderpress/app/CassetteDialog.h

232 lines
7.4 KiB
C
Raw Normal View History

2007-03-27 17:47:10 +00:00
/*
* CiderPress
* Copyright (C) 2007 by faddenSoft, LLC. All Rights Reserved.
* See the file LICENSE for distribution terms.
*/
/*
* Apple II cassette I/O functions.
*/
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-10 23:32:55 +00:00
#ifndef APP_CASSETTEDIALOG_H
#define APP_CASSETTEDIALOG_H
2007-03-27 17:47:10 +00:00
/*
* 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) {}
2007-03-27 17:47:10 +00:00
CString fFileName; // file to open
2007-03-27 17:47:10 +00:00
bool IsDirty(void) const { return fDirty; }
2007-03-27 17:47:10 +00:00
private:
virtual BOOL OnInitDialog(void) override;
//virtual void DoDataExchange(CDataExchange* pDX);
//virtual void OnOK(void);
//enum { WMU_DIALOG_READY = WM_USER+2 };
/*
* Something changed in the list. Update the "OK" button.
*/
afx_msg void OnListChange(NMHDR* pNotifyStruct, LRESULT* pResult);
/*
* The volume filter drop-down box has changed.
*/
afx_msg void OnAlgorithmChange(void);
/*
* User pressed "import" button. Add the selected item to the current
* archive or disk image.
*/
afx_msg void OnImport(void);
afx_msg void OnListDblClick(NMHDR* pNotifyStruct, LRESULT* pResult);
afx_msg void OnHelp(void) {
MyApp::HandleHelp(this, HELP_TOPIC_IMPORT_CASSETTE);
}
/*
* This holds converted data from the WAV file, plus some meta-data
* like what type of file we think this is.
*/
class CassetteData {
public:
2014-11-18 05:13:13 +00:00
CassetteData(void) : fFileType(0x00), fOutputBuf(NULL), 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;
/*
* Scan the WAV file, starting from the specified byte offset.
*
* Returns "true" if we found a file, "false" if not (indicating that the
* end of the input has been reached). Updates "*pStartOffset" to point
* past the end of the data we've read.
*/
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;
/*
* Convert a block of samples from PCM to float.
*
* Only the first (left) channel is converted in multi-channel formats.
*/
void ConvertSamplesToReal(const WAVEFORMATEX* pFormat,
const unsigned char* buf, long chunkLen, float* sampleBuf);
/*
* Process one audio sample. Updates "pScanState" appropriately.
*
* If we think we found a bit, this returns "true" with 0 or 1 in "*pBitVal".
*/
bool ProcessSample(float sample, long sampleIndex,
ScanState* pScanState, int* pBitVal);
/*
* Process the data by measuring the distance between zero crossings.
*
* This is very similar to the way the Apple II does it, though
* we have to scan for the 770Hz lead-in instead of simply assuming the
* the user has queued up the tape.
*
* To offset the effects of DC bias, we examine full cycles instead of
* half cycles.
*/
bool ProcessSampleZero(float sample, long sampleIndex,
ScanState* pScanState, int* pBitVal);
/*
* Process the data by finding and measuring the distance between peaks.
*/
bool ProcessSamplePeak(float sample, long sampleIndex,
ScanState* pScanState, int* pBitVal);
/*
* Given the width of a half-cycle, update "phase" and decide whether or not
* it's time to emit a bit.
*
* Updates "halfCycleWidth" too, alternating between 0.0 and a value.
*
* The "sampleIndex" parameter is largely just for display. We use it to
* set the "start" and "end" pointers, but those are also ultimately just
* for display to the user.
*/
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;
};
/*
* Analyze the contents of a WAV file.
*
* Returns true if it found anything at all, false if not.
*/
bool AnalyzeWAV(void);
/*
* Add an entry to the list.
*
* Layout: index format length checksum start-offset
*/
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()
2007-03-27 17:47:10 +00:00
};
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-10 23:32:55 +00:00
#endif /*APP_CASSETTEDIALOG_H*/