]> git.sesse.net Git - vlc/blob - src/audio_decoder/audio_test.c
Bon finalement puisque tout le monde dort, je l'ai fait :)
[vlc] / src / audio_decoder / audio_test.c
1 /*****************************************************************************
2  * audio_test.c: MPEG1 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 GNU
16  * General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public
19  * License along with this program; if not, write to the
20  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21  * Boston, MA 02111-1307, USA.
22  *****************************************************************************/
23
24 /*
25  * TODO :
26  *
27  * - optimiser les NeedBits() et les GetBits() du code là où c'est possible ;
28  * - vlc_cond_signal() / vlc_cond_wait() ;
29  *
30  */
31
32 /*****************************************************************************
33  * Preamble
34  *****************************************************************************/
35
36 #include <stdio.h>
37 #include <string.h>
38
39 #include "int_types.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         return 1;
56
57     stream = adec_byte_stream (&decoder);
58     stream->p_byte = NULL;
59     stream->p_end = NULL;
60     stream->info = stdin;
61
62     framenum = 0;
63
64     while (1) {
65         int i;
66
67         if (adec_sync_frame (&decoder, &sync_info))
68             return 1;
69         if (adec_decode_frame (&decoder, buffer))
70             return 1;
71
72 #if 1
73         for (i = 0; i < (2*1152); i++)
74             printf ("%04X\n",(u16)buffer[i]);
75 #endif
76     }
77
78     return 0;
79 }
80
81 void adec_byte_stream_next (adec_byte_stream_t * p_byte_stream)
82 {
83     static u8 buffer [1024];
84     static u8 dummy = 0;
85     FILE * fd;
86     int size;
87
88     fd = p_byte_stream->info;
89     size = fread (buffer, 1, 1024, fd);
90     if (size) {
91         p_byte_stream->p_byte = buffer;
92         p_byte_stream->p_end = buffer + size;
93     } else {    /* end of stream, read dummy zeroes */
94         p_byte_stream->p_byte = &dummy;
95         p_byte_stream->p_end = &dummy + 1;
96     }
97 }