]> git.sesse.net Git - vlc/blob - modules/codec/mpeg_audio/test.c
* ./modules/*: moved plugins to the new tree. Yet untested builds include
[vlc] / modules / codec / mpeg_audio / test.c
1 /*****************************************************************************
2  * test.c: MPEG Layer I-II audio decoder test program
3  *****************************************************************************
4  * Copyright (C) 1999, 2000 VideoLAN
5  * $Id: test.c,v 1.1 2002/08/04 17:23:42 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  * Preamble
27  *****************************************************************************/
28
29 #include <stdio.h>
30 #include <string.h>
31
32 #include <vlc/vlc.h>
33
34 #include "generic.h"
35 #include "decoder.h"
36
37 #define ADEC_FRAME_SIZE (2*1152)
38
39 int main (void)
40 {
41     audiodec_t decoder;
42     adec_sync_info_t sync_info;
43     adec_byte_stream_t * stream;
44     s16 buffer [ADEC_FRAME_SIZE];
45
46     int framenum;
47
48     memset (&decoder, 0, sizeof (decoder));
49     if (adec_init (&decoder))
50     {
51         return 1;
52     }
53
54     stream = adec_byte_stream (&decoder);
55     stream->p_byte = NULL;
56     stream->p_end = NULL;
57     stream->info = stdin;
58
59     framenum = 0;
60
61     while (1)
62     {
63         int i;
64
65         if (adec_sync_frame (&decoder, &sync_info))
66         {
67             return 1;
68         }
69         if (adec_decode_frame (&decoder, buffer))
70         {
71             return 1;
72         }
73
74 #if 1
75         for (i = 0; i < (2*1152); i++)
76         {
77             fprintf ( stderr, "%04X\n",(u16)buffer[i] );
78         }
79 #endif
80     }
81
82     return 0;
83 }
84
85 void adec_byte_stream_next (adec_byte_stream_t * p_byte_stream)
86 {
87     static u8 buffer [1024];
88     static u8 dummy = 0;
89     FILE * fd;
90     int size;
91
92     fd = p_byte_stream->info;
93     size = fread (buffer, 1, 1024, fd);
94     if (size)
95     {
96         p_byte_stream->p_byte = buffer;
97         p_byte_stream->p_end = buffer + size;
98     }
99     else
100     {   /* end of stream, read dummy zeroes */
101         p_byte_stream->p_byte = &dummy;
102         p_byte_stream->p_end = &dummy + 1;
103     }
104 }