You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Christopher Snowhill c85c52be91 Updated project files 2 months ago
..
.gitignore Added TTA component, which seems to be otherwise unmaintained. 3 years ago
COPYING Added TTA component, which seems to be otherwise unmaintained. 3 years ago
Makefile.linux Added TTA component, which seems to be otherwise unmaintained. 3 years ago
Makefile.mipsel Added TTA component, which seems to be otherwise unmaintained. 3 years ago
Makefile.rm Added TTA component, which seems to be otherwise unmaintained. 3 years ago
README Added TTA component, which seems to be otherwise unmaintained. 3 years ago
libtta.cpp Added TTA component, which seems to be otherwise unmaintained. 3 years ago
libtta.h Added TTA component, which seems to be otherwise unmaintained. 3 years ago
libtta.sln Added TTA component, which seems to be otherwise unmaintained. 3 years ago
libtta.v12.suo Added TTA component, which seems to be otherwise unmaintained. 3 years ago
libtta.vcxproj Updated project files 2 months ago
libtta.vcxproj.filters Added TTA component, which seems to be otherwise unmaintained. 3 years ago

README

/////////////////////////////////////////////////////////////////////////////
//////////////// THE LOSSLESS TRUE AUDIO CODEC LIBRARY V2.0 /////////////////
/////////////////////////////////////////////////////////////////////////////

This package contains a full-futured codec library for realtime encoding and
decoding of True Audio (TTA) files.

The library has a 3 interface classes, which provides a possibility to work
in applications of any complexity.

For maintenance of namespace wholeness, all functions and library classes are
transferred out to the separate namespace, named tta.

For using this library in advanced applications the tta_encoder, tta_decoder
and tta_exception interface classes can be used.

//////////////////////////// TTA decoder class //////////////////////////////
/////////////////////////////////////////////////////////////////////////////

The tta_decoder class is intended for decoding of the TTA audio files.
The public structure 'info' can be used to retrieve the basic information
about the stream.

The decode_stream function can be used to get a chunk of the decompressed
data. The decode_frame can be used to decode one TTA frame. The tta_callback
function, intended for the extension of possibilities of the user program.
Can be used to get a statistics of the decoding process. This parameter must
be set to NULL if not used.

The decode_stream function returns the decompressed data into the output
buffer and the count of actually decoded samples as a function value.

The set_position function allows you to jump to different parts of the audio
track playback. Function accepts the time position in seconds where playback
has to start, and returns the actual time position of start of the next audio
frame.

//////////////////////////// TTA encoder class //////////////////////////////
/////////////////////////////////////////////////////////////////////////////

The tta_encoder class is intended for coding PCM data with into the output
TTA file.

The encode_stream function can be used to compress a chunk of the input
data. The encode_frame function intended for encoding one TTA frame.
The tta_callback function can be used to get a statistics of the decoding
process. The encoder_finalize function must be called when you're finished
encoding.

/////////////////////////// TTA exception class /////////////////////////////
/////////////////////////////////////////////////////////////////////////////

If an error occurs, the both of tta_encoder and tta_decoder classes generates
exceptions of the tta_exception type. The error code can be retrieved by
code() function of the exception value. This function returns the code which
has a TTA_CODEC_STATUS type.

Description of the TTA error codes:

TTA_NO_ERROR - No known errors found;
TTA_OPEN_ERROR - Can't open file;
TTA_FORMAT_ERROR - Not compatible file format;
TTA_FILE_ERROR - File is corrupted;
TTA_READ_ERROR - Can't read from input file;
TTA_WRITE_ERROR - Can't write to output file;
TTA_SEEK_ERROR - File seek error;
TTA_MEMORY_ERROR - Insufficient memory available.

//////// Sample for building the TTA decoder on Sigma Designs EM86XX ////////
/////////////////////////////////////////////////////////////////////////////

#include "./libtta/libtta.h"

using namespace std;
using namespace tta;

typedef struct {
RMuint32 number_of_channels;
RMuint32 sample_rate;
RMuint32 bits_per_sample;
RMuint32 bytes_per_sample;
RMuint32 total_count_of_samples;
RMuint32 total_count_of_frames;
RMuint32 sample_size;
RMuint64 track_duration;
} tta_context;

typedef struct {
TTA_io_callback iocb;
RMfile f_handle;
} TTA_io_callback_wrapper;

static TTA_io_callback_wrapper iowr;
static tta_decoder *TTA;
static tta_context t_info;
static RMuint32 seek_skip = 0; // count of samples to skip after seek

//////////////////////// 1. Defining codec callbacks ////////////////////////

RMint32 CALLBACK read_callback(TTA_io_callback *io,
RMuint8 *buffer, RMuint32 size) {
TTA_io_callback_wrapper *iocb = (TTA_io_callback_wrapper *)io;
RMuint32 result;
if (RMReadFile(iocb->f_handle, buffer, size, &result) == RM_OK)
return result;
return 0;
}

RMint64 CALLBACK seek_callback(TTA_io_callback *io, RMint64 offset) {
TTA_io_callback_wrapper *iocb = (TTA_io_callback_wrapper *)io;
if (RMSeekFile(iocb->f_handle, offset, RM_FILE_SEEK_START) == RM_OK)
return 0;
return -1;
}

///////////////////////// 2. Decoder initialization /////////////////////////

RMstatus rmtta_file_init(RMfile f_handle) {
if (!f_handle)
return RM_ERROR;

RMMemset(&t_info, 0, sizeof(tta_context));

iowr.iocb.read = &read_callback;
iowr.iocb.seek = &seek_callback;
iowr.iocb.write = NULL;
iowr.handle = f_handle;

try {
TTA = new tta_decoder((TTA_io_callback *) &iowr);
TTA->decoder_init();
} catch (tta_exception ex) {
RMDBGLOG((ENABLE, "rmtta_error: %d\n", ex.code());
if (TTA) delete TTA; // cleanup
return RM_ERROR;
}

// TTA->info structure contains now all of required information:

t_info.number_of_channels = TTA->info.nch;
t_info.sample_rate = TTA->info.sps;
t_info.bits_per_sample = TTA->info.bps;
t_info.bytes_per_sample = TTA->info.depth;
t_info.total_count_of_samples = TTA->info.samples;
t_info.total_count_of_frames = TTA->info.frames;
t_info.sample_size = t_info.bytes_per_sample *
t_info.number_of_channels;

// The track duration (in ms) can be easily calculated as
t_info.track_duration = RMuint64(t_info.total_count_of_samples /
t_info.sample_rate * 1000);

return RM_OK;
}

///////////////////////////// 3. File seeking ///////////////////////////////

RMstatus rmtta_file_seek(RMuint64 seconds) {
if (!TTA->seek_allowed) return RM_ERROR;

RMuint32 frame_start = 0;

try {
frame_start = TTA->set_position((double)seconds);
} catch (tta_exception ex) {
RMDBGLOG((ENABLE, "rmtta_error: %d\n", ex.code());
return RM_ERROR;
}

// We need to skip some samples from start of the frame if required
seek_skip = RMuint32((seconds - frame_start) *
t_info.sample_rate + 0.5);

return RM_OK;
}

/////////////////////// 4. Reading the data from file ///////////////////////

RMstatus rmtta_file_read(RMuint8 *buffer, RMuint32 length,
RMuint32 *size_returned) {

if (!TTA)
return RM_ERROR;

RMuint32 buffer_length = length / t_info.sample_size;
RMuint32 samples_returned = 0;
RMuint32 eos_flag = 0; // end of stream flag

try {
while (seek_skip && !eos_flag) {
if (seek_skip >= buffer_length) {
samples_returned = TTA->decode_stream(buffer,
buffer_length);
seek_skip -= samples_returned;
} else {
samples_returned = TTA->decode_stream(buffer,
seek_skip);
seek_skip = 0;
}
if (!samples_returned) eos_flag = 1;
}

if (!eos_flag) {
samples_returned = TTA->decode_stream(buffer,
buffer_length);
if (!samples_returned) eos_flag = 1;
}
} catch (tta_exception ex) {
RMDBGLOG((ENABLE, "rmtta_error: %d\n", ex.code());
delete TTA; // cleanup
return RM_ERROR;
}

*size_returned = samples_returned * t_info.sample_size;

if (eos_flag)
return RM_ERRORENDOFFILE;

return RM_OK;
}

////////////////////////////// Contributors /////////////////////////////////
/////////////////////////////////////////////////////////////////////////////

Listed in chronological order:

Aleksander Djuric, Pavel Zhilin, Tamir Barak, Noam Koenigstein,
Kazuki Oikawa, Christophe Paris, Eugene Okhotsky, Yoshihisa Uchida, LM Poh.

/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////

Copyright (c) 1999-2010 Aleksander Djuric. All rights reserved.

For the latest in news and downloads, please visit the official True Audio
project site:

http://www.true-audio.com