summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2012-08-12 16:50:09 (GMT)
committerH. Peter Anvin <hpa@zytor.com>2012-08-12 16:50:09 (GMT)
commit19f9717284a852044700c9f9b6bbb21b1504d47d (patch)
treee1e4eaeedcaff0c18b0fc3520b4b9f112acd8380
parent93e99986f7bf536efccc092119b7ab2e74adf182 (diff)
downloadmfmdecode-19f9717284a852044700c9f9b6bbb21b1504d47d.zip
mfmdecode-19f9717284a852044700c9f9b6bbb21b1504d47d.tar.gz
mfmdecode-19f9717284a852044700c9f9b6bbb21b1504d47d.tar.bz2
mfmdecode-19f9717284a852044700c9f9b6bbb21b1504d47d.tar.xz
Make parameters adjustable
Adjusting parameters can result in more files being extractable
-rw-r--r--mfmdecode.c34
1 files changed, 15 insertions, 19 deletions
diff --git a/mfmdecode.c b/mfmdecode.c
index 6eeec0f..7cee0e4 100644
--- a/mfmdecode.c
+++ b/mfmdecode.c
@@ -1,14 +1,10 @@
/*
- * Decode ABC80 cassette files (by H. Peter Anvin,
- * modified by Mikael O. Bonnier 2012-07-23)
+ * Decode ABC80 cassette files
*
- * Convert to samples Hz single channel 16-bit with appropriate endianness
+ * Convert to 44100 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>
@@ -17,10 +13,7 @@
#include <math.h>
#include <inttypes.h>
-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 unsigned int xtime;
static const char my_tolower[256] =
"\000\001\002\003\004\005\006\007\010\011\012\013\014\015\016\017"
@@ -76,12 +69,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) {
@@ -224,24 +217,27 @@ static void process_flank(unsigned int time)
int main(int argc, char *argv[])
{
+ unsigned int frequency;
FILE *f;
int16_t samp, osamp;
- double v;
+ double v, k, cutoff, thresh;
unsigned int state;
unsigned int time, ptime;
- 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);
+
+ frequency = (argc > 2) ? strtoul(argv[2], NULL, 0) : 44100;
+ thresh = (argc > 3) ? atof(argv[3]) : 5300.0;
+ cutoff = (argc > 4) ? atof(argv[4]) : 0.0;
+
+ k = exp(-cutoff/frequency);
+ xtime = frequency/700; /* Samples per baud */
+
state = time = ptime = 0;
samp = osamp = 0;
v = 0.0;
while (fread(&samp, 1, 2, f) == 2) {
-
/* Emulate high pass filter in ABC80 */
v = (v * k) + (samp - osamp);
osamp = samp;