OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [tags/] [first/] [mp3/] [sw/] [mad-xess/] [libmad/] [decoder.c] - Blame information for rev 769

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 268 lampret
/*
2
 * mad - MPEG audio decoder
3
 * Copyright (C) 2000-2001 Robert Leslie
4
 *
5
 * This program is free software; you can redistribute it and/or modify
6
 * it under the terms of the GNU General Public License as published by
7
 * the Free Software Foundation; either version 2 of the License, or
8
 * (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18
 *
19
 * $Id: decoder.c,v 1.1.1.1 2001-11-04 19:37:39 lampret Exp $
20
 */
21
 
22
# ifdef HAVE_CONFIG_H
23
#  include "config.h"
24
# endif
25
 
26
# include "global.h"
27
 
28
# include "stream.h"
29
# include "frame.h"
30
# include "synth.h"
31
# include "decoder.h"
32
 
33
extern int test_button(void);
34
 
35
inline void mad_decoder_init(struct mad_decoder *decoder, void *data,
36
                      enum mad_flow (*input_func)(void *, struct mad_stream *),
37
                      enum mad_flow (*error_func)(void *, struct mad_stream *, struct mad_frame *frame))
38
{
39
  decoder->mode         = -1;
40
 
41
  decoder->options      = 0;
42
 
43
  decoder->sync         = 0;
44
 
45
  decoder->cb_data      = data;
46
 
47
  decoder->input_func   = input_func;
48
  decoder->error_func   = error_func;
49
}
50
 
51
inline
52
int mad_decoder_finish(struct mad_decoder *decoder)
53
{
54
  return 0;
55
}
56
 
57
 
58
/* Both parameters are required.  */
59
inline static
60
int run_sync(struct mad_decoder *decoder)
61
{
62
  enum mad_flow (*error_func)(void *, struct mad_stream *, struct mad_frame *);
63
  void *error_data;
64
  int bad_last_frame = 0;
65
  struct mad_stream *stream;
66
  struct mad_frame *frame;
67
  struct mad_synth *synth;
68
  int result = 0;
69
 
70
  error_func = decoder->error_func;
71
  error_data = decoder->cb_data;
72
 
73
  stream = &decoder->sync->stream;
74
  frame  = &decoder->sync->frame;
75
  synth  = &decoder->sync->synth;
76
 
77
  mad_stream_init(stream);
78
  mad_frame_init(frame);
79
  mad_synth_init(synth);
80
 
81
  mad_stream_options(stream, decoder->options);
82
 
83
  do {
84
    switch (decoder->input_func(decoder->cb_data, stream)) {
85
    case MAD_FLOW_STOP:
86
      goto done;
87
    case MAD_FLOW_BREAK:
88
      goto fail;
89
    case MAD_FLOW_IGNORE:
90
      continue;
91
    case MAD_FLOW_CONTINUE:
92
      break;
93
    }
94
 
95
    while (1) {
96
      if (mad_frame_decode(frame, stream) == -1) {
97
        if (!MAD_RECOVERABLE(stream->error))
98
          break;
99
 
100
        error_func(error_data, stream, frame);
101
        goto done;
102
      }
103
      else
104
        bad_last_frame = 0;
105
 
106
      mad_synth_frame(synth, frame);
107
      if(test_button())
108
        return 1;
109
    }
110
  }
111
  while (stream->error == MAD_ERROR_BUFLEN);
112
 
113
 fail:
114
  result = -1;
115
 
116
 done:
117
  mad_synth_finish(synth);
118
  mad_frame_finish(frame);
119
  mad_stream_finish(stream);
120
 
121
  return result;
122
}
123
 
124
inline int mad_decoder_run(struct mad_decoder *decoder, enum mad_decoder_mode mode)
125
{
126
  int result;
127
  struct dec_sync_struct sync;
128
  decoder->sync = &sync;
129
 
130
  result = run_sync(decoder);
131
 
132
  decoder->sync = 0;
133
  return result;
134
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.