Moves the filters' logging info to work.c, adds parameter info. I also changed the...
[HandBrake.git] / libhb / declpcm.c
blobf6a703d385eaab84b2027d3483ad07c2eed267bb
1 /* $Id: declpcm.c,v 1.8 2005/11/04 14:44:01 titer Exp $
3 This file is part of the HandBrake source code.
4 Homepage: <http://handbrake.m0k.org/>.
5 It may be used under the terms of the GNU General Public License. */
7 #include "hb.h"
9 int declpcmInit( hb_work_object_t *, hb_job_t * );
10 int declpcmWork( hb_work_object_t *, hb_buffer_t **, hb_buffer_t ** );
11 void declpcmClose( hb_work_object_t * );
13 hb_work_object_t hb_declpcm =
15 WORK_DECLPCM,
16 "LPCM decoder",
17 declpcmInit,
18 declpcmWork,
19 declpcmClose
22 int declpcmInit( hb_work_object_t * w, hb_job_t * job )
24 return 0;
27 int declpcmWork( hb_work_object_t * w, hb_buffer_t ** buf_in,
28 hb_buffer_t ** buf_out )
30 hb_buffer_t * in = *buf_in, * out;
31 int samplerate = 0;
32 int count;
33 uint8_t * samples_u8;
34 float * samples_fl32;
35 int i;
36 uint64_t duration;
38 *buf_out = NULL;
40 if( in->data[5] != 0x80 )
42 hb_log( "no LPCM frame sync (%02x)", in->data[5] );
43 return HB_WORK_OK;
46 switch( ( in->data[4] >> 4 ) & 0x3 )
48 case 0:
49 samplerate = 48000;
50 break;
51 case 1:
52 samplerate = 96000;//32000; /* FIXME vlc says it is 96000 */
53 break;
54 case 2:
55 samplerate = 44100;
56 break;
57 case 3:
58 samplerate = 32000;
59 break;
62 count = ( in->size - 6 ) / 2;
63 out = hb_buffer_init( count * sizeof( float ) );
64 duration = count * 90000 / samplerate / 2;
65 out->start = in->start;
66 out->stop = out->start + duration;
68 samples_u8 = in->data + 6;
69 samples_fl32 = (float *) out->data;
71 /* Big endian int16 -> float conversion */
72 for( i = 0; i < count; i++ )
74 #ifdef WORDS_BIGENDIAN
75 samples_fl32[0] = *( (int16_t *) samples_u8 );
76 #else
77 samples_fl32[0] = (int16_t) ( ( samples_u8[0] << 8 ) | samples_u8[1] );
78 #endif
79 samples_u8 += 2;
80 samples_fl32 += 1;
83 *buf_out = out;
85 return HB_WORK_OK;
88 void declpcmClose( hb_work_object_t * w )