# TAK Applications

(T)om's lossless (A)udio (K)ompressor.

Version: TAK 2.0.0, 2010-01-07

Copyright 2006 by Thomas Becker, D-49080 Osnabrück.
All rights reserved.

## Contents

#### Chapters

- License
- About TAK
- Applications with TAK support
- Compressing files with the GUI version
- Decompressing files with the GUI version
- Viewing file info with the GUI version
- Command line version TAKC
- History

#### Some prominent topics

- Pipe encoding
- Wave file meta data
- Decompressor error log file "Tak_Deco_Error.txt"

## License

This software is provided as FREEWARE, but only for private, non-commercial use. It's also free for educational and scientific use and for use in charity and humanitarian organisations.

## Disclaimer of warranty

The software is provided "as is" without warranty of any kind. To the maximum extent permitted by applicable law, the author further disclaims all warranties, including without limitation any implied warranties of merchantability, fitness for a particular purpose, and non-infringement. The entire risk arising out of the use or performance of the product and documentation remains with recipient.

To the maximum extent permitted by applicable law, in no event shall the author be liable for any consequential, incidental, direct, indirect, special, punitive, or other damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of this agreement or the use of or inability to use the product, even if the author has been advised of the possibility of such damages.

## Distribution

The Software may be freely distributed provided that it is not modified and the original archive remains intact with all accompanying files, and provided that no fee is charged (except for any reasonable fees necessary to cover costs of distribution media).

## Contact

I am frequently active in the Lossless Audio Compression forum at Hydrogen Audio; a good place to ask questions regarding TAK.

My homepage, www.thbeck.de, contains some information about TAK, but unfortunately only in German.

If you would like to contact me by email please be aware that I will not always have time to answer.

## Thank you

Thank you to all the people who have supported the development of TAK, most of whom are members of Hydrogen Audio.

Firstly, they have provided encouragement to build yet another lossless audio compressor. Otherwise I would have dropped the whole project!

They helped to evaluate and optimize TAK. There have been 13 releases over a period of 8 months before the alpha version, and all of them have been evaluated by those testers!

# About TAK

TAK is a lossless audio compressor, similar to FLAC, WavPack and Monkey's Audio. On average, lossless compression reduces the file size to about 50 percent of the original size; however the compression can vary between approximately 30 and 70 percent, depending on the file. Decompression restores a bit identical copy of the original audio data (that's why we call it lossless).

My goal was to develop a compressor which combines good compression with optimal decoding speeds. On average, the current implementation should match the compression efficiency of Monkey's Audio High, while achieving decompression speeds similar to FLAC.

## Features

- Good compression. The strongest mode is on par with Monkey's Audio High and OptimFrog Normal. With classical music, jazz or speech the compression is often significantly better. This classification is based upon the evaluation of hundreds of files of different genres; it may not be the case for every file that you compress.
- Fast compression speed. Currently I know of no other compressor which compresses faster than TAK's 0, 1 and 2 modes, while providing similar compression ratios.
- Very fast decompression speed. The decoding speeds achieved are similar to those achieved by FLAC.
- Support for any common audio format (not fully implemented).
- Streaming support. An info frame, which contains all the information required to decompress a file, is inserted into the compressed audio data every 2 seconds.
- Error tolerance. A single bit error will never affect more than 250 ms of the audio data, as the compressed data is being stored in independent frames no more than that duration. The decoder is able to decompress even badly damaged files, by removing corrupt frames or replacing them with silence.
- Error detection. Each single frame is protected by a 24-bit checksum (CRC). Optionally a MD5 checksum of the raw (unencodeded) audio can be added.
- Fast and sample accurate seeking.
- Meta data. A flexible and extensible structure in which to embed non audio data.
- A Winamp and a Foobar plugin are available.
- A SDK for other developers is available.

## Missing features

Some important features are missing in this release. Please find below my current to-do list (in order of my current priority):

- Encoding on multiple cores.
- Store cover art in APEv2 tags.
- Raw audio data files as input for the encoder.
- Option to decode only a specific part of a file.
- Unicode support.
- Even more speed and better compression.
- Applications for other operating systems than Windows.
- TAK files as input for the encoder for transcoding purposes.
- Multi channel audio.
- A german version.

## Supported file formats

Only Wave for now.

As the streaming format is only partially implemented, and because some less common formats need some more fine tuning and verification, only a subset of the possible audio formats are supported in this version: Sample rates from 8000 to 192000 Hz. Bit depths of 8, 16 or 24. Channels: Mono or Stereo.

The final implementation should support 8 to 24 bits per sample and up to 16 Channels.

Wave files may be up to 4 GB in size (to be exact: 4 GB minus 15 bytes for now). Unfortunately some applications partition the audio data in chunks of 2 GB size, if the source data is bigger than 2 GB. This is against the Wave file format standard and currently not supported by TAK.

## Tagging

While TAK now supports tagging on its own (APEv2 located at the end of the file), it still does not support unicode characters on the command line.

Please note, the current decompressor will throw an error message if you have prepended tags to the beginning of the file. This may be fixed in later releases.

## GUI and command line version

The archive contains two versions of TAK:

- Tak.exe is the dialog oriented GUI (Graphical User Interface) version.
- Takc.exe is the command line version.

# Applications with TAK support

### Exact Audio Copy (EAC) - Audio grabber

Can save the audio data as TAK files. Guides:

- EAC and TAK at Hydrogenaudio.org

### Foobar2000 - Audio player

Encoding, decoding, tagging and playback. Guides and plugins:

- TAK Wiki at hydrogenaudio.org
- Playback plugin: Foosion's foobar2000 stuff (TAK Decoder)

### GermaniX Transcoder

Transcoding.

### Mp3tag - Tag Editor

Supports TAK since V 2.38.

### Quintessential Player - Media Player

Playback of TAK files. Requires this plugin.

### shntool

Processing and analysis of (compressed) WAVE-audio files.

### Winamp - Media Player

Playback of TAK files. Requires my Winamp plugin.

### XMPlay - Audio Player

Playback of TAK files. Requires my Winamp plugin.

### xrecode II

Transcoding.

# Compressing files with the GUI version

## File management

Compression creates files with the same name as the source, but with the extension '.tak':

        Sample.wav -> Sample.tak

By default existing files will not be overwritten.

## Quick tour

- Use "Add files" to select the files to compress. This does not work cumulatively; further selections will replace the previous selection.
- "Compress" starts the compression process. "Stop" cancels the process. Use "Test" to compress the files without creating any output - useful if you just want to check the potential compression ratio.

#### Warnings and errors

If there are any problems with a file you will see a short message following the file name:

Message | Description
Meta data too big | The non-audio wave file meta data was bigger than 1 MByte, and could not be stored in the file. The audio data itself is intact.
Audio format not supported | The current encoder implementation cannot handle the source audio format.
Wave file not supported | My wave file reader was not able to parse the wave container, or the source file structure is damaged.
Error reading source | A source I/O error occurred.
Error writing destination | A destination I/O error occurred.
Verify failed! | This will only happen with Verify enabled. Possible reasons: A bug in the encoder, or instable hardware.
Already exists | The destination file already exists, and you have not specified the Overwrite option.

## Options

The Options dialog lets you choose encoder options like the preset, which determines compression efficiency, encoding and decoding speed. Furthermore you can modify stream properties and specify output options like for instance the destination directory.

## Encoder options

### Presets

The table contains 15 rows. Each is representing one encoder preset, which affects compression efficiency, encoding and decoding speed. You select a preset with a mouse click.

Each preset selects a set of internal encoder options. Some of them affect only the encoding speed, the others also the decoding speed.

Slower decoding usually means higher hardware requirements (memory size and/or cpu power) for a playback device. Some devices may be too weak to support the more demanding internal encoder options. But any option, which only affects the encoding speed and complexity, is always applicable.

Therefore each preset consists of two components:

- The profile selects internal encoder options which affect both encoding and decoding speed. Profiles are declared as a number from 0 to 4 (fastest to strongest).
- The evaluation level selects only internal encoder options, which have no effect on the decoding speed. The evaluation levels are named Standard, Extra and Max and abbreviated as s, e and m (fastest to strongest).

Presets are beeing declared as a combination of the profile and the abbreviated evaluation level (if not specified Standard is beeing used): 0 is the fastest, 4m the strongest setting.

Put a -p in front of the preset and you get the corresponding command line parameter for TAKC, which is also used in the table as name for the preset.

A hardware manufacturer supporting TAK has only to specify the strongest profile it's hardware can decode, because the evaluation level does not affect the hardware requirements.

Hint: If you want higher compression and fast encoding, and are able to accept some decrease in decoding speed, it is usually preferable to select a higher profile instead of increasing the evaluation level.

#### Comparison

The table contains results from my primary test file set to give you an idea of the effect of profiles and evaluation levels on compression efficiency, encoding and decoding speed. Depending on your files and system you may get quite different results!

The data in columns 2 to 4 is always relative to the currently selected preset:

Compression difference tells you, how much better (positive values) or worse (negative values) the other presets performed. Example: if 2 is selected (Default), you can see, that 4 + MAX achieved 1.00 percent better compression on my file set. Percentage values always refer to the original, uncompressed file size.

Encoding/Decoding speed: How much faster / slower are the other presets on encoding / decoding.

## Details

The Details dialog let's you modify some internal encoder options.

### Frame Size Limit

The Frame size is defined as samples per channel. The encoder first calculates the frame size for the preset's Frame Duration and then compares the resulting sample count with the Frame Size Limit value. If it's bigger, it will be limited. An Example:

Profile 0 is using a Frame Duration of 94 ms. CD-Audio has a sample rate of 441000. 44100 * 0.094 = 4145 samples. This value is bigger than the profile's Frame Size Limit and will therefore be limited to 4096.

Caution: if you increase the frame size limit, you are breaking the profile's specification! Some hardware players may not have enough memory to decode the bigger frames. Decreasing the frame size usually reduces the compression efficiency.

There is only one situation where you are adviced to change the frame size limit: If you want to encode files generated by the high quality LossyWav- preprocessor, Tak's frame size has to match the preprocessors frame size (usually 512 samples). For more information about LossyWave please read those threads at Hydrogenaudio.org: Near-lossless / lossy FLAC, An idea & MATLAB implementation and lossyWAV Development, WAV bit reduction by 2BDecided.

Another warning: Frame Size Limit's of 512, 1024 and 2048 are not backwards compatible and can not be decoded by TAK applications and libraries prior to V1.0.2!

### Verify

With Verify enabled, any compressed frame is subsequently decompressed and then compared to the original data. This reduces encoding speed, but is useful for the more paranoid among us!

## Stream

#### Wave file meta data

When decompressing TAK always generates a bit identical copy of the audio data of the original wave file. Nevertheless, the resulting wave file may be different from the original!

This is because a wave file contains not only raw audio data, but also some header structures describing the audio format, and sometimes additional data which is not needed for the playback - for instance meta information created by the application that created the original wave.

Even if there is no additional (dropped) information besides the wave header, the wave file created by the decoder can be different from the original. This is because there are several different ways to create a valid wave header describing the same audio format. TAK may use an alternative to the creator of the original wave.

All this does not affect the validity of the audio data itself. It will always be bit identical to the original!

By default TAK will store up to 1 MByte of non-audio data into the compressed file. This guarantees a bit identical reproduction of the whole wave file, including the non-audio data.

### Maximum size

Specify a maximum size for the meta data. If it is bigger, it will not be be copied into the TAK file.

### Add MD5

Check this option if you want TAK to calculate a MD5 checksum of the raw (unencoded) audio data excluding headers or other meta data contained in the source file. The MD5 will be stored in the meta data section of the compressed file. Depending on the preset, the calculation may result in a noticable slow down of the encoding process.

Why you may want to add an MD5:

- It's an approved standard to identify audio files. Here it serves as a fingerprint of the audio data. Some software is using it to check your file collection for duplicates.
- On decoding TAK will optionally calculate an MD5 of the decoded audio data and compare it with the checksum stored in the compressed file. If the checksums don't match, something went wrong. I wouldn't regard this as very useful, because TAK is already protecting each single frame with a CRC24 checksum. The MD5 will add little to the error detection capability.

## Output

### Destination

Where should the compressed files be stored:

- in the same directory as the source files, or
- in a user-specified directory. After selecting this option you can select Browse to select the directory.
  NB: The selection dialog is a bit different from the standard Windows dialogs. The treeview does not show plus symbols, which can usually be clicked to show directories located within the parent folder. Here you have to perform a double click on the directory name to open it.

### !!! Overwrite existing TAK files !!!

Enable this option to overwrite already existing TAK files; otherwise they will be skipped. You will not be asked for a confirmation!

#### Protocol

TAK can save information about the compression process in the protocol file "Tak_Enco_Proto.txt", which will be created in the output directory.

### Level

What should be stored into the protocol file:

- Off: Don't generate a protocol file.
- Result: Save a copy of the screen output.
- Result & Diagnostics: Save results and settings. Not supported in public releases.

### Append

Append new protocol data to an existing protocol file, instead of overwriting it.

### Use MMX

Uses MMX-assembler instead of pure Pascal on the most time consuming functions. Increases speed performance.

This option affects the Decoder too! It should really be in a new General Options dialog...

# Decompressing files with the GUI version

## File management

Decompression creates files with the same name as the source and the extension '.wav':

        Sample.tak -> Sample.wav

By default existing files will not be overwritten.

## Quick tour

- Use "Add files" to select the files to decompress. This does not work cumulatively; further selections will replace the previous selection.
- "Decompress" starts the decompression process. "Stop" cancels the process. Use "Test" to decompress the files without creating any output - useful if you just want to check file integrity.

#### Warnings and errors

If there are any problems with a file you will see a short message following the file name:

Message | Description
Invalid Stream-ID | The Stream-ID (indicating that this is a TAK file) at the beginning of the file is damaged, but everything else is intact.
Stream info damaged | The stream info meta data is damaged, but everything else is intact.
Meta data damaged | One or more of the meta data structures are damaged, but the audio data is intact.
Stream structure damaged | The stream part containing the audio data had errors, but the audio data itself is intact.
Frame(s) damaged | At least one audio data frame is damaged.
Undecodable | Too many errors. The file cannot be decoded (it possibly isn't a TAK-file). Occasionally it is worth trying again, with the Restore wave file meta data-option disabled.
Audio format not supported | The file has been created with a newer encoder, which is able to handle more audio formats than the decoder you are using.
Incompatible version | The file has been created with a newer encoder, which uses compression methods not supported by the decoder you are using.
Error reading source | A source I/O error occurred.
Error writing destination | A destination I/O error occurred.
Already exists | The destination file already exists and you have not specified the Overwrite option.

## Options

The Options dialog gives you access to a few decoder options.

### Destination

Where should the decompressed files be stored:

- in the same directory as the source files or
- in a user-specified directory. After selecting this option you can press Browse to select the directory.
  NB: The selection dialog is a bit different from the standard Windows dialogs. The treeview does not show plus symbols, which can usually be clicked to show directories located within the parent folder. Here you have to perform a double click on the directory name to open it.

### !!! Overwrite existing wave files !!!

Enable this option to overwrite already existing wave files; otherwise they will be skipped. You will not be asked for a confirmation!

### Restore wave file meta data

Enable this option to write the non-audio meta data of the original wave file into the decompressed file.

This only works if the compressed file has been created with the encoder option "Save wave file meta data" enabled, and the meta data was not larger than 1 MByte.

### Check Md5

Enable this option if you want TAK to calculate a MD5 checksum of the decoded audio data and compare it with the one stored in the compressed file.

This only works if the compressed file has been created with the encoder option "Add Md5" enabled.

Depending on the preset, the calculation may result in a noticable slow down of the decoding process.

## Error handling

How should errors caused by damaged files be handled?

Important: You will sometimes have to disable the "Restore wave file meta data" option to decode a damaged file!

### Files

Select Skip, if you don't want to decompress damaged files. If you select Recover TAK will attempt to recover as much of the audio data as possible.

### Frames

Specify what should be done if the decompressor finds a damaged block of audio data within the file:

- Skip the damaged data. Nothing is inserted between the previous and the next intact audio data frames. This is likely to generate a clicking sound when playing.
- Mute replaces the damaged data with a frame of silence.

### Save error log

If enabled, an error log is saved to the file "Tak_Deco_Error.txt".

#### Protocol

TAK can save information about the decompression process in the protocol file "Tak_Deco_Proto.txt", which will be created in the output directory.

### Level

What should be stored into the protocol file:

- Off: Don't generate a protocol file.
- Result: Save a copy of the screen output.

# Decompressor error log file

This section describes the content of the Decompressor error log file "Tak_Deco_Error.txt".

An entry is created for each damaged file:

    --- 41_30sec_No head - No tail.tak ---

    Result
      Audio data damaged

    Stream components
      File-ID damaged
      StreamInfo damaged
      Meta data damaged
      First frame not found

    Audio data
      Size in samples:     1323001
      Damaged samples:       12523
        Muted samples:       12523
        Cut   samples:           0
      Damaged blocks :           2

    Damaged data blocks

    No       Position    Size
           1           0        4134
           2     1314612        8389

Sections:

- The overall result.
- Info about damages of non-audio stream components.
- An overview of damages of the audio data.
- A detailed list of damaged data blocks in the audio data.

#### Audio data

contains:

- The stream size in samples including damaged samples. Important: If the stream components section contains the error "Audio size unknown", this value maybe inaccurate. Can only happen if the file has been created via pipe encoding and with the -ihs switch applied.
- The count of damaged samples.
- Damaged samples can be muted (replaced with silence) or cut (taken out of the file).
- The count of damaged blocks which have been skipped. Each block contains one or more undecodable frames.

#### Damaged data blocks

contains a list of defective data blocks. Each block is characterized by it's position and size within the decompressed (wave) file in samples. With this information it is easy to find the affected file parts within an audio editor.

# Viewing file info with the GUI version

This command will show you some useful information about compressed TAK files, which can optionally be written to a protocol file. Operation is nearly identical to decompressing files.

Example output for one file:

    === waiting.tak ===============================================

      File size:                     2.19 MB
      Header size:                   0.24 KB
        Unused:                      0.00 KB
      Compression:                  64.46 %
      Samples per channel:         888832
      File duration:                20.15 sec
      Frame duration:                 125 ms
      Seek table:              Yes
      Audio format:            PCM, 44100 Hz, 16 Bits, 2 Channels
      Encoder:                 V 1.1.0, -p2
      Wave file meta data:     Header 44, Footer 0 Bytes
      MD5:                     00c29080dc2892f24b712b86fea12f87
      APEv2-Tag:               No
      Status:                  Ok

Items:

- The compressed File size in MByte (1024 * 1024 Bytes).
- The Header size in KByte (1024 Bytes). The Header contains meta data structures and the seek table.
- The size of Unused data in the header in KByte. Currently can only be non-zero if the file has been created via pipe encoding.
- The Compression ratio in percent of the original file size.
- The count of Samples per channel.
- The File duration in seconds.
- The Frame duration in milliseconds. A single bit error will never affect more of your audio data.
- Contains the file a since V1.1.1 obsolete Seek table?.
- A description of the Audio format.
- Information about the Encoder, which compressed this file: Encoder version and preset. For files generated with TAK 1.0 the evaluation level is unknown.
- The sizes of leading and trailing Wave file meta data in bytes.
- If available, the MD5 checksum of the raw audio data.
- If available, the size and item count of the APEv2-Tag located at the end of the file.
- Status: Ok or an error message.

## Options

The Options dialog lets you choose the information to show:

- Any information creates the output above.
- Encoder outputs only the encoder version and the preset.
- Wave meta data outputs only the wave meta data sizes.
- Md5 outputs only the MD5 checksums.

If you check the Save protocol option, any output will be saved to a protocol file named "Tak_Info_Proto.txt" located in the source file directory.

# Command line version TAKC

## Parameters

    TAKC -mode [-p# -fsl# -wm# -md5 -ihs -v -overwrite -fim# -l# -silent -w -lp]
         [-tt #] infile [outfile]

    -mode      -e encode, -d decode, -t test decode, -te test encode,
               -fi file information
    -p#        select encoder preset #: 0-4 (fastest to strongest, default is 2).
               Append E/M (-p2m) to increase the evaluation level to Extra/Max.
               pMax is a synonym for the strongest setting.
    -fsl#      Set the frame size limit to # samples per channel. Valid values:
                 512, 1024, 2048, 4096, 8192, 16384
    -wm#       Control saving(encode)/restoring(decode) of wave file meta data:
                 0 = disable
                 1 = enable and use default values for maximum size (default)
                 46 to 1048576 = enable and set maximum size (encoding only)
    -md5       add (encoding) / verify (decoding) MD5 of the raw wave data
    -ihs       ignore (wave) header size entry (pipe encoding only)
    -v         verify encoded frames (when encoding)
    -overwrite overwrite existing output files (without confirmation!)
    -fim#      select file information mode #
                 0 = any information (default)
                 1 = encoder
                 2 = wave meta data
                 3 = MD5
    -l#        select log file level #
                 0 = no log file (default)
                 1 = log results
                 Append A (-l1a) to append new results to an existing file.
    -silent    silent operation: Write nothing to StdOut/the screen.
    -w         wait for enter key when finished
    -lp        Execute with low priority. Nice for background processing.
    -tt #      Add textual tag item #, where # is a key/value pair: "key=value",
               for instance "TITLE=A nice song". "key=@file" will read the value
               from the text(!) file "file" in the source directory.
    infile     Specify file or directory (Dir\*) to be processed.
               - selects StdIn (encoding only, requires outfile specification).
    outfile    Specify output file or directory (Dir\*).
               - selects StdOut (decoding only, requires infile specification).

### -mode

What should the program do:

- -e: Encode (compress) files.
- -d: Decode (decompress) files.
- -t: Test files. Files are decoded to check their integrity, but no output file is created.
- -te: Test-encode files. Check the potential compression ratio, but do not create an output file.
- -fi: Show file information.

### -p#

Select an encoder preset. Default is -p2.

### -fsl#

Set the Frame Size Limit to one of the listed values.

### -wm#

Specify 1/0 to enable(default)/disable saving(encode)/restoring(decode) of non-audio wave file meta data. Please read the description of the GUI version for the options Wave file meta data and Restore wave file meta data.

On encoding you may also specify a maximum size (46 to 1,048,576 bytes) for the meta data, for example:

    -wm1024

limits the meta data size to 1024 Bytes. If it is bigger, it will be ignored.

The default value selected by -wm1 depends on the encoding mode:

- When encoding from a file the maximum size is set to 1,048,576 bytes.
- When encoding from a pipe without the -ihs switch applied the maximum size is set to 46 bytes.
- When encoding from a pipe with the -ihs switch applied no meta data can be saved.

### -md5

On encoding (-e): Calculate a MD5 checksum of the raw audio data and store it in the compressed file.

On decoding (-d, -t): Calculate a MD5 checksum of the decoded audio data and compare it with the Md5 stored in the compressed file.

### -ihs

Ignore the (wave) header size entry in the source file. Only valid when pipe encoding.

### -v

Enables Verify: Any compressed frame is subsequently decompressed and then compared to the original data. This reduces encoding speed, but is useful for the more paranoid among us!

### -overwrite

By default already existing output files will not be overwritten. Specify this option to enable overwriting. You will not be asked for a confirmation!

### -fim#

Select the file information to show.

### -l#

Specify the log (protocol) file level.

### -silent

Silent operation: Write nothing to StdOut/the screen.

### -tt #

Some remarks:

Tagging is only available when encoding.

TAK does not distinguish between upper and lower case in the keys; therfore "key" and "KEY" are equivalent.

You may assign multiple values to the same key:

    -tt "Artist=One" -tt "ARTIST=Two"

will create a tag item with the key "Artist" and the value "One Two". The notation of the first appearance of the key is beeing used. Multiple values are beeing separated by zero bytes as defined in the APEv2 specification.

Item values are not allowed to be empty.

### infile

Depending on the selected mode the program automatically appends the proper extension to the file spec: ".wav" when encoding, ".tak" when decoding.

Examples for encoding:

    d:\VocComp_Data\Sample

Compress file "Sample.wav" in the directory "d:\VocComp_Data".

    d:\VocComp_Data\*

Compress any file with the extension ".wav" in the directory "d:\VocComp_Data".

    *

Compress any file with the extension ".wav" in the current directory.

    -

Read the data to compress from StdIn. See pipe encoding for more information.

### outfile

The optional outfile specification works the same way as infile.

Specify "-" to enable pipe decoding: The decoded data is beeing written to StdOut. Currently there are some minor issues with pipe decoding.

Not every in-/outfile spec combination is valid: if you are using wildcards for the infile, you cannot specify an individual filename as outfile. With pipe decoding you have to specify an individual infile.

## Exit codes

The following exit codes may be returned:

### 0 = Success

No errors.

### 1 = Invalid parameter(s)

One or more of the command line parameters are invalid.

### 2 = Operation error

The requested operation failed. Currently nearly any failure is beeing reported as error including the detection of damaged audio data when decoding, even if the file could be partially decoded.

Only exception: If a file is beeing compressed and the wave meta data is too big to be copied into TAK's meta data, the resulting warning is not beeing reported as error.

Probably later program versions will differentiate warnings (code 2) and errors (code 3).

## Pipe encoding

#### What it is good for

Usually TAK reads the data to be encoded from a wave file. Sometimes this is not the best way:

- If you use another application to convert a file from another format than wave into the TAK format, the application first has to convert the data into a temporary wave file and then has to call the TAK command line version to encode the wave file.
- The same is required if you are ripping a cd. First rip and then encode.

This method requires some disk space for the temporary wave file and reading and writing of this file will cost some time.

Those disadvantages can be avoided if the application supports pipe encoding: In this context pipe means a direct connection between two applications. The application writes the data to encode into one end of the pipe and TAK reads it from the other.

Currently the pipe data has to be in the wave file format. Later TAK versions will also support raw data streams.

#### Basic usage

To activate pipe encoding you have to specify a minus as source file and an outfile specification is obligatory:

    takc -e - Outfile

#### Some complications

Because the pipe can only be read sequentially and it's final size is unknown, TAK can not know in advance, if there will be some (rare) additional wave meta data at the end of the file. Since wave meta data is beeing stored into TAK's meta data structures in the file header and this has to be created when encoding starts, TAK has to reserve sufficient space to hold the meta data it might encounter at the end of the file. If the space is too small, the meta data can not be stored, if it is too big, we are wasting some space and the compression will be not optimal.

You may use the -wm option to control the size of the reserved space:

    takc -e -wm46 - Outfile

reserves 46 Bytes which is also the default setting for pipe encoding. This is only sufficient for the simpliest wave file header, but will waste nearly no space.

A similar problem arises if the other application does not know the final sample count of the audio data. This can happen, if the audio data is simultaneously beeing ripped from a cd or if the data is beeing converted from a format which doesen't provide an accurate size information before the whole decoding is done. In both cases the other application can not write an accurate sample count into the wave header which is beeing sent to TAK.

You have to tell TAK to ignore this size entry by adding the ignore-header-size switch to the command line:

    takc -e -ihs - Outfile

The -wm switch can not be used in combination with the -ihs switch. If the header data is invalid, it's useless to save it.

#### Some recommendations for Foobar2000

You have to create an encoder preset to use pipe encoding with Foobar2000. Here an example of a preset i created for Foobar2000 V0.9.4.5:

Some remarks:

- The Encoder path ("C:\Programme\Foobar2000\Takc.exe") has to point to your "Takc.exe".
- You may change the preset selection "-p3" in "Parameters" to your preset of choice.
- Since lossless files have a variable bitrate, the bitrate value of 800 kbps is only an estimate.

# History

### V2.0.0 / 10-01-07

This release introduces a new file format, which can not be decoded by earlier versions of Tak, Takc, in_tak and tak_deco_lib! But surely it can decode files created by any earlier version.

Improvements:

- Slightly better compression of CD-Audio for any preset (ranging from 0.09 to 0.37 percent for my primary test corpus).
- More than 2 percent better compression for my 8-bit test corpus.
- More than 1.5 percent better compression for my 192 KHz / 24-bit test corpus.
- Up to 0.45 percent better compression for my LossyWav test corpus.
- Higher encoding speed for any basic preset (without addditional evaluation level), higher decoding speed for any preset. Depending on the cpu up to 11 percent faster encoding for -p0 and up to 15 percent faster decoding for -p3 compared with V1.1.2.
- While the new codec is smaller than the previous one, the binaries are a bit bigger because the decoder for the old file format takes up about 18 KB.
- The file format is prepared to support some more future improvements.

Modifications:

- Added xrecode II to the list of applications with TAK support in the readme file.

Known issues:

- If you use pipe decoding and the application reading the pipe is beeing terminated before the whole file has been read, TAKC may get into an endless loop and has to be manually killed with the task manager. I don't think this is a big issue but i will try to fix it in one of the next versions. BTW: Big thanks to shnutils for testing the pipe decoding!
- There seem to be some compatibility issues with pipe decoding to some other applications ("crc1632.exe" has been reported). I will try to fix it in the next release.

### V1.1.2 / 9-07-27

New Features:

- Tagging support for the command line encoder.

Improvements:

- Depending on preset and cpu up to 10 percent faster encoding and decoding compared with V1.1.1.
- Slightly faster encoding and decoding of LossyWav files.
- Slightly faster encoding and decoding if MMX is disabled and the pure pascal code is beeing used.
- Removed some more assembler routines and simplified a lot of code. The binaries are again smaller now.

Fixes:

- The new filter introduced in V1.1.1 revealed a bug in the encoder, which resulted in suboptimal performance especially when compressing LossyWav-files with the presets -p3 or -p4 (BTW: It doesn't make sense to go higher than -p2m when compressing LossyWav-files...).

Known issues:

- If you use pipe decoding and the application reading the pipe is beeing terminated before the whole file has been read, TAKC may get into an endless loop and has to be manually killed with the task manager. I don't think this is a big issue but i will try to fix it in one of the next versions. BTW: Big thanks to shnutils for testing the pipe decoding!
- There seem to be some compatibility issues with pipe decoding to some other applications ("crc1632.exe" has been reported). I will try to fix it in the next release.

### V1.1.1 / 9-03-11

New Features:

- In very rare cases the presets -p3 and -p4 could compress much worse than the lower presets. A new filter in the encoder will nearly eliminate this annoying effect. It can also increase the average compression by a tiny (<= 0.05 percent) amount.
- Creation and verification of MD5 checksums of the raw audio data. The file info command can show you the MD5.
- Option to lower the process priority. Nice for background processing.

Improvements:

- Up to 9 KB smaller binaries. Although i have removed a lot of the assembler optimizations, the speed is still very close to the previous version.
- Further clean up of the Code.

Modifications:

- Support for seek tables removed. The new version will neither add seek tables to newly encoded files nor use seek tables contained in files created with older program versions. Important: Seeking in files without seek table is only supported since V1.1.0. Please update the WinAmp plugin and/or the decoding library for full seeking support in media players.
- There is a new metadata object which contains position and size of the last frame in the stream. This info is useful for seeking and tag detection.

### V1.1.0 / 9-01-04

New Features:

- Support for 192 Khz Audio.
- Seeking without seek table.

Improvements:

- Encoding and decoding speed improvements of about 3 percent for presets p0 and p1 on my system. Also some decoding speedup for p2.
- Fixed a bug in the encoder that resulted in suboptimal compression of some loud files and especially high resolution audio. Some files may gain about 0.05 percent of compression. Not much, but it comes without any speed penality.
- Further clean up of the Code.

Modifications:

- I hope you don't mind but i always had the feeling 5 presets are enough. Therefore i dropped the appropriately 'Insane' named preset -p5 and instead made presets 3 and 4 stronger. Okay, new -p4 will nevertheless be slightly weaker than old -p5, because i have reduced the maximum predictor count from 256 to 160. Before doing this i performed a detailed analysis of predictor count * compression * speed. There are not many files which benefit from such high predictor orders. Two of my file sets contain many of such files, but even they will only loose about 0.10 percent compression. Not a big loss if in exchange you get nearly half the decoding (cpu power) requirements.
- Removed option to modify the Prefilter sensitivity.

### V1.0.4 / 8-03-11

New Features:

- Support for pipe decoding.

Improvements:

- Decoding speed improvements of 7 (preset 5) to 13 (preset 0) percent on my system.
- Modification of the presets -p0 and -p1 to make them even faster: -p0 is now encoding 17, -p1 10 percent faster on my system.
- I have replaced some of the Delphi libraries with own code. This will help a later translation to standard C, which can't use delphi libraries. A nice side effect: Most of the binaries are much smaller now.
- The Readme file now contains links to software with TAK support and to some guides.

Modifications:

- The read buffer used to decode presets -p0 to -p3 is considerably smaller now. In most cases this should improve the decoding speed.

### V1.0.3b / 7-12-16

Fixed a bug in the GUI version ("Tak.exe"):

- If the maximum size of the wave file meta data was set to 0, the compressor stopped with an "Error writing destination" error.

### V1.0.3 / 7-12-14

New Features:

- Support for pipe encoding.
- New command line switch -ihs (ignore header size) for pipe encoding.
- New command line option -sts (set seek table size) for pipe encoding.
- New command line switch -silent (silent operation).
- The command line option -wm now let's you specify a maximum size for the wave meta data.
- New command line switch -pMax to select the strongest encoder preset.
- The file info function shows you how much space (if any) in the header is beeing wasted because of pipe encoding.

Improvements:

- Tiny compression improvements for the presets 0 to 2, rarely also for the stronger presets. The average improvement for my test corpus is about 0.05 percent. Not much, but it comes without a significant speed penality.
- Small decoding speed improvements of 4 (preset 5) to 8 (preset 0) percent on my system.
- The Readme file now contains a simple contents section with links to the most relevant topics. There is also a new section about pipe encoding. If you want to use it, please read the text...

Modifications:

- The decoder had to be modified to guarantee error robustness (decoding through errors) for files created by pipe encoding with the -ihs (ignore header size) switch applied.
- Some modifications of the decoding error log file ("Tak_Deco_Error.txt").
- In TAK 1.0.2 there was no difference between the presets -p4/p4e and -p5/-p5e. This irritated some users. Now they are slightly different.
- Command line: The alternative syntax (-pT to -pI) for the preset specification is no longer supported. Now -p0 to -p5 is obligatory.
- GUI: The buttons for preset and evaluation level selection have been removed from the encoder options dialog. Please use the comparison table instead.
- GUI: Moved the Verify switch from the general encoder options to the details dialog.
- GUI: The Save wave file meta data switch has been removed from the encoder output options sheet. Please use the Wave file meta data - Maximum Size setting on the stream options sheet instead.
- Because of an update of my Delphi compiler the binaries are now about 35 KB bigger.

Fixed:

- Some applications crashed if they tried to redirect the output of the command line version. This seems to have been caused by a bug in the Delphi runtime library. Now i am accessing the console directly, what hopefully avoids this trouble.

### V1.0.2 / 7-11-05

New preset configuration:

- Most of the presets have been modified to speed them up and to reduce the decoding requirements. Usually they are more than 50 percent faster while loosing only about 0.3 percent of compression efficiency.
- The fastest preset TURBO (-p0) is now using 8 instead of 16 predictors and compresses (on average) nevertheless better than FLAC -8 (with 12 predictors). The reduced cpu requirements should guarantee that this preset can be decoded on any hardware device capable to playback FLAC -8 (maybe even -5).
- Because of the insertion of the new TURBO preset we now have 6 instead of 5 presets: -p0 to -p5. The strongest setting is now -p5m and it's called INSANE.
- The maximum frame size (samples per channel) is now limited as follows: 4096 for TURBO and FAST, 8192 for NORMAL, HIGH and EXTRA, 16384 for INSANE. This way the specification of the memory requirements of the decoder is more accurate.

New Features:

- You can now manually set the frame size to 512, 1024 or 2048 samples to match the frame size of the LossyWav/LossyFlac preprocessor developed by the Hydrogenaudio.org-Members 2Bdecided, Nick C. and halb27. But caution: Frame sizes of 512, 1024 and 2048 are not backwards compatible and can not be decoded by TAK applications and libraries prior to V1.0.2!
- The Prefilter can now be disabled by the user.

Improvements:

- The strongest compression mode -p5m (aka -p4m in V1.0.1) is now encoding 62 percent faster on my system and is on average loosing only 0.01 percent compression!
- Tiny overall speed improvements.
- Better compression of some low passed files and files coming from lossy sources (especially low and medium constant bitrate). Up to more than 1 % for presets Turbo, Fast and Normal, up to 0.3 precent for High, Extra and Insane. This comes without any significant speed penality.
- Modification of the file read function of the decoder. It's now reading the file in smaller blocks. This will hopefully increase the decoding speed of high resolution audio, which seems to be suffering from the io system of V1.0.1.
- The memory requirements have been reduced. Depending on the preset the encoder is now using 2 to 3 times, the encoder 1.5 to 2.5 times less memory. This may slightly improve the speed on some cpus. But i did it primarily to prepare later hardware implementations.
- Considerable parts of the source code have been partially rewritten or simplified. It's in no way important for the current users (well, like any modification it might even introduce bugs...), but it's part of the preparation of a later source code release. It's only one more step into this direction, there is still much more to do. As always, i can't tell you a release date.

Fixed:

- The file info function was rounding the file duration to the nearest second. Now it's correctly displaying the fraction with 2 decimal places. (30.53 instead of 36.00 seconds).
- When compressing 96 Khz audio with preset HIGH, preset EXTRA has been stored into the encoder meta data. This had no effect on the decoding or data integrity, but the file info function and media players will display the wrong preset.
- The decoder is expected to process any (damaged) data without any problems. But i have found and corrected two cases, where the decoder could crash. The chance for this was less than 1 : 1000 (for damaged files only!).
- In one place i used an invalid flag combination in a call of Windows' VirtualFree().

### V1.0.1 / 7-04-14

Features:

- Some speed optimizations of encoder and decoder. Depending on the preset and your cpu you may see improvements of 2 to 10 percent (if your hard disk is fast enough). Most affected: Encoding and decoding of presets Turbo and Fast, decoding of presets High and Extra.
- Removed the access to internal encoder options. Reintroduced the additional evaluation level EXTRA as compensation.
- Added a dynamic comparison table to illustrate the effect of presets and evaluation levels on compression efficiency, encoding and decoding speed.
- Added a meta data structure to hold encoder version, preset and evaluation level used for compression. Because of rounding errors the addition of this handful of bytes can cause 0.01 percent worse compression be reported (compared to TAK 1.0).
- Added a new command to show selected information about a compressed file.
- The command line version now indicates errors via the exit code. I always thought i already had done this...
- Even better error tolerance of the decoder.

Fixed:

- GUI: When compressing/decompressing the selection of a drives root directory as user specified output destination caused an error.
- It was theoretically possible, that when decoding some verify or source io errors had not been reported properly.
- One tester send me a very special file which could not be encoded; the encoder stopped with an error message. The fact, that nobody before reported such problems, confirms, that this file generated a very special conndition. Fortunately TAK still contains much self check code (which is slowing it down a bit), which detected this error condition and throw the error message. This bug affected only the encoder; if your files have been encoded without the encoder reporting an error, they are fine.

### V1.0 / 7-01-23

Fixed:

- Decoding with the command line version: if you specified wildcards for the file selection and the source directory contained only 1 TAK file, the decoder always threw the message 'File already exists'. Even worse: using the overwrite option in this situation led to deletion of the compressed source file!
- Usually the decoder ignores any data appended to the file end of the compressed file (for instance APEv2 tags). But it failed, if the file size was an integer multiple of the frame size (in samples).

Both bugs affected only the decoder, therefore there is no need to re-encode TAK files created with beta 2.