Re: Prog to convert .WAV to .PRG or .TXT

From: Marko Mäkelä <msmakela_at_gmail.com>
Date: Sun, 19 Nov 2017 11:03:04 +0200
Message-ID: <20171119090304.xdjwlcrny7jz2uji@hp>
On Sat, Nov 18, 2017 at 06:11:57PM -0500, Mike Stein wrote:
>A friend would like to convert some cassette tape .WAV files to binary 
>(PRG) or text files; any recommendations that work well?

I made some experiments with that in 2005. If you have a Commodore tape 
drive, you can attach it to a computer's GPIO interface and use a 
program to copy the stream of pulses. Back in 2005, one solution was 
MTAP that used the PC parallel port. Maybe it even decoded the pulse 
stream on the fly. A modern single-board computer such as the Raspberry 
Pi should definitely be up to this task.

But, you say that there already are .wav files. If I reemember 
correctly, that was my choice in 2005 too. I remember digitizing the 
analog output of an audio cassette player and then feeding the PCM files 
(let's say 44.1kHz, 8 or 16 bits per sample) as .wav files to TAPir 
http://tapir.sourceforge.net/ which converted them to .tap images 
(containing pulse durations, measured in microseconds, if I remember 
correctly). I used my own c2n232 tool to decode the pulse stream into a 
tape image. On tapes, programs are stored in a slightly different format 
than on disk. The format is like this:

1. Pilot tone
2. 192-byte tape header with the file name and the start and end addresses
3. Another copy of the 129-byte tape header
4. Short pilot tone
5. The program code (the size depends on what was in the tape header)
6. Another copy of the program code

The .prg format does not store the file name. It consists of a 2-byte 
header (start address in little-endian format) followed by the data 
bytes.

You can use the petcat utility from the VICE emulator to convert BASIC 
programs from .prg to text format.

Some tapes that I archived in this way were badly corrupted, so I had to 
manually edit the binary output, and use both copies of the data as 
reference. I might have tweaked the decoding algorithm as well. One of 
the programs that I resurrected was published by a Finnish bank in the 
1980s. It was mostly written in BASIC, and I also used the disk version 
of the program as reference. For editing the binaries, I used GNU Emacs, 
which happily allows one to edit binary files, even though it primarily 
is a text editor.

I hope that this helps. And I wish you and your friend good luck; if my 
tapes were slightly unreadable after 20 years 12 years ago, the 
situation may only become worse as time passes. You might also want to 
re-read the tapes after adjusting the head position or angle. A live 
histogram display of the decoded pulse durations would help with that.  
(Commodore uses 3 distinct pulse durations; fastloaders tend to use 2.)

	Marko

       Message was sent through the cbm-hackers mailing list
Received on 2017-11-19 10:00:03

Archive generated by hypermail 2.2.0.