annotate src/tta/ttalib.h @ 805:1ba5f86aeac9 trunk

[svn] - should check data != NULL before clear data->playing.
author yaz
date Mon, 12 Mar 2007 09:12:26 -0700
parents c0f69d57483b
children d0d99b22e393
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
290
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
1 /*
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
2 * ttalib.h
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
3 *
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
4 * Description: TTAv1 player library prototypes
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
5 * Developed by: Alexander Djourik <sasha@iszf.irk.ru>
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
6 * Pavel Zhilin <pzh@iszf.irk.ru>
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
7 *
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
8 * Copyright (c) 1999-2004 Alexander Djourik. All rights reserved.
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
9 *
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
10 */
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
11
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
12 /*
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
13 * This library is free software; you can redistribute it and/or
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
14 * modify it under the terms of the GNU Lesser General Public
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
15 * License as published by the Free Software Foundation; either
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
16 * version 2.1 of the License, or (at your option) any later version.
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
17 *
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
18 * This library is distributed in the hope that it will be useful,
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
21 * Lesser General Public License for more details.
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
22 *
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
23 * You should have received a copy of the GNU Lesser General Public
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
24 * License along with this library; if not, write to the Free Software
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
25 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
26 *
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
27 * Please see the file COPYING in this directory for full copyright
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
28 * information.
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
29 */
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
30
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
31 #ifndef TTALIB_H_
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
32 #define TTALIB_H_
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
33
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
34 #include "ttaid3tag.h"
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
35
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
36 //#define _BIG_ENDIAN
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
37 #define MAX_BPS 24 // Max supported Bit resolution
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
38 #define MAX_NCH 8 // Max supported number of channels
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
39
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
40 // return codes
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
41 #define NO_ERROR 0
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
42 #define OPEN_ERROR 1 // Can't open file
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
43 #define FORMAT_ERROR 2 // Unknown TTA format version
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
44 #define PLAYER_ERROR 3 // Not supported file format
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
45 #define FILE_ERROR 4 // File is corrupted
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
46 #define READ_ERROR 5 // Can't read from file
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
47 #define MEMORY_ERROR 6 // Insufficient memory available
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
48
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
49 #define FRAME_TIME 1.04489795918367346939
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
50 #define SEEK_STEP (int)(FRAME_TIME * 1000)
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
51
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
52 #define ISO_BUFFER_LENGTH (1024*32)
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
53 #define ISO_NBUFFERS (8)
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
54 #define ISO_BUFFERS_SIZE (ISO_BUFFER_LENGTH*ISO_NBUFFERS)
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
55 #define PCM_BUFFER_LENGTH (4608)
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
56
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
57 typedef struct {
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
58 FILE *HANDLE; // file handle
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
59 unsigned short NCH; // number of channels
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
60 unsigned short BPS; // bits per sample
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
61 unsigned short BSIZE; // byte size
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
62 unsigned short FORMAT; // audio format
551
c0f69d57483b [svn] - change some references for long to int, reported by and patch by
nenolod
parents: 290
diff changeset
63 unsigned int SAMPLERATE; // samplerate (sps)
c0f69d57483b [svn] - change some references for long to int, reported by and patch by
nenolod
parents: 290
diff changeset
64 unsigned int DATALENGTH; // data length in samples
c0f69d57483b [svn] - change some references for long to int, reported by and patch by
nenolod
parents: 290
diff changeset
65 unsigned int FRAMELEN; // frame length
c0f69d57483b [svn] - change some references for long to int, reported by and patch by
nenolod
parents: 290
diff changeset
66 unsigned int LENGTH; // playback time (sec)
c0f69d57483b [svn] - change some references for long to int, reported by and patch by
nenolod
parents: 290
diff changeset
67 unsigned int STATE; // return code
c0f69d57483b [svn] - change some references for long to int, reported by and patch by
nenolod
parents: 290
diff changeset
68 unsigned int DATAPOS; // size of ID3v2 header
290
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
69 id3v1_data id3v1;
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
70 id3v2_data id3v2;
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
71 } tta_info;
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
72
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
73 /*********************** Library functions *************************/
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
74
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
75 #ifdef LIBTEST
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
76 #ifndef DPRINTF
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
77 #define DPRINTF(x) fprintf(stderr, (x))
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
78 #endif /* DPRINTF */
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
79
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
80 static void tta_error (int error) {
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
81 DPRINTF("TTA Decoder Error - ");
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
82 switch (error) {
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
83 case OPEN_ERROR: DPRINTF("Can't open file\n"); break;
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
84 case FORMAT_ERROR: DPRINTF("Not supported file format\n"); break;
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
85 case FILE_ERROR: DPRINTF("File is corrupted\n"); break;
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
86 case READ_ERROR: DPRINTF("Can't read from file\n"); break;
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
87 case MEMORY_ERROR: DPRINTF("Insufficient memory available\n"); break;
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
88 }
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
89 }
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
90 #endif /* LIBTEST */
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
91
551
c0f69d57483b [svn] - change some references for long to int, reported by and patch by
nenolod
parents: 290
diff changeset
92 int open_tta_file ( // FUNCTION: opens TTA file
290
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
93 const char *filename, // file to open
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
94 tta_info *info, // file info structure
551
c0f69d57483b [svn] - change some references for long to int, reported by and patch by
nenolod
parents: 290
diff changeset
95 unsigned int offset); // ID3v2 header size
290
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
96 /*
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
97 * RETURN VALUE
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
98 * This function returns 0 if success. Otherwise, -1 is returned
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
99 * and the variable STATE of the currently using info structure
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
100 * is set to indicate the error.
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
101 *
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
102 */
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
103
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
104 void close_tta_file ( // FUNCTION: closes currently playing file
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
105 tta_info *info); // file info structure
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
106
551
c0f69d57483b [svn] - change some references for long to int, reported by and patch by
nenolod
parents: 290
diff changeset
107 int set_position ( // FUNCTION: sets playback position
c0f69d57483b [svn] - change some references for long to int, reported by and patch by
nenolod
parents: 290
diff changeset
108 unsigned int pos); // seek position = seek_time_ms / SEEK_STEP
290
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
109 /*
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
110 * RETURN VALUE
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
111 * This function returns 0 if success. Otherwise, -1 is returned
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
112 * and the variable STATE of the currently using info structure
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
113 * is set to indicate the error.
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
114 *
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
115 */
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
116
551
c0f69d57483b [svn] - change some references for long to int, reported by and patch by
nenolod
parents: 290
diff changeset
117 int player_init ( // FUNCTION: initializes TTA player
290
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
118 tta_info *info); // file info structure
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
119 /*
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
120 * RETURN VALUE
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
121 * This function returns 0 if success. Otherwise, -1 is returned
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
122 * and the variable STATE of the currently using info structure
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
123 * is set to indicate the error.
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
124 *
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
125 */
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
126
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
127 void player_stop (void); // FUNCTION: destroys memory pools
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
128
551
c0f69d57483b [svn] - change some references for long to int, reported by and patch by
nenolod
parents: 290
diff changeset
129 int get_samples ( // FUNCTION: decode PCM_BUFFER_LENGTH samples
290
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
130 unsigned char *buffer); // into the current PCM buffer position
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
131 /*
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
132 * RETURN VALUE
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
133 * This function returns the number of samples successfully decoded.
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
134 * Otherwise, -1 is returned and the variable STATE of the currently
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
135 * using info structure is set to indicate the error.
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
136 *
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
137 */
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
138
551
c0f69d57483b [svn] - change some references for long to int, reported by and patch by
nenolod
parents: 290
diff changeset
139 int get_bitrate (void); // RETURN VALUE: TTA dynamic bitrate
290
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
140
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
141 #endif /* TTALIB_H_ */
fbd06b4aa776 [svn] - add TrueAudio plugin
yaz
parents:
diff changeset
142