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. */
9 struct hb_work_object_s
19 static int Work( hb_work_object_t * w, hb_buffer_t ** buf_in,
20 hb_buffer_t ** buf_out )
22 hb_buffer_t * in = *buf_in, * out;
32 if( in->data[5] != 0x80 )
34 hb_log( "no LPCM frame sync (%02x)", in->data[5] );
38 switch( ( in->data[4] >> 4 ) & 0x3 )
44 samplerate = 96000;//32000; /* FIXME vlc says it is 96000 */
54 count = ( in->size - 6 ) / 2;
55 out = hb_buffer_init( count * sizeof( float ) );
56 duration = count * 90000 / samplerate / 2;
57 if( w->pts_last > 0 &&
58 in->start < w->pts_last + duration / 6 &&
59 in->start > w->pts_last - duration / 6 )
61 /* Workaround for DVDs where dates aren't exact */
62 out->start = w->pts_last;
66 out->start = in->start;
68 out->stop = out->start + duration;
69 w->pts_last = out->stop;
71 samples_u8 = in->data + 6;
72 samples_fl32 = (float *) out->data;
74 /* Big endian int16 -> float conversion */
75 for( i = 0; i < count; i++ )
77 #ifdef WORDS_BIGENDIAN
78 samples_fl32[0] = *( (int16_t *) samples_u8 );
80 samples_fl32[0] = (int16_t) ( ( samples_u8[0] << 8 ) | samples_u8[1] );
91 static void Close( hb_work_object_t ** _w )
93 hb_work_object_t * w = *_w;
99 hb_work_object_t * hb_work_declpcm_init( hb_job_t * job, hb_audio_t * audio )
101 hb_work_object_t * w = calloc( sizeof( hb_work_object_t ), 1 );
102 w->name = strdup( "LPCM decoder" );