annotate libmpcodecs/ad_twin.c @ 15219:c931a567a395

Translation synced with 1.52
author jheryan
date Wed, 20 Apr 2005 07:41:24 +0000
parents fa80ed52127b
children 6ff3379a0862
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
14276
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
1 #include <stdio.h>
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
2 #include <stdlib.h>
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
3 #include <unistd.h>
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
4 #include "config.h"
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
5
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
6 #ifdef USE_WIN32DLL
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
7
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
8 #include "ad_internal.h"
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
9 #include "vqf.h"
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
10 #include "../../loader/ldt_keeper.h"
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
11 #include "wine/windef.h"
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
12 #include "../libaf/af_format.h"
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
13
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
14 #include "help_mp.h"
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
15
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
16 static ad_info_t info =
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
17 {
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
18 "TWinVQ decoder",
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
19 "vqf",
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
20 "Roberto Togni",
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
21 "Nick Kurshev",
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
22 "Ported from MPlayerXP"
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
23 };
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
24
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
25 LIBAD_EXTERN(twin)
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
26
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
27 void* WINAPI LoadLibraryA(char* name);
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
28 void* WINAPI GetProcAddress(void* handle, char* func);
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
29 int WINAPI FreeLibrary(void* handle);
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
30
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
31 static int (*TvqInitialize)( headerInfo *setupInfo, INDEX *index, int dispErrorMessageBox );
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
32 static void (*TvqTerminate)( INDEX *index );
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
33 static void (*TvqGetVectorInfo)(int *bits0[], int *bits1[]);
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
34
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
35 static void (*TvqDecodeFrame)(INDEX *indexp, float out[]);
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
36 static int (*TvqWtypeToBtype)( int w_type, int *btype );
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
37 static void (*TvqUpdateVectorInfo)(int varbits, int *ndiv, int bits0[], int bits1[]);
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
38
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
39 static int (*TvqCheckVersion)(char *versionID);
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
40 static void (*TvqGetConfInfo)(tvqConfInfo *cf);
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
41 static int (*TvqGetFrameSize)();
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
42 static int (*TvqGetNumFixedBitsPerFrame)();
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
43
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
44 #define BYTE_BIT 8
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
45 #define BBUFSIZ 1024 /* Bit buffer size (bytes) */
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
46 #define BBUFLEN (BBUFSIZ*BYTE_BIT) /* Bit buffer length (bits) */
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
47 typedef struct vqf_priv_s
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
48 {
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
49 float pts;
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
50 WAVEFORMATEX o_wf; // out format
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
51 INDEX index;
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
52 tvqConfInfo cf;
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
53 headerInfo hi;
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
54 int *bits_0[N_INTR_TYPE], *bits_1[N_INTR_TYPE];
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
55 unsigned framesize;
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
56 /* stream related */
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
57 int readable;
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
58 int ptr; /* current point in the bit buffer */
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
59 int nbuf; /* bit buffer size */
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
60 char buf[BBUFSIZ]; /* the bit buffer */
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
61 int skip_cnt;
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
62 }vqf_priv_t;
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
63
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
64 static void* vqf_dll;
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
65
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
66 static int load_dll( char *libname )
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
67 {
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
68 #ifdef WIN32_LOADER
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
69 Setup_LDT_Keeper();
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
70 #endif
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
71 vqf_dll = LoadLibraryA(libname);
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
72 if( vqf_dll == NULL )
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
73 {
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
74 mp_msg(MSGT_DECAUDIO, MSGL_ERR, "failed loading dll\n" );
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
75 return 0;
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
76 }
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
77 TvqInitialize = GetProcAddress(vqf_dll,"TvqInitialize");
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
78 TvqTerminate = GetProcAddress(vqf_dll,"TvqTerminate");
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
79 TvqGetVectorInfo = GetProcAddress(vqf_dll,"TvqGetVectorInfo");
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
80 TvqDecodeFrame = GetProcAddress(vqf_dll,"TvqDecodeFrame");
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
81 TvqWtypeToBtype = GetProcAddress(vqf_dll,"TvqWtypeToBtype");
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
82 TvqUpdateVectorInfo = GetProcAddress(vqf_dll,"TvqUpdateVectorInfo");
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
83 TvqCheckVersion = GetProcAddress(vqf_dll,"TvqCheckVersion");
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
84 TvqGetConfInfo = GetProcAddress(vqf_dll,"TvqGetConfInfo");
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
85 TvqGetFrameSize = GetProcAddress(vqf_dll,"TvqGetFrameSize");
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
86 TvqGetNumFixedBitsPerFrame = GetProcAddress(vqf_dll,"TvqGetNumFixedBitsPerFrame");
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
87 return TvqInitialize && TvqTerminate && TvqGetVectorInfo &&
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
88 TvqDecodeFrame && TvqWtypeToBtype && TvqUpdateVectorInfo &&
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
89 TvqCheckVersion && TvqGetConfInfo && TvqGetFrameSize &&
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
90 TvqGetNumFixedBitsPerFrame;
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
91 }
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
92
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
93 extern void print_wave_header(WAVEFORMATEX *h);
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
94 static int init_vqf_audio_codec(sh_audio_t *sh_audio){
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
95 WAVEFORMATEX *in_fmt=sh_audio->wf;
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
96 vqf_priv_t*priv=sh_audio->context;
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
97 int ver;
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
98 mp_msg(MSGT_DECAUDIO, MSGL_INFO, "======= Win32 (TWinVQ) AUDIO Codec init =======\n");
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
99
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
100 sh_audio->channels=in_fmt->nChannels;
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
101 sh_audio->samplerate=in_fmt->nSamplesPerSec;
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
102 sh_audio->sample_format=AF_FORMAT_S16_NE;
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
103 // sh_audio->sample_format=AF_FORMAT_FLOAT_NE;
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
104 sh_audio->samplesize=af_fmt2bits(sh_audio->sample_format)/8;
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
105 priv->o_wf.nChannels=in_fmt->nChannels;
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
106 priv->o_wf.nSamplesPerSec=in_fmt->nSamplesPerSec;
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
107 priv->o_wf.nBlockAlign=sh_audio->samplesize*in_fmt->nChannels;
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
108 priv->o_wf.nAvgBytesPerSec=in_fmt->nBlockAlign*in_fmt->nChannels;
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
109 priv->o_wf.wFormatTag=0x01;
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
110 priv->o_wf.wBitsPerSample=in_fmt->wBitsPerSample;
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
111 priv->o_wf.cbSize=0;
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
112
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
113 if(verbose)
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
114 {
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
115 mp_msg(MSGT_DECAUDIO, MSGL_INFO, "Input format:\n");
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
116 print_wave_header(in_fmt);
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
117 mp_msg(MSGT_DECAUDIO, MSGL_INFO, "Output fmt:\n");
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
118 print_wave_header(&priv->o_wf);
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
119 }
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
120 memcpy(&priv->hi,&in_fmt[1],sizeof(headerInfo));
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
121 if((ver=TvqInitialize(&priv->hi,&priv->index,0))){
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
122 const char *tvqe[]={
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
123 "No errors",
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
124 "General error",
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
125 "Wrong version",
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
126 "Channel setting error",
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
127 "Wrong coding mode",
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
128 "Inner parameter setting error",
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
129 "Wrong number of VQ pre-selection candidates, used only in encoder" };
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
130 mp_msg(MSGT_DECAUDIO, MSGL_ERR, "Tvq initialization error: %s\n",ver>=0&&ver<7?tvqe[ver]:"Unknown");
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
131 return 0;
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
132 }
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
133 ver=TvqCheckVersion(priv->hi.ID);
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
134 if(ver==TVQ_UNKNOWN_VERSION){
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
135 mp_msg(MSGT_DECAUDIO, MSGL_ERR, "Tvq unknown version of stream\n" );
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
136 return 0;
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
137 }
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
138 TvqGetConfInfo(&priv->cf);
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
139 TvqGetVectorInfo(priv->bits_0,priv->bits_1);
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
140 priv->framesize=TvqGetFrameSize();
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
141 sh_audio->audio_in_minsize=priv->framesize*in_fmt->nChannels;
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
142 sh_audio->a_in_buffer_size=4*sh_audio->audio_in_minsize;
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
143 sh_audio->a_in_buffer=malloc(sh_audio->a_in_buffer_size);
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
144 sh_audio->a_in_buffer_len=0;
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
145
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
146
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
147 return 1;
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
148 }
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
149
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
150 static int close_vqf_audio_codec(sh_audio_t *sh_audio)
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
151 {
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
152 vqf_priv_t*priv=sh_audio->context;
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
153 TvqTerminate(&priv->index);
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
154 return 1;
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
155 }
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
156
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
157 int init(sh_audio_t *sh_audio)
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
158 {
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
159 return 1;
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
160 }
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
161
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
162 int preinit(sh_audio_t *sh_audio)
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
163 {
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
164 /* Win32 VQF audio codec: */
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
165 vqf_priv_t *priv;
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
166 if(!(sh_audio->context=malloc(sizeof(vqf_priv_t)))) return 0;
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
167 priv=sh_audio->context;
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
168 if(!load_dll(sh_audio->codec->dll))
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
169 {
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
170 mp_msg(MSGT_DECAUDIO, MSGL_ERR, "win32.dll looks broken :(\n");
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
171 return 0;
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
172 }
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
173 if(!init_vqf_audio_codec(sh_audio)){
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
174 mp_msg(MSGT_DECAUDIO, MSGL_ERR, "TWinVQ initialization fail\n");
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
175 return 0;
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
176 }
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
177 mp_msg(MSGT_DECAUDIO, MSGL_INFO, "INFO: TWinVQ (%s) audio codec init OK!\n",sh_audio->codec->dll);
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
178 priv->skip_cnt = 2;
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
179 return 1;
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
180 }
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
181
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
182 void uninit(sh_audio_t *sh)
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
183 {
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
184 close_vqf_audio_codec(sh);
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
185 free(sh->context);
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
186 FreeLibrary(vqf_dll);
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
187 }
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
188
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
189 int control(sh_audio_t *sh_audio,int cmd,void* arg, ...)
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
190 {
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
191 switch(cmd) {
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
192 case ADCTRL_QUERY_FORMAT:
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
193 return CONTROL_TRUE;
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
194 default:
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
195 return CONTROL_UNKNOWN;
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
196 }
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
197 }
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
198
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
199 static int bread(char *data, /* Output: Output data array */
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
200 int size, /* Input: Length of each data */
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
201 int nbits, /* Input: Number of bits to write */
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
202 sh_audio_t *sh) /* Input: File pointer */
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
203 {
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
204 /*--- Variables ---*/
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
205 int ibits, iptr, idata, ibufadr, ibufbit, icl;
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
206 unsigned char mask, tmpdat;
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
207 int retval;
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
208 vqf_priv_t *priv=sh->context;
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
209
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
210 /*--- Main operation ---*/
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
211 retval = 0;
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
212 mask = 0x1;
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
213 for ( ibits=0; ibits<nbits; ibits++ ){
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
214 if ( priv->readable == 0 ){ /* when the file data buffer is empty */
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
215 priv->nbuf = demux_read_data(sh->ds, priv->buf, BBUFSIZ);
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
216 priv->nbuf *= 8;
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
217 priv->readable = 1;
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
218 }
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
219 iptr = priv->ptr; /* current file data buffer pointer */
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
220 if ( iptr >= priv->nbuf ) /* If data file is empty then return */
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
221 return(retval);
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
222 ibufadr = iptr/BYTE_BIT; /* current file data buffer address */
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
223 ibufbit = iptr%BYTE_BIT; /* current file data buffer bit */
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
224 /* tmpdat = stream->buf[ibufadr] >> (BYTE_BIT-ibufbit-1); */
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
225 tmpdat = (unsigned char)priv->buf[ibufadr];
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
226 tmpdat >>= (BYTE_BIT-ibufbit-1);
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
227 /* current data bit */
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
228
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
229 idata = ibits*size; /* output data address */
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
230 data[idata] = (char)(tmpdat & mask); /* set output data */
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
231 for (icl=1; icl<size; icl++)
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
232 data[idata+icl] = 0; /* clear the rest output data buffer */
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
233 priv->ptr += 1; /* update data buffer pointer */
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
234 if (priv->ptr == BBUFLEN){
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
235 priv->ptr = 0;
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
236 priv->readable = 0;
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
237 }
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
238 ++retval;
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
239 }
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
240 return(retval);
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
241 }
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
242
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
243 #define BITS_INT (sizeof(int)*8)
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
244
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
245 static int get_bstm(int *data, /* Input: input data */
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
246 unsigned nbits, /* Input: number of bits */
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
247 sh_audio_t *sh) /* Input: bit file pointer */
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
248 {
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
249 unsigned ibit;
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
250 unsigned mask;
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
251 unsigned work;
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
252 char tmpbit[BITS_INT];
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
253 int retval;
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
254
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
255 if ( nbits > BITS_INT ){
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
256 mp_msg(MSGT_DECAUDIO, MSGL_ERR, "get_bstm(): %d: %d Error.\n",
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
257 nbits, BITS_INT);
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
258 exit(1);
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
259 }
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
260 retval = bread(tmpbit, sizeof(*tmpbit), nbits, sh);
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
261 for (ibit=retval; ibit<nbits; ibit++){
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
262 tmpbit[ibit] = 0;
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
263 }
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
264 mask = 0x1<<(nbits-1);
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
265 work=0;
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
266 for ( ibit=0; ibit<nbits; ibit++ ){
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
267 work += mask*tmpbit[ibit];
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
268 mask >>= 1;
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
269 }
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
270 *data = work;
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
271 return(retval);
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
272 }
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
273
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
274 static int GetVqInfo( tvqConfInfoSubBlock *cfg,
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
275 int bits0[],
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
276 int bits1[],
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
277 int variableBits,
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
278 INDEX *index,
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
279 sh_audio_t *sh)
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
280 {
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
281 int idiv;
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
282 int bitcount = 0;
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
283
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
284 if ( index->btype == BLK_LONG ){
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
285 TvqUpdateVectorInfo( variableBits, &cfg->ndiv, bits0, bits1 ); // re-calculate VQ bits
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
286 }
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
287 for ( idiv=0; idiv<cfg->ndiv; idiv++ ){
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
288 bitcount += get_bstm(&index->wvq[idiv],bits0[idiv],sh); /* CB 0 */
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
289 bitcount += get_bstm(&index->wvq[idiv+cfg->ndiv],bits1[idiv],sh); /* CB 1 */
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
290 }
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
291 return bitcount;
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
292 }
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
293
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
294 static int GetBseInfo( tvqConfInfo *cf, tvqConfInfoSubBlock *cfg, INDEX *index, sh_audio_t *sh)
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
295 {
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
296 int i_sup, isf, itmp, idiv;
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
297 int bitcount = 0;
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
298
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
299 for ( i_sup=0; i_sup<cf->N_CH; i_sup++ ){
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
300 for ( isf=0; isf<cfg->nsf; isf++ ){
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
301 for ( idiv=0; idiv<cfg->fw_ndiv; idiv++ ){
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
302 itmp = idiv + ( isf + i_sup * cfg->nsf ) * cfg->fw_ndiv;
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
303 bitcount += get_bstm(&index->fw[itmp],cfg->fw_nbit,sh);
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
304 }
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
305 }
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
306 }
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
307 for ( i_sup=0; i_sup<cf->N_CH; i_sup++ ){
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
308 for ( isf=0; isf<cfg->nsf; isf++ ){
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
309 bitcount += get_bstm(&index->fw_alf[i_sup * cfg->nsf + isf],cf->FW_ARSW_BITS,sh);
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
310 }
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
311 }
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
312 return bitcount;
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
313 }
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
314
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
315 static int GetGainInfo(tvqConfInfo *cf, tvqConfInfoSubBlock *cfg, INDEX *index, sh_audio_t *sh )
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
316 {
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
317 int i_sup, iptop, isf;
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
318 int bitcount = 0;
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
319
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
320 for ( i_sup=0; i_sup<cf->N_CH; i_sup++ ){
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
321 iptop = ( cfg->nsubg + 1 ) * i_sup;
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
322 bitcount += get_bstm(&index->pow[iptop], cf->GAIN_BITS,sh);
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
323 for ( isf=0; isf<cfg->nsubg; isf++ ){
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
324 bitcount += get_bstm(&index->pow[iptop+isf+1], cf->SUB_GAIN_BITS,sh);
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
325 }
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
326 }
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
327 return bitcount;
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
328 }
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
329
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
330 static int GetLspInfo( tvqConfInfo *cf, INDEX *index, sh_audio_t *sh )
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
331 {
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
332 int i_sup, itmp;
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
333 int bitcount = 0;
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
334
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
335 for ( i_sup=0; i_sup<cf->N_CH; i_sup++ ){
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
336 bitcount += get_bstm(&index->lsp[i_sup][0], cf->LSP_BIT0,sh); /* pred. switch */
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
337 bitcount += get_bstm(&index->lsp[i_sup][1], cf->LSP_BIT1,sh); /* first stage */
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
338 for ( itmp=0; itmp<cf->LSP_SPLIT; itmp++ ){ /* second stage */
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
339 bitcount += get_bstm(&index->lsp[i_sup][itmp+2], cf->LSP_BIT2,sh);
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
340 }
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
341 }
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
342
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
343 return bitcount;
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
344 }
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
345
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
346 static int GetPpcInfo( tvqConfInfo *cf, INDEX *index, sh_audio_t *sh)
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
347 {
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
348 int idiv, i_sup;
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
349 int bitcount = 0;
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
350 vqf_priv_t*priv=sh->context;
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
351
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
352 for ( idiv=0; idiv<cf->N_DIV_P; idiv++ ){
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
353 bitcount += get_bstm(&(index->pls[idiv]), priv->bits_0[BLK_PPC][idiv],sh); /*CB0*/
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
354 bitcount += get_bstm(&(index->pls[idiv+cf->N_DIV_P]), priv->bits_1[BLK_PPC][idiv],sh);/*CB1*/
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
355 }
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
356 for (i_sup=0; i_sup<cf->N_CH; i_sup++){
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
357 bitcount += get_bstm(&(index->pit[i_sup]), cf->BASF_BIT,sh);
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
358 bitcount += get_bstm(&(index->pgain[i_sup]), cf->PGAIN_BIT,sh);
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
359 }
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
360
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
361 return bitcount;
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
362 }
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
363
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
364 static int GetEbcInfo( tvqConfInfo *cf, tvqConfInfoSubBlock *cfg, INDEX *index, sh_audio_t *sh)
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
365 {
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
366 int i_sup, isf, itmp;
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
367 int bitcount = 0;
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
368
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
369 for ( i_sup=0; i_sup<cf->N_CH; i_sup++ ){
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
370 for ( isf=0; isf<cfg->nsf; isf++){
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
371 int indexSfOffset = isf * ( cfg->ncrb - cfg->ebc_crb_base ) - cfg->ebc_crb_base;
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
372 for ( itmp=cfg->ebc_crb_base; itmp<cfg->ncrb; itmp++ ){
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
373 bitcount += get_bstm(&index->bc[i_sup][itmp+indexSfOffset], cfg->ebc_bits,sh);
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
374 }
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
375 }
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
376 }
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
377
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
378 return bitcount;
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
379 }
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
380
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
381 static int vqf_read_frame(sh_audio_t *sh,INDEX *index)
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
382 {
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
383 /*--- Variables ---*/
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
384 tvqConfInfoSubBlock *cfg;
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
385 int variableBits;
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
386 int bitcount;
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
387 int numFixedBitsPerFrame = TvqGetNumFixedBitsPerFrame();
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
388 int btype;
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
389 vqf_priv_t *priv=sh->context;
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
390
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
391 /*--- Initialization ---*/
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
392 variableBits = 0;
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
393 bitcount = 0;
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
394
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
395 /*--- read block independent factors ---*/
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
396 /* Window type */
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
397 bitcount += get_bstm( &index->w_type, priv->cf.BITS_WTYPE, sh );
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
398 if ( TvqWtypeToBtype( index->w_type, &index->btype ) ) {
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
399 mp_msg(MSGT_DECAUDIO, MSGL_ERR, "Error: unknown window type: %d\n", index->w_type);
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
400 return 0;
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
401 }
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
402 btype = index->btype;
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
403
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
404 /*--- read block dependent factors ---*/
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
405 cfg = &priv->cf.cfg[btype]; // set the block dependent paremeters table
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
406
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
407 bitcount += variableBits;
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
408
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
409 /* Interleaved vector quantization */
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
410 bitcount += GetVqInfo( cfg, priv->bits_0[btype], priv->bits_1[btype], variableBits, index, sh );
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
411
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
412 /* Bark-scale envelope */
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
413 bitcount += GetBseInfo( &priv->cf, cfg, index, sh );
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
414 /* Gain */
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
415 bitcount += GetGainInfo( &priv->cf, cfg, index, sh );
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
416 /* LSP */
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
417 bitcount += GetLspInfo( &priv->cf, index, sh );
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
418 /* PPC */
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
419 if ( cfg->ppc_enable ){
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
420 bitcount += GetPpcInfo( &priv->cf, index, sh );
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
421 }
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
422 /* Energy Balance Calibration */
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
423 if ( cfg->ebc_enable ){
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
424 bitcount += GetEbcInfo( &priv->cf, cfg, index, sh );
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
425 }
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
426
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
427 return bitcount == numFixedBitsPerFrame ? bitcount/8 : 0;
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
428 }
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
429
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
430 static void frtobuf_s16(float out[], /* Input --- input data frame */
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
431 short bufout[], /* Output --- output data buffer array */
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
432 unsigned frameSize, /* Input --- frame size */
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
433 unsigned numChannels) /* Input --- number of channels */
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
434 {
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
435 /*--- Variables ---*/
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
436 unsigned ismp, ich;
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
437 float *ptr;
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
438 float dtmp;
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
439
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
440 for ( ich=0; ich<numChannels; ich++ ){
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
441 ptr = out+ich*frameSize;
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
442 for ( ismp=0; ismp<frameSize; ismp++ ){
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
443 dtmp = ptr[ismp];
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
444 if ( dtmp >= 0. ) {
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
445 if ( dtmp > 32700. )
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
446 dtmp = 32700.;
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
447 bufout[ismp*numChannels+ich] = (short)(dtmp+0.5);
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
448 } else {
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
449 if ( dtmp < -32700. )
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
450 dtmp = -32700.;
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
451 bufout[ismp*numChannels+ich] = (short)(dtmp-0.5);
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
452 }
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
453 }
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
454 }
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
455 }
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
456
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
457 static void frtobuf_float(float out[], /* Input --- input data frame */
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
458 float bufout[], /* Output --- output data buffer array */
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
459 unsigned frameSize, /* Input --- frame size */
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
460 unsigned numChannels) /* Input --- number of channels */
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
461 {
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
462 /*--- Variables ---*/
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
463 unsigned ismp, ich;
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
464 float *ptr;
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
465 float dtmp;
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
466
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
467 for ( ich=0; ich<numChannels; ich++ ){
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
468 ptr = out+ich*frameSize;
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
469 for ( ismp=0; ismp<frameSize; ismp++ ){
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
470 dtmp = ptr[ismp];
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
471 if ( dtmp >= 0. ) {
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
472 if ( dtmp > 32700. )
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
473 dtmp = 32700.;
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
474 bufout[ismp*numChannels+ich] = dtmp/32767.;
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
475 } else {
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
476 if ( dtmp < -32700. )
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
477 dtmp = -32700.;
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
478 bufout[ismp*numChannels+ich] = dtmp/32767.;
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
479 }
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
480 }
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
481 }
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
482 }
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
483
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
484 int decode_audio(sh_audio_t *sh_audio,unsigned char *buf,int minlen,int maxlen)
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
485 {
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
486 int l, len=0;
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
487 vqf_priv_t *priv=sh_audio->context;
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
488 while(len<minlen)
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
489 {
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
490 float out[priv->framesize*sh_audio->channels];
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
491 l=vqf_read_frame(sh_audio,&priv->index);
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
492 if(!l) break;
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
493 TvqDecodeFrame(&priv->index, out);
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
494 if (priv->skip_cnt) {
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
495 // Ingnore first two frames, replace them with silence
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
496 priv->skip_cnt--;
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
497 memset(buf, 0, priv->framesize*sh_audio->channels*sh_audio->samplesize);
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
498 } else {
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
499 if (sh_audio->sample_format == AF_FORMAT_S16_NE)
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
500 frtobuf_s16(out, (short *)buf, priv->framesize, sh_audio->channels);
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
501 else
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
502 frtobuf_float(out, (float *)buf, priv->framesize, sh_audio->channels);
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
503 }
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
504 len += priv->framesize*sh_audio->channels*sh_audio->samplesize;
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
505 buf += priv->framesize*sh_audio->channels*sh_audio->samplesize;
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
506 }
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
507 return len;
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
508 }
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
509
fa80ed52127b TwinVQ decoder and demuxer
rtognimp
parents:
diff changeset
510 #endif