annotate libmpcodecs/ad_twin.c @ 34748:f86e300072f0

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