(T)om's lossless (A)udio (K)ompressor.
Version: TAK 1.0, 2007-01-23
Copyright 2006 by Thomas Becker, D-49080 Osnabrück.
All rights reserved.
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.
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.
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).
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 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!
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.
Some important features are missing in this release. Please find below my current to-do list:
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 96000 Hz. Bit depths of 8, 16 or 24. Channels: Mono or Stereo.
The final implementation should support any sample rate from at least 8 to 192 KHz, 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.
While TAK does not yet support tagging on its own, you may use external taggers to append tag data to the end of the compressed file. The decompressor will simply ignore the extra data. You are recommended to use APEv2, and this is likely the format that TAK will use when tagging is implemented.
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.
The archive contains two versions of TAK:
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.
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. |
The Options dialog provides access to many individual encoder options, which affect compression ratio, encoding and decoding speed. If you do not want to be concerned with individual options you can select one of the predefined presets.
The presets TURBO, FAST, NORMAL, HIGH and EXTRA have been carefully configured to achieve the best compromise between encoding speed and compression performance. Each higher preset should encode approximately 1.6 times slower than the preceding one, and provide the maximum compression performance that is possible at that speed.
The presets TURBO, FAST and NORMAL are called restricted hardware profiles.
Profiles may become important, if TAK should be supported by hardware players. Some hardware players may be limited in terms of CPU power or memory size, and not be able to play files which have been encoded by using more demanding encoder options. The manufacturer may specify the maximum hardware profile that can be used by the player. More powerful players may even support the unrestricted presets HIGH and EXTRA.
After selecting a preset you may select the additional evaluation level MAX. This will add encoder options to your preset which provide better compression but slow down encoding; however, importantly, they will not significantly affect decoding speed!
Its primary purpose is getting the most out of the hardware profiles: regardless of the evaluation level you will always stay within the set of allowed options for the selected profile.
Level Max sets all possible options to the maximum. Encoding can be 2 to 3 times slower, depending on the preset.
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 preset instead of increasing the evaluation level.
You may want to play with the individual encoder options to fine tune the presets. For example, if you require a particular encoding speed that lies in between two of the presets.
The linear prediction is the heart of the compression algorithm. It basically works the same way as FLAC, so I'm sure that you can find a better paper which describes its function.
Nevertheless, I will try some short explanation.
The main principle of a lossless audio compressor is the attempt to predict the next sample value based upon the knowledge of the previous ones. If you can make a good guess you only have to store the difference between your prediction and the true sample, which can be much smaller than the true sample. Because smaller values can be stored within less space, you will achieve some compression.
The predictor order determines how many previous samples your prediction takes into account. Usually more predictors give better compression. But, for every predictor, a coefficient has to be stored in the data stream. Because this takes up some additional space, there is always a trade-off between the advantage that an additional predictor provides, and the space needed to store its coefficient.
The coefficients have to fit the audio signal that will be compressed. If the signal characteristics change, new coefficients have to be calculated and stored into the stream.
The coefficients have to be converted from real to integer values before being stored in the stream (this is called "quantization"). This will lead to some precision loss, which lowers the accuracy of the prediction, and therefore compression efficiency. Again a trade-off: the accuracy of the coefficient versus the additional space required to store the extra bits.
Options:
Choose the maximum predictor number to be used. The encoder tries to find the optimum number in the range of 4 to the maximum value you have specified. It is possible that far less then the maximum number will be used, depending on the signal characteristics.
This option is the most important for the decoder performance!
Looks for the best balance between predictor coefficient precision and prediction accuracy. It can achieve up to 0.3 percent better compression with high predictor orders.
Applies some window function to the samples before calculating the predictor coefficients. It can, on average, achieve about 0.05 percent better compression - up to 0.5 percent on selected files. This process is comparatively fast.
This may be detrimental in some rare cases. In such circumstances the frame partition calculator option Validate may help.
The prefilter cleans the signal slightly, before it is sent to the linear predictor. It usually gives, on average, 0.15 to 0.20 percent better compression - up to 4 percent on (very) specific files (for instance files that come from lossy compressed sources).
This can significantly reduce the decoding speed (10-20 %).
Specify the ratio between Prefilter usage (on a frame basis), which can slow down decoding, and the compression advantage:
Specify the frame duration in ms.
Generally, high predictor orders need larger frames, to reduce the overhead of the space required to store the predictors in the stream.
This option can have some (usually small) system-specific effect on the decoding speed.
Because the predictors have to fit to the signal characteristics, the encoder has to calculate new ones, if the signal changes. The frame partition calculator looks for such changes within the current frame and splits it into between 2 and 5 subframes, with individual predictors if necessary.
This operation is very time consuming! There isn't a true insane mode yet, which should calculate every sub frame combination. There is only some estimation (of every combination, and there are many), so there is room for improvement.
Because the processing time grows exponentially with increased frame sizes, a reduction of the frame size can provide a large speed advantage without a significant loss of compression efficiency with low predictor orders.
Sub frame boundaries are aligned to multiples of 1000 / Resolution ms. If you specify 128 there are 32 possible sub frame positions within a frame of 250 ms. TAK checks every possible partition with between 2 and 5 sub frames. That is a lot of work, so higher resolutions are very slow, but provide better adaption to rapid signal changes. 256 should be considered as insane, but it sometimes helps (for example: electronic music).
This increases the accuracy of the search for the best partition. On average, it provides only about 0.05 percent better compression, but up to 0.5 percent for some very specific (and rare) files (but only if the Prefilter is disabled). It slows encoding down drastically, especially when using high predictor orders.
Channel decorrelation (joint stereo) attempts to take advantage of the similarities between two channels.
Enables or disables the standard method for channel decorrelation. Disabling increases encoding speed dramatically, but will normally reduce compression (on average by more than 1 percent).
The encoder will usually try two alternatives for the (Prediction-) decorrelation of two channels A and B, and select the better one: predict A from B or predict B from A. With this option disabled only one alternative is evaluated, which provides a small speed increase for fast encoding modes, but at the cost of reduced compression efficiency.
An alternative method for the channel decorrelation. While nearly always inferior to the Prediction method, it has two advantages: it is much faster, and it compresses better - if both channels contain exactly the same signal (mono signal copied to both channels, which does happen on occasion).
A variation of the Difference method. Sometimes improves compression a little.
The final encoding step is my modified rice encoding of the prediction error.
Calculate the best rice parameters, otherwise they are estimated. Usually only provides about 0.05 percent better compression, and is quite slow.
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!
Where should the compressed files be stored:
Enable this option to overwrite already existing TAK files; otherwise they will be skipped. You will not be asked for a confirmation!
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!
However, if you want to have a bit identical reproduction of the whole wave file, including the non-audio data, you may enable the "Save wave file meta data" option (enabled by default). TAK will store up to 1 MByte of non-audio data into the compressed file. If you enable the corresponding option of the decoder, you will obtain a bit identical copy of the whole wave file.
TAK can save information about the compression process in the protocol file "Tak_Enco_Proto.txt", which will be created in the output directory.
What should be stored into the protocol file:
Append new protocol data to an existing protocol file, instead of overwriting it.
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...
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.
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. |
The Options dialog gives you access to a few decoder options.
Where should the decompressed files be stored:
Enable this option to overwrite already existing wave files; otherwise they will be skipped. You will not be asked for a confirmation!
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.
How should errors caused by damaged files be handled?
Important: You will often have to disable the "Restore wave file meta data" option to decode a damaged file!
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.
Specify what should be done if the decompressor finds a damaged block of audio data within the file:
If enabled, an error log is saved to the file "Tak_Deco_Error.txt".
TAK can save information about the decompression process in the protocol file "Tak_Deco_Proto.txt", which will be created in the output directory.
What should be stored into the protocol 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.tak --- Result: Frame(s) damaged Header frames: 241 Valid frames: 238 Skipped blocks: 3 Skipped end: 0 Skipped data blocks No Source pos Size Sample pos Count 1 1069674 30665 429936 5512 2 2014491 34040 804752 5512 3 2567479 27182 1014208 5512
It contains:
Skipped data blocks contains a list of the defective data blocks:
Because the current decoder implementation has been designed for speed its analysis and correctional capabilities are limited. It will not always be able to report the correct sample count of a damaged block. If the decoder encounters a damaged block within the compressed file it cannot know, without deeper analysis, if this block contains only 1 or more audio frames.
TAKC -mode [-p# -wm# -v -overwrite -l# -w] infile [outfile] -mode -e encode, -d decode, -t test decode, -te test encode -p# select encoder preset # T/F/N/H/E or 0-4 for Turbo/Fast/Normal(default)/High/Extra Append M (-p2m) to increase the evaluation level to the maximum. -wm# 1/0 to enable(default)/disable saving(encode)/restoring(decode) of non-audio wave file meta data -v verify encoded frames (when encoding) -overwrite overwrite existing output files (without confirmation!) -l# select log file level # 0 = no log file (default) 1 = log results 2 = log results and diagnostics Append A (-l1a) to append new results to an existing file. -w wait for enter key when finished infile specify file or directory (Dir\*) to be processed outfile specify output file or directory (Dir\*)
What should the program do:
Select an encoder preset. Default is NORMAL. Append "m" to increase the evaluation level to the maximum. For more information, please read the description for the GUI version.
It's also possible to overwrite some of the encoder options selected by the preset. Each option overwrite has to be begin with a comma, followed by two to three letters identifying the option, and then usually a numeric value. No blank spaces are allowed. An example:
-p2,po128,oq0
Selects preset Normal (2), sets the predictor order to 128, and disables optimize quantization.
Supported options:
Select predictor order #. Possible values: 4, 8, 12, 16, 24, 32, 48, 64, 80, 96, 112, 128, 160, 192, 224, 256.
Optimize Quantization. 0 = off, 1 = on.
Prefilter sensitivity. 0 - 3 for Off/Low/Medium/High.
Frame duration. 0 - 3 for 94, 125, 188 or 250 ms.
Frame partition resolution. 64, 128 or 256 for 15.6, 7.8 or 3.9 ms.
Sub frame number. This option isn't available in the GUI version. It determines how many sub frames the partition calculator may divide each frame into (if appropriate). Valid values: 2 to 5.
The default value depends on the frame duration:
31 - 125 ms: 3 156 - 188 ms: 4 219 - 250 ms: 5
Specify exactly 4 flags (0/1 for off/on) to select the channel decorrelation methods.
Flag 1 = Prediction Flag 2 = Check both Flag 3 = Difference Flag 4 = Mid-Side
Hence "1010" enables "Prediction" and "Difference".
There are some dependencies: You have to enable "Prediction" to use "Check both" and "Difference" to use "Mid-Side".
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 Save wave file meta data and Restore wave file meta data.
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!
By default already existing output files will not be overwritten. Specify this option to enable overwriting. You will not be asked for a confirmation!
Specify the log (protocol) file level. Please read the description of the GUI version for more details.
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.
The optional outfile specification works the same way as infile.
Not every in-/outfile spec combination is valid: if you are using wildcards for the infile, you cannot specify an individual filename as outfile.
The purpose of these versions was the optimization of encoder speed and compression efficiency.
Alpha releases for selected testers.
Public beta releases.
Fixed:
Both bugs affected only the decoder, therefore there is no need to re-encode TAK files created with beta 2.