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