OSIKCS is a utility that converts audio data stored in the Kansas City Standard format to binary, and binary to KCS audio.

The Kansas City Standard format is the cassette data format used by Ohio Scientific and other early computers. Data is stored at 300bps with 8 cycles of 2400Hz representing a '1' and 4 cycles of 1200Hz representing a '0'. Serial data is usually stored in 8bits, no parity, 2 stop bits format.
The serial stream is usually at a '1' state. A '0' start bit begins the serial word, followed by the
least significant bit to most significant data bits, ending with 1 or 2 '1' stop bits.

An optional 600bps format haves the waveform time with 4 cycles of 2400Hz representing a '1' and 2 cycles of 1200Hz representing a '0'.

For decoding the audio input file must be in Windows WAV format, either 8, 16 or 32bit signed PCM at 21600 samples per second or higher.  At a minimum it must be 21600 samples per second, 8 bit, mono.

For encoding from binary to KCS audio, the output will be ~300bps encoded @ 21600 samples per second, 8bit mono WAV file. The generated audio file uses a predefined repeating waveform and so will compress greatly.  A 3MB to 4MB generated audio file can zip compress down to 26K or so! It is possible to append to an existing WAV file that uses the same format, allowing you to create pauses between encoded sessions as needed i.e. to append data to a loader.

The encoder is based in part on Ed's (dxforth@netbay.com.au) forth Kansas City Standard/CUTS Tape Conversion Utility. Although the fixed waveform compresses well, it's slightly faster than the target frequency by about 2% but should not affect decoding by real hardware.

The decoder was created from scratch. It uses the transitions of the rising slope of the waveform along with the 2:1 ratio of the frequencies & number of cycles to extract the serial data. As long as the waveform is generally clean with a big enough amplitude, extraction should be possible.  DC offset or inconsistant zero-crossings should not be a problem as long as there is sufficient waveform amplitude.  Clipping should be avoided. The decoder auto-calibrates using the 2400Hz leader tone to adjust parameters.

OSIKCS - Transcodes between Kansas City Standard audio & data file for OSI  
Usage: OSIKCS [options] infile [outfile]
    If [outfile] is not specified, a target file is automatically
       created based on input filetype
    -Rn Rate for en/decoding 0=300/1=600 (default: 0)(600 baud decoding not stable)
    -F  Force overwrite of existing output file
    -A  Append to output file (WAV or data)(WAV must be 21600/22050[legacy mode] 8bit mono)
    Encode options:
    -B  BASIC processing -add NULS between <CR> & <LF> like OSI BASIC
    -Nn Number of Nulls (default 10)
    -O  Odd parity
    -E  Even parity
    -D  7 Data bits
    -S  1 Stop bit
    -Wn padding in msec after each serial Word
    -Pn Padding in msec after each EOL
    -Ln Leader time (in msec) defaults to 2000
    -Tn Trailer time (in msec) defaults to 1000
    -U  use sine Tone instead of precompensated square wave
    -Cn select WAV Channel for decode 0=Any 1=Left 2=Right
    -Q  Use Legacy 22050 sample rate
    -X  Decoding output diagnostics
 Default encode: create 21600 8bit mono WAV file @300 baud 8N2
 Default decode: create data file from 300 baud 8N2 WAV file
 (ver 1.3)


The -X diagnostics mode generates a stream of bits represented by '1' and '0' along with the decimal position of any decoded characters along with the character, and any Framing or Parity errors encountered.

On cassette based OSI systems, each line of BASIC is stored with a carriage return <0D> 10 NULLS <0s>, and a linefeed <0A>. This is done to allow the BASIC interpreter time to tokenize the input before getting the next line of data. When editing files on other platforms, these NULLS are generally removed or not present.
The -B option inserts these NULLS between <CR> and <LF> when encoding.
