]> git.sesse.net Git - vlc/blob - src/audio_decoder/adec_test.c
* Header cleaning: filled all empty authors fields, added CVS $Id stuff.
[vlc] / src / audio_decoder / adec_test.c
1 /*****************************************************************************
2  * adec_test.c: MPEG Layer I-II audio decoder test program
3  *****************************************************************************
4  * Copyright (C) 1999, 2000 VideoLAN
5  * $Id: adec_test.c,v 1.4 2001/03/21 13:42:34 sam Exp $
6  *
7  * Authors: Michel Kaempf <maxx@via.ecp.fr>
8  *          Michel Lespinasse <walken@via.ecp.fr>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  * 
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
23  *****************************************************************************/
24
25 /*
26  * TODO :
27  *
28  * - optimiser les NeedBits() et les GetBits() du code là où c'est possible ;
29  * - vlc_cond_signal() / vlc_cond_wait() ;
30  *
31  */
32
33 /*****************************************************************************
34  * Preamble
35  *****************************************************************************/
36
37 #include <stdio.h>
38 #include <string.h>
39
40 #include "int_types.h"
41 #include "adec_generic.h"
42 #include "audio_decoder.h"
43
44 #define ADEC_FRAME_SIZE (2*1152)
45
46 int main (void)
47 {
48     audiodec_t decoder;
49     adec_sync_info_t sync_info;
50     adec_byte_stream_t * stream;
51     s16 buffer [ADEC_FRAME_SIZE];
52
53     int framenum;
54
55     memset (&decoder, 0, sizeof (decoder));
56     if (adec_init (&decoder))
57     {
58         return 1;
59     }
60
61     stream = adec_byte_stream (&decoder);
62     stream->p_byte = NULL;
63     stream->p_end = NULL;
64     stream->info = stdin;
65
66     framenum = 0;
67
68     while (1)
69     {
70         int i;
71
72         if (adec_sync_frame (&decoder, &sync_info))
73         {
74             return 1;
75         }
76         if (adec_decode_frame (&decoder, buffer))
77         {
78             return 1;
79         }
80
81 #if 1
82         for (i = 0; i < (2*1152); i++)
83         {
84             fprintf ( stderr, "%04X\n",(u16)buffer[i] );
85         }
86 #endif
87     }
88
89     return 0;
90 }
91
92 void adec_byte_stream_next (adec_byte_stream_t * p_byte_stream)
93 {
94     static u8 buffer [1024];
95     static u8 dummy = 0;
96     FILE * fd;
97     int size;
98
99     fd = p_byte_stream->info;
100     size = fread (buffer, 1, 1024, fd);
101     if (size)
102     {
103         p_byte_stream->p_byte = buffer;
104         p_byte_stream->p_end = buffer + size;
105     }
106     else
107     {   /* end of stream, read dummy zeroes */
108         p_byte_stream->p_byte = &dummy;
109         p_byte_stream->p_end = &dummy + 1;
110     }
111 }