annotate libmpcodecs/ad_twin.c @ 30581:fef54a0e6ec2

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