summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMikael Bonnier <mikaelb@df.lth.se>2012-08-12 16:49:46 (GMT)
committerH. Peter Anvin <hpa@zytor.com>2012-08-12 16:49:46 (GMT)
commit93e99986f7bf536efccc092119b7ab2e74adf182 (patch)
tree77ca9792e3512b0f5529855a35c87e4d859715ec
parent9d7cdd8ed9e4645548b87b7224dc0356e2d8cf13 (diff)
downloadmfmdecode-93e99986f7bf536efccc092119b7ab2e74adf182.zip
mfmdecode-93e99986f7bf536efccc092119b7ab2e74adf182.tar.gz
mfmdecode-93e99986f7bf536efccc092119b7ab2e74adf182.tar.bz2
mfmdecode-93e99986f7bf536efccc092119b7ab2e74adf182.tar.xz
Improvements by Mikael Bonnier
-rw-r--r--mfmdecode.c34
1 files changed, 20 insertions, 14 deletions
diff --git a/mfmdecode.c b/mfmdecode.c
index e092bdc..6eeec0f 100644
--- a/mfmdecode.c
+++ b/mfmdecode.c
@@ -1,10 +1,14 @@
/*
- * Decode ABC80 cassette files
+ * Decode ABC80 cassette files (by H. Peter Anvin,
+ * modified by Mikael O. Bonnier 2012-07-23)
*
- * Convert to 44100 Hz single channel 16-bit with appropriate endianness
+ * Convert to samples Hz single channel 16-bit with appropriate endianness
* and normalized gain first:
*
* sox muzak.wav --endian little -c 1 -s muzak.raw
+ * mfmdecode muzak.raw 44100 5300
+ *
+ * This program doesn't work with 96 kHz.
*/
#include <stdio.h>
@@ -13,8 +17,10 @@
#include <math.h>
#include <inttypes.h>
-#define THRESH 14300
-static unsigned int xtime = 44100/700; /* Samples/baud */
+static unsigned int thresh; /* threshold e.g. 5300 */
+static unsigned int samples; /* sample frequency in Hz e.g. 44100 or 96000
+*/
+static unsigned int xtime; /* samples/baud */
static const char my_tolower[256] =
"\000\001\002\003\004\005\006\007\010\011\012\013\014\015\016\017"
@@ -70,12 +76,12 @@ static void output_block(uint8_t *buf, uint8_t *csum)
csum1 = 0x03; /* Checksum includes ETX */
for (i = 0; i < 256; i++)
csum1 += buf[i];
-
+
if (csum1 == csum2) {
if (!memcmp(buf, "\xff\xff\xff", 3)) {
if (f)
fclose(f);
-
+
unmangle_filename(filename, buf+3);
f = fopen(filename, "wb");
if (!f) {
@@ -223,30 +229,30 @@ int main(int argc, char *argv[])
double v;
unsigned int state;
unsigned int time, ptime;
- const double k = exp(-10000.0/44100);
+ double k;
f = fopen(argv[1], "rb");
-
+ sscanf(argv[2], "%u", &samples);
+ sscanf(argv[3], "%u", &thresh);
+ xtime = samples/700;
+ k = exp(-10000.0/samples);
state = time = ptime = 0;
samp = osamp = 0;
v = 0.0;
while (fread(&samp, 1, 2, f) == 2) {
+
/* Emulate high pass filter in ABC80 */
-#if 0
v = (v * k) + (samp - osamp);
-#else
- v = samp;
-#endif
osamp = samp;
- if (v >= THRESH) {
+ if (v >= thresh) {
if (!state) {
state = 1;
process_flank(time - ptime);
ptime = time;
}
- } else if (v <= -THRESH) {
+ } else if (v <= -thresh) {
if (state) {
state = 0;
process_flank(time - ptime);