add True Audio (TTA) codec
[kugel-rb.git] / apps / codecs / libtta / ttalib.h
blob861c119cd42cdb67c51669d7cab370b3cb51468b
1 /*
2 * ttalib.h
4 * Description: TTAv1 player library prototypes
5 * Developed by: Alexander Djourik <ald@true-audio.com>
6 * Pavel Zhilin <pzh@true-audio.com>
8 * Copyright (c) 2004 True Audio Software. All rights reserved.
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions
15 * are met:
17 * 1. Redistributions of source code must retain the above copyright
18 * notice, this list of conditions and the following disclaimer.
19 * 2. Redistributions in binary form must reproduce the above copyright
20 * notice, this list of conditions and the following disclaimer in the
21 * documentation and/or other materials provided with the distribution.
22 * 3. Neither the name of the True Audio Software nor the names of its
23 * contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
26 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
27 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
28 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
29 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
30 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
31 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
32 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
33 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
34 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
35 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
36 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 #ifndef TTALIB_H_
40 #define TTALIB_H_
42 #define MAX_BPS 24 /* Max supported Bit resolution */
43 #define MAX_NCH 2 /* Max supported number of channels (Rockbox changes: 8 -> 2) */
45 #ifndef MAXLINE
46 #define MAX_LINE 1024
47 #endif
49 /* decoded pcm sample depth (sample 28bit + sign 1bit) */
50 #define TTA_OUTPUT_DEPTH 29
52 /* return codes */
53 #define NO_ERROR 0 /* No errors found */
54 #define OPEN_ERROR 1 /* Can't open file */
55 #define FORMAT_ERROR 2 /* Unknown TTA format version */
56 #define PLAYER_ERROR 3 /* Not supported file format */
57 #define FILE_ERROR 4 /* File is corrupted */
58 #define READ_ERROR 5 /* Can't read from file */
59 #define MEMORY_ERROR 6 /* Insufficient memory available */
61 /* Rockbox speciffic: does not use FRAME_TIME */
62 /* #define FRAME_TIME 1.04489795918367346939 */
63 #define MULTIPLY_FRAME_TIME(x) (256 * (x) / 245) /* = FRAME_TIME * x */
64 #define SEEK_STEP (int)MULTIPLY_FRAME_TIME(1000) /* (FRAME_TIME * 1000) */
66 #define ISO_BUFFER_LENGTH (1024*32)
67 #define ISO_NBUFFERS (8)
68 #define ISO_BUFFERS_SIZE (4096) /* (ISO_BUFFER_LENGTH*ISO_NBUFFERS) */
69 #define PCM_BUFFER_LENGTH (4608)
70 #define MAX_SEEK_TABLE_SIZE (4096)
72 typedef struct {
73 /* FILE *HANDLE; // file handle (Rockbox does not use) */
74 unsigned int FILESIZE; /* compressed size */
75 unsigned short NCH; /* number of channels */
76 unsigned short BPS; /* bits per sample */
77 unsigned short BSIZE; /* byte size */
78 unsigned short FORMAT; /* audio format */
79 unsigned int SAMPLERATE; /* samplerate (sps) */
80 unsigned int DATALENGTH; /* data length in samples */
81 unsigned int FRAMELEN; /* frame length */
82 unsigned int LENGTH; /* playback time (sec) */
83 unsigned int STATE; /* return code */
84 unsigned int DATAPOS; /* size of ID3v2 header */
85 unsigned int BITRATE; /* average bitrate (kbps) */
86 /* double COMPRESS; // compression ratio (Rockbox does not use) */
87 /* id3_info ID3; // ID3 information (Rockbox does not use) */
88 } tta_info;
90 enum tta_seek_type
92 TTA_SEEK_TIME,
93 TTA_SEEK_POS,
96 /*********************** Library functions *************************/
97 /* Rockbox speciffic: open_tta_file() does not use */
99 /* Rockbox speciffic: It is used in place of open_tta_file(). */
100 int set_tta_info( // FUNCTION: set tta file info structure
101 tta_info *info); // file info structure
103 * RETURN VALUE
104 * This function returns 0 if success. Otherwise, -1 is returned
105 * and the variable STATE of the currently using info structure
106 * is set to indicate the error.
110 /* Rockbox speciffic: close_tta_file() does not use */
112 /* Rockbox speciffic: set_position() change arguments and return value. */
114 * FUNCTION: sets playback position
115 * pos: seek position
116 * seek_time_ms / SEEK_STEP (when type is TTA_SEEK_TIME)
117 * file position (when type is TTA_SEEK_POS)
119 int set_position (
120 unsigned int pos,
121 enum tta_seek_type type);
124 * RETURN VALUE
125 * This function returns the seeked data position (>= 0) if success. Otherwise, -1 is returned
126 * and the variable STATE of the currently using info structure
127 * is set to indicate the error.
131 int player_init ( // FUNCTION: initializes TTA player
132 tta_info *info); // file info structure
134 * RETURN VALUE
135 * This function returns 0 if success. Otherwise, -1 is returned
136 * and the variable STATE of the currently using info structure
137 * is set to indicate the error.
141 void player_stop (void); // FUNCTION: destroys memory pools
143 /* Rockbox speciffic: unsigned char -> int32_t */
144 int get_samples ( // FUNCTION: decode PCM_BUFFER_LENGTH samples
145 int32_t *buffer); // into the current PCM buffer position
148 * RETURN VALUE
149 * This function returns the number of samples successfully decoded.
150 * Otherwise, -1 is returned and the variable STATE of the currently
151 * using info structure is set to indicate the error.
155 const char *get_error_str (int error); // FUNCTION: get error description
157 #endif /* TTALIB_H_ */