本文整理汇总了C++中MAD_RECOVERABLE函数的典型用法代码示例。如果您正苦于以下问题:C++ MAD_RECOVERABLE函数的具体用法?C++ MAD_RECOVERABLE怎么用?C++ MAD_RECOVERABLE使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了MAD_RECOVERABLE函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: mp3_decode_frame
static int mp3_decode_frame (mp3_s *mp3)
{
if (mp3->stream.buffer == NULL || mp3->stream.error == MAD_ERROR_BUFLEN) {
if (mp3_fill_input (mp3) < 0) {
return DECODE_BREAK;
}
}
if (mad_frame_decode (&mp3->frame, &mp3->stream)) {
if (MAD_RECOVERABLE (mp3->stream.error)) {
return DECODE_CONT;
} else {
if (mp3->stream.error == MAD_ERROR_BUFLEN) {
return DECODE_CONT;
} else {
printf ("Unrecoverable frame error: \'%s\'\n", mad_stream_errorstr (&mp3->stream));
mp3->status = 1;
return DECODE_BREAK;
}
}
}
mp3->frame_count++;
return DECODE_OK;
}
开发者ID:tedkulp,项目名称:bossogg,代码行数:26,代码来源:mp3.c
示例2: getNumChannels
//
// Read up samples from madSynth_
// If needed, read some more MP3 data, decode them and synth them
// Place in audioBuffer_.
// Return number of samples read.
//
size_t MadDecoder::decode(size_t numPendingTotal, AudioBuffer* buffer)
{
size_t numProcessedTotal = 0;
int numChannels = getNumChannels();
mad_fixed_t sample;
do {
size_t numPendingFrame = (madSynth_.pcm.length - currentFrame_) * numChannels;
numPendingFrame = std::min(numPendingTotal, numPendingFrame);
size_t numProcessedFrame = 0;
while (numProcessedFrame < numPendingFrame)
{
for (int channel = 0; channel < numChannels; channel++)
{
sample = madSynth_.pcm.samples[channel][currentFrame_];
if (sample < -MAD_F_ONE)
sample = -MAD_F_ONE;
else if (sample >= MAD_F_ONE)
sample = MAD_F_ONE - 1;
float fSample = (float)(sample / (float)(1L << MAD_F_FRACBITS));
float* pos = buffer->getHead() + numProcessedTotal;
*pos = fSample;
numProcessedFrame++;
numProcessedTotal++;
}
currentFrame_++;
}
numPendingTotal -= numProcessedFrame;
if (numPendingTotal == 0)
break;
if (madStream_.error == MAD_ERROR_BUFLEN) { // check whether input buffer needs a refill
if (readMpgFile() == false) // eof
break;
}
if (mad_frame_decode(&madFrame_, &madStream_))
{
if (MAD_RECOVERABLE(madStream_.error)) {
consumeId3Tag();
continue;
}
else {
if (madStream_.error == MAD_ERROR_BUFLEN)
continue;
else
THROW(std::exception, "unrecoverable frame level error (%s).", mad_stream_errorstr(&madStream_));
}
}
mad_timer_add(&madTimer_, madFrame_.header.duration);
mad_synth_frame(&madSynth_, &madFrame_);
currentFrame_ = 0;
numMpegFrames_++;
} while (true);
return numProcessedTotal;
}
开发者ID:dreieier,项目名称:E3,代码行数:66,代码来源:MadDecoder.cpp
示例3: file
int TrackDuration::duration(const QFileInfo &fileinfo)
{
QString fn = fileinfo.absoluteFilePath();
if (fn.isEmpty())
return 0;
QFile file(fn);
if (!file.open(QFile::ReadOnly))
return 0;
mad_stream infostream;
mad_header infoheader;
mad_timer_t infotimer;
mad_stream_init(&infostream);
mad_header_init(&infoheader);
mad_timer_reset(&infotimer);
qint64 r;
qint64 l = 0;
unsigned char* buf = new unsigned char[INPUT_BUFFER_SIZE];
while (!file.atEnd()) {
if (l < INPUT_BUFFER_SIZE) {
r = file.read(reinterpret_cast<char*>(buf) + l, INPUT_BUFFER_SIZE - l);
l += r;
}
mad_stream_buffer(&infostream, buf, l);
for (;;) {
if (mad_header_decode(&infoheader, &infostream)) {
if (!MAD_RECOVERABLE(infostream.error))
break;
if (infostream.error == MAD_ERROR_LOSTSYNC) {
TagLib::ID3v2::Header header;
uint size = (uint)(infostream.bufend - infostream.this_frame);
if (size >= header.size()) {
header.setData(TagLib::ByteVector(reinterpret_cast<const char*>(infostream.this_frame), size));
uint tagsize = header.tagSize();
if (tagsize > 0) {
mad_stream_skip(&infostream, qMin(tagsize, size));
continue;
}
}
}
qDebug() << "header decode error while getting file info" << infostream.error;
continue;
}
mad_timer_add(&infotimer, infoheader.duration);
}
if (infostream.error != MAD_ERROR_BUFLEN && infostream.error != MAD_ERROR_BUFPTR)
break;
memmove(buf, infostream.next_frame, &(buf[l]) - infostream.next_frame);
l -= (infostream.next_frame - buf);
}
mad_stream_finish(&infostream);
mad_header_finish(&infoheader);
delete[] buf;
return timerToMs(&infotimer);
}
开发者ID:jhanssen,项目名称:Ornament,代码行数:60,代码来源:trackduration.cpp
示例4: readMP3Data
void MP3Stream::readHeader() {
if (_state != MP3_STATE_READY)
return;
// If necessary, load more data into the stream decoder
if (_stream.error == MAD_ERROR_BUFLEN)
readMP3Data();
while (_state != MP3_STATE_EOS) {
_stream.error = MAD_ERROR_NONE;
// Decode the next header. Note: mad_frame_decode would do this for us, too.
// However, for seeking we don't want to decode the full frame (else it would
// be far too slow). Hence we perform this explicitly in a separate step.
if (mad_header_decode(&_frame.header, &_stream) == -1) {
if (_stream.error == MAD_ERROR_BUFLEN) {
readMP3Data(); // Read more data
continue;
} else if (MAD_RECOVERABLE(_stream.error)) {
//status("MP3Stream: Recoverable error in mad_header_decode (%s)", mad_stream_errorstr(&_stream));
continue;
} else {
warning("MP3Stream: Unrecoverable error in mad_header_decode (%s)", mad_stream_errorstr(&_stream));
break;
}
}
// Sum up the total playback time so far
mad_timer_add(&_totalTime, _frame.header.duration);
break;
}
if (_stream.error != MAD_ERROR_NONE)
_state = MP3_STATE_EOS;
}
开发者ID:Glyth,项目名称:xoreos,代码行数:35,代码来源:mp3.cpp
示例5: DEBUG_ENTER_FUNC
// Seek in the stream, finding the next valid header
void Mp3PspStream::findValidHeader() {
DEBUG_ENTER_FUNC();
if (_state != MP3_STATE_READY)
return;
// If necessary, load more data into the stream decoder
if (_stream.error == MAD_ERROR_BUFLEN)
readMP3DataIntoBuffer();
while (_state != MP3_STATE_EOS) {
_stream.error = MAD_ERROR_NONE;
// Decode the next header.
if (mad_header_decode(&_header, &_stream) == -1) {
if (_stream.error == MAD_ERROR_BUFLEN) {
readMP3DataIntoBuffer(); // Read more data
continue;
} else if (MAD_RECOVERABLE(_stream.error)) {
debug(6, "MP3PSPStream: Recoverable error in mad_header_decode (%s)", mad_stream_errorstr(&_stream));
continue;
} else {
warning("MP3PSPStream: Unrecoverable error in mad_header_decode (%s)", mad_stream_errorstr(&_stream));
break;
}
}
// Sum up the total playback time so far
mad_timer_add(&_totalTime, _header.duration);
break;
}
if (_stream.error != MAD_ERROR_NONE)
_state = MP3_STATE_EOS;
}
开发者ID:MatChung,项目名称:scummvm-ps3,代码行数:36,代码来源:mp3.cpp
示例6: decode_next_frame_header
static enum mp3_action
decode_next_frame_header(struct mp3_data *data, G_GNUC_UNUSED struct tag **tag)
{
enum mad_layer layer;
if ((data->stream).buffer == NULL
|| (data->stream).error == MAD_ERROR_BUFLEN) {
if (!mp3_fill_buffer(data))
return DECODE_BREAK;
}
if (mad_header_decode(&data->frame.header, &data->stream)) {
if ((data->stream).error == MAD_ERROR_LOSTSYNC &&
(data->stream).this_frame) {
signed long tagsize = id3_tag_query((data->stream).
this_frame,
(data->stream).
bufend -
(data->stream).
this_frame);
if (tagsize > 0) {
if (tag && !(*tag)) {
mp3_parse_id3(data, (size_t)tagsize,
tag);
} else {
mad_stream_skip(&(data->stream),
tagsize);
}
return DECODE_CONT;
}
}
if (MAD_RECOVERABLE((data->stream).error)) {
return DECODE_SKIP;
} else {
if ((data->stream).error == MAD_ERROR_BUFLEN)
return DECODE_CONT;
else {
g_warning("unrecoverable frame level error "
"(%s).\n",
mad_stream_errorstr(&data->stream));
return DECODE_BREAK;
}
}
}
layer = data->frame.header.layer;
if (!data->layer) {
if (layer != MAD_LAYER_II && layer != MAD_LAYER_III) {
/* Only layer 2 and 3 have been tested to work */
return DECODE_SKIP;
}
data->layer = layer;
} else if (layer != data->layer) {
/* Don't decode frames with a different layer than the first */
return DECODE_SKIP;
}
return DECODE_OK;
}
开发者ID:Acidburn0zzz,项目名称:mpd,代码行数:59,代码来源:mad_decoder_plugin.c
示例7: scan_file
static void
scan_file (FILE * fd, int *length, int *bitrate)
{
struct mad_stream stream;
struct mad_header header;
mad_timer_t timer;
unsigned char buffer[8192];
unsigned int buflen = 0;
mad_stream_init (&stream);
mad_header_init (&header);
timer = mad_timer_zero;
while (1)
{
if (buflen < 8192)
{
int bytes = 0;
bytes = fread (buffer + buflen, 1, 8192 - buflen, fd);
if (bytes <= 0)
break;
buflen += bytes;
}
mad_stream_buffer (&stream, buffer, buflen);
while (1)
{
if (mad_header_decode (&header, &stream) == -1)
{
if (!MAD_RECOVERABLE (stream.error))
break;
continue;
}
if (length)
mad_timer_add (&timer, header.duration);
}
if (stream.error != MAD_ERROR_BUFLEN)
break;
memmove (buffer, stream.next_frame, &buffer[buflen] - stream.next_frame);
buflen -= stream.next_frame - &buffer[0];
SDL_Delay(1);
}
mad_header_finish (&header);
mad_stream_finish (&stream);
if (length)
*length = mad_timer_count (timer, MAD_UNITS_MILLISECONDS);
}
开发者ID:BackupTheBerlios,项目名称:beatforce,代码行数:56,代码来源:mp3.c
示例8: mad_stream_buffer
static const void *mp_registersong (music_player_t *music, const void *data, unsigned len)
{
mp_player_t *mp = (mp_player_t*)music;
int i;
int maxtry;
int success = 0;
// the MP3 standard doesn't include any global file header. the only way to tell filetype
// is to start decoding stuff. you can't be too strict however because MP3 is resilient to
// crap in the stream.
// this routine is a bit slower than it could be, but apparently there are lots of files out
// there with some dodgy stuff at the beginning.
// if the stream begins with an ID3v2 magic, search hard and long for our first valid header
if (memcmp (data, "ID3", 3) == 0)
maxtry = 100;
// otherwise, search for not so long
else
maxtry = 20;
mad_stream_buffer (&mp->Stream, data, len);
for (i = 0; i < maxtry; i++)
{
if (mad_header_decode (&mp->Header, &mp->Stream) != 0)
{
if (!MAD_RECOVERABLE (mp->Stream.error))
{
lprintf (LO_WARN, "mad_registersong failed: %s\n", mad_stream_errorstr (&mp->Stream));
return NULL;
}
}
else
{
success++;
}
}
// 80% to pass
if (success < maxtry * 8 / 10)
{
lprintf (LO_WARN, "mad_registersong failed\n");
return NULL;
}
lprintf (LO_INFO, "mad_registersong succeed. bitrate %lu samplerate %d\n", mp->Header.bitrate, mp->Header.samplerate);
mp->mp_data = data;
mp->mp_len = len;
// handle not used
return data;
}
开发者ID:Mistranger,项目名称:prboom-plus,代码行数:53,代码来源:madplayer.c
示例9: mad_js_decode_frame
/* Returns 1 if a recoverable error occured, 0 else. */
int mad_js_decode_frame(madfile_t *mf)
{
int dec;
dec = mad_frame_decode(&mf->frame, &mf->stream);
if (dec) {
if (MAD_RECOVERABLE(mf->stream.error)
|| mf->stream.error == MAD_ERROR_BUFLEN) {
return 1;
} else {
_mad_js_raise(mad_stream_errorstr(&mf->stream));
}
}
mad_synth_frame(&mf->synth, &mf->frame);
return 0;
}
开发者ID:webcast,项目名称:libmad.js,代码行数:19,代码来源:wrapper.c
示例10: while
int LibMadWrapper::findValidHeader(struct mad_header &header)
{
int ret;
while ((ret = mad_header_decode(&header, this->stream)) != 0 && MAD_RECOVERABLE(this->stream->error))
{
if (this->stream->error == MAD_ERROR_LOSTSYNC)
{
long tagsize = id3_tag_query(this->stream->this_frame, this->stream->bufend - this->stream->this_frame);
if (tagsize > 0)
{
mad_stream_skip(this->stream, tagsize);
continue;
}
}
}
return ret;
}
开发者ID:derselbst,项目名称:ANMP,代码行数:19,代码来源:LibMadWrapper.cpp
示例11: decodeNextFrame
static enum mp3_action
decodeNextFrame(struct mp3_data *data)
{
if ((data->stream).buffer == NULL
|| (data->stream).error == MAD_ERROR_BUFLEN) {
if (!mp3_fill_buffer(data))
return DECODE_BREAK;
}
if (mad_frame_decode(&data->frame, &data->stream)) {
#ifdef HAVE_ID3TAG
if ((data->stream).error == MAD_ERROR_LOSTSYNC) {
signed long tagsize = id3_tag_query((data->stream).
this_frame,
(data->stream).
bufend -
(data->stream).
this_frame);
if (tagsize > 0) {
mad_stream_skip(&(data->stream), tagsize);
return DECODE_CONT;
}
}
#endif
if (MAD_RECOVERABLE((data->stream).error)) {
return DECODE_SKIP;
} else {
if ((data->stream).error == MAD_ERROR_BUFLEN)
return DECODE_CONT;
else {
g_warning("unrecoverable frame level error "
"(%s).\n",
mad_stream_errorstr(&data->stream));
return DECODE_BREAK;
}
}
}
return DECODE_OK;
}
开发者ID:azuwis,项目名称:mpd,代码行数:39,代码来源:mad_plugin.c
示例12: xmms_mad_init
static gboolean
xmms_mad_init (xmms_xform_t *xform)
{
struct mad_frame frame;
struct mad_stream stream;
xmms_error_t err;
guchar buf[40960];
xmms_mad_data_t *data;
int len;
const gchar *metakey;
g_return_val_if_fail (xform, FALSE);
data = g_new0 (xmms_mad_data_t, 1);
mad_stream_init (&data->stream);
mad_frame_init (&data->frame);
mad_synth_init (&data->synth);
xmms_xform_private_data_set (xform, data);
data->buffer_length = 0;
data->synthpos = 0x7fffffff;
mad_stream_init (&stream);
mad_frame_init (&frame);
len = xmms_xform_peek (xform, buf, 40960, &err);
mad_stream_buffer (&stream, buf, len);
while (mad_frame_decode (&frame, &stream) == -1) {
if (!MAD_RECOVERABLE (stream.error)) {
XMMS_DBG ("couldn't decode %02x %02x %02x %02x",buf[0],buf[1],buf[2],buf[3]);
mad_frame_finish (&frame);
mad_stream_finish (&stream);
return FALSE;
}
}
data->channels = frame.header.mode == MAD_MODE_SINGLE_CHANNEL ? 1 : 2;
data->samplerate = frame.header.samplerate;
if (frame.header.flags & MAD_FLAG_PROTECTION) {
XMMS_DBG ("Frame has protection enabled");
if (stream.anc_ptr.byte > stream.buffer + 2) {
stream.anc_ptr.byte = stream.anc_ptr.byte - 2;
}
}
data->samples_to_play = -1;
data->xing = xmms_xing_parse (stream.anc_ptr);
if (data->xing) {
xmms_xing_lame_t *lame;
XMMS_DBG ("File with Xing header!");
metakey = XMMS_MEDIALIB_ENTRY_PROPERTY_IS_VBR;
xmms_xform_metadata_set_int (xform, metakey, 1);
if (xmms_xing_has_flag (data->xing, XMMS_XING_FRAMES)) {
guint duration;
mad_timer_t timer;
timer = frame.header.duration;
mad_timer_multiply (&timer, xmms_xing_get_frames (data->xing));
duration = mad_timer_count (timer, MAD_UNITS_MILLISECONDS);
XMMS_DBG ("XING duration %d", duration);
metakey = XMMS_MEDIALIB_ENTRY_PROPERTY_DURATION;
xmms_xform_metadata_set_int (xform, metakey, duration);
if (xmms_xing_has_flag (data->xing, XMMS_XING_BYTES) && duration) {
guint tmp;
tmp = xmms_xing_get_bytes (data->xing) * ((guint64)8000) / duration;
XMMS_DBG ("XING bitrate %d", tmp);
metakey = XMMS_MEDIALIB_ENTRY_PROPERTY_BITRATE;
xmms_xform_metadata_set_int (xform, metakey, tmp);
}
}
lame = xmms_xing_get_lame (data->xing);
if (lame) {
/* FIXME: add a check for ignore_lame_headers from the medialib */
data->frames_to_skip = 1;
data->samples_to_skip = lame->start_delay;
data->samples_to_play = ((guint64) xmms_xing_get_frames (data->xing) * 1152ULL) -
lame->start_delay - lame->end_padding;
XMMS_DBG ("Samples to skip in the beginning: %d, total: %" G_GINT64_FORMAT,
data->samples_to_skip, data->samples_to_play);
/*
metakey = XMMS_MEDIALIB_ENTRY_PROPERTY_GAIN_ALBUM;
xmms_xform_metadata_set_int (xform, metakey, lame->audiophile_gain);
metakey = XMMS_MEDIALIB_ENTRY_PROPERTY_PEAK_TRACK;
xmms_xform_metadata_set_int (xform, metakey, lame->peak_amplitude);
//.........这里部分代码省略.........
开发者ID:eggpi,项目名称:xmms2-guilherme,代码行数:101,代码来源:mad.c
示例13: mp_render_ex
static void mp_render_ex (void *dest, unsigned nsamp)
{
short *sout = (short *) dest;
int localerrors = 0;
if (!mp_playing || mp_paused)
{
memset (dest, 0, nsamp * 4);
return;
}
while (1)
{
// write any leftover data from last MP3 frame
while (mp_leftoversamps > 0 && nsamp > 0)
{
short s = mp_fixtoshort (Synth.pcm.samples[0][mp_leftoversamppos]);
*sout++ = s;
if (Synth.pcm.channels == 2)
s = mp_fixtoshort (Synth.pcm.samples[1][mp_leftoversamppos]);
// if mono, just duplicate the first channel again
*sout++ = s;
mp_leftoversamps -= 1;
mp_leftoversamppos += 1;
nsamp -= 1;
}
if (nsamp == 0)
return; // done
// decode next valid MP3 frame
while (mad_frame_decode (&Frame, &Stream) != 0)
{
if (MAD_RECOVERABLE (Stream.error))
{ // unspecified problem with one frame.
// try the next frame, but bail if we get a bunch of crap in a row;
// likely indicates a larger problem (and if we don't bail, we could
// spend arbitrarily long amounts of time looking for the next good
// packet)
localerrors++;
if (localerrors == 10)
{
lprintf (LO_WARN, "mad_frame_decode: Lots of errors. Most recent %s\n", mad_stream_errorstr (&Stream));
mp_playing = 0;
memset (sout, 0, nsamp * 4);
return;
}
}
else if (Stream.error == MAD_ERROR_BUFLEN)
{ // EOF
// FIXME: in order to not drop the last frame, there must be at least MAD_BUFFER_GUARD
// of extra bytes (with value 0) at the end of the file. current implementation
// drops last frame
if (mp_looping)
{ // rewind, then go again
mad_stream_buffer (&Stream, mp_data, mp_len);
continue;
}
else
{ // stop
mp_playing = 0;
memset (sout, 0, nsamp * 4);
return;
}
}
else
{ // oh well.
lprintf (LO_WARN, "mad_frame_decode: Unrecoverable error %s\n", mad_stream_errorstr (&Stream));
mp_playing = 0;
memset (sout, 0, nsamp * 4);
return;
}
}
// got a good frame, so synth it and dispatch it.
mad_synth_frame (&Synth, &Frame);
mp_leftoversamps = Synth.pcm.length;
mp_leftoversamppos = 0;
}
// NOT REACHED
}
开发者ID:DooMJunkie,项目名称:wii-doom,代码行数:83,代码来源:madplayer.c
示例14: read_next_frame
/* Reads the next frame from the file. Returns true on success or
false on failure. */
static int
read_next_frame(mad_data *mp3_mad) {
if (mp3_mad->stream.buffer == NULL ||
mp3_mad->stream.error == MAD_ERROR_BUFLEN) {
size_t read_size;
size_t remaining;
unsigned char *read_start;
/* There might be some bytes in the buffer left over from last
time. If so, move them down and read more bytes following
them. */
if (mp3_mad->stream.next_frame != NULL) {
remaining = mp3_mad->stream.bufend - mp3_mad->stream.next_frame;
memmove(mp3_mad->input_buffer, mp3_mad->stream.next_frame, remaining);
read_start = mp3_mad->input_buffer + remaining;
read_size = MAD_INPUT_BUFFER_SIZE - remaining;
} else {
read_size = MAD_INPUT_BUFFER_SIZE;
read_start = mp3_mad->input_buffer;
remaining = 0;
}
/* Now read additional bytes from the input file. */
read_size = SDL_RWread(mp3_mad->src, read_start, 1, read_size);
if (read_size <= 0) {
if ((mp3_mad->status & (MS_input_eof | MS_input_error)) == 0) {
if (read_size == 0) {
mp3_mad->status |= MS_input_eof;
} else {
mp3_mad->status |= MS_input_error;
}
/* At the end of the file, we must stuff MAD_BUFFER_GUARD
number of 0 bytes. */
SDL_memset(read_start + read_size, 0, MAD_BUFFER_GUARD);
read_size += MAD_BUFFER_GUARD;
}
}
/* Now feed those bytes into the libmad stream. */
mad_stream_buffer(&mp3_mad->stream, mp3_mad->input_buffer,
read_size + remaining);
mp3_mad->stream.error = MAD_ERROR_NONE;
}
/* Now ask libmad to extract a frame from the data we just put in
its buffer. */
if (mad_frame_decode(&mp3_mad->frame, &mp3_mad->stream)) {
if (MAD_RECOVERABLE(mp3_mad->stream.error)) {
return 0;
} else if (mp3_mad->stream.error == MAD_ERROR_BUFLEN) {
return 0;
} else {
mp3_mad->status |= MS_decode_error;
return 0;
}
}
mp3_mad->frames_read++;
mad_timer_add(&mp3_mad->next_frame_start, mp3_mad->frame.header.duration);
return 1;
}
开发者ID:mgerhardy,项目名称:caveexpress,代码行数:69,代码来源:music_mad.c
示例15: scan
/* Following two functions are adapted from mad_timer, from the
libmad distribution */
void scan(void const *ptr, ssize_t len, buffer *buf)
{
struct mad_stream stream;
struct mad_header header;
struct xing xing;
unsigned long bitrate = 0;
int has_xing = 0;
int is_vbr = 0;
mad_stream_init(&stream);
mad_header_init(&header);
mad_stream_buffer(&stream, ptr, len);
buf->num_frames = 0;
/* There are three ways of calculating the length of an mp3:
1) Constant bitrate: One frame can provide the information
needed: # of frames and duration. Just see how long it
is and do the division.
2) Variable bitrate: Xing tag. It provides the number of
frames. Each frame has the same number of samples, so
just use that.
3) All: Count up the frames and duration of each frames
by decoding each one. We do this if we've no other
choice, i.e. if it's a VBR file with no Xing tag.
*/
while (1)
{
if (mad_header_decode(&header, &stream) == -1)
{
if (MAD_RECOVERABLE(stream.error))
continue;
else
break;
}
/* Limit xing testing to the first frame header */
if (!buf->num_frames++)
{
if(parse_xing(&xing, stream.anc_ptr, stream.anc_bitlen))
{
is_vbr = 1;
if (xing.flags & XING_FRAMES)
{
/* We use the Xing tag only for frames. If it doesn't have that
information, it's useless to us and we have to treat it as a
normal VBR file */
has_xing = 1;
buf->num_frames = xing.frames;
break;
}
}
}
/* Test the first n frames to see if this is a VBR file */
if (!is_vbr && !(buf->num_frames > 20))
{
if (bitrate && header.bitrate != bitrate)
{
is_vbr = 1;
}
else
{
bitrate = header.bitrate;
}
}
/* We have to assume it's not a VBR file if it hasn't already been
marked as one and we've checked n frames for different bitrates */
else if (!is_vbr)
{
break;
}
mad_timer_add(&buf->duration, header.duration);
}
if (!is_vbr)
{
double time = (len * 8.0) / (header.bitrate); /* time in seconds */
double timefrac = (double)time - ((long)(time));
long nsamples = 32 * MAD_NSBSAMPLES(&header); /* samples per frame */
/* samplerate is a constant */
buf->num_frames = (long) (time * header.samplerate / nsamples);
mad_timer_set(&buf->duration, (long)time, (long)(timefrac*100), 100);
}
else if (has_xing)
{
/* modify header.duration since we don't need it anymore */
mad_timer_multiply(&header.duration, buf->num_frames);
//.........这里部分代码省略.........
开发者ID:mvd7793,项目名称:RED-SIREN,代码行数:101,代码来源:mad.c
示例16: MP3Player
// MP3 decode player
void MP3Player(void)
{
FRESULT res;
uint8_t *ReadStart;
uint8_t *GuardPtr;
volatile uint8_t u8PCMBufferTargetIdx = 0;
volatile uint32_t pcmbuf_idx, i;
volatile unsigned int Mp3FileOffset=0;
uint16_t sampleL, sampleR;
pcmbuf_idx = 0;
memset((void *)&audioInfo, 0, sizeof(audioInfo));
/* Parse MP3 header */
MP3_ParseHeaderInfo(MP3_FILE);
/* First the structures used by libmad must be initialized. */
mad_stream_init(&Stream);
mad_frame_init(&Frame);
mad_synth_init(&Synth);
/* Open MP3 file */
res = f_open(&mp3FileObject, MP3_FILE, FA_OPEN_EXISTING | FA_READ);
if (res != FR_OK) {
printf("Open file error \r\n");
return;
}
/* Open I2S1 interface and set to slave mode, stereo channel, I2S format */
I2S_Open(I2S1, I2S_MODE_SLAVE, 16000, I2S_DATABIT_16, I2S_STEREO, I2S_FORMAT_I2S, I2S_I2S);
/* Initialize WAU8822 codec */
WAU8822_Setup();
/* Configure wau8822 for specific sampling rate */
WAU8822_ConfigSampleRate(audioInfo.mp3SampleRate);
/* Set MCLK and enable MCLK */
I2S_EnableMCLK(I2S1, 12000000);
while(1) {
if(Stream.buffer==NULL || Stream.error==MAD_ERROR_BUFLEN) {
if(Stream.next_frame != NULL) {
/* Get the remaining frame */
Remaining = Stream.bufend - Stream.next_frame;
memmove(MadInputBuffer, Stream.next_frame, Remaining);
ReadStart = MadInputBuffer + Remaining;
ReadSize = FILE_IO_BUFFER_SIZE - Remaining;
} else {
ReadSize = FILE_IO_BUFFER_SIZE,
ReadStart = MadInputBuffer,
Remaining = 0;
}
/* read the file from SDCard */
res = f_read(&mp3FileObject, ReadStart, ReadSize, &ReturnSize);
if((res != FR_OK) || f_eof(&mp3FileObject)) {
printf("Stop !(%x)\n\r", res);
goto stop;
}
/* if the file is over */
if (ReadSize > ReturnSize) {
GuardPtr=ReadStart+ReadSize;
memset(GuardPtr,0,MAD_BUFFER_GUARD);
ReadSize+=MAD_BUFFER_GUARD;
}
Mp3FileOffset = Mp3FileOffset + ReturnSize;
/* Pipe the new buffer content to libmad's stream decoder
* facility.
*/
mad_stream_buffer(&Stream,MadInputBuffer,ReadSize+Remaining);
Stream.error=(enum mad_error)0;
}
/* decode a frame from the mp3 stream data */
if(mad_frame_decode(&Frame,&Stream)) {
if(MAD_RECOVERABLE(Stream.error)) {
/*if(Stream.error!=MAD_ERROR_LOSTSYNC ||
Stream.this_frame!=GuardPtr)
{
}*/
continue;
} else {
/* the current frame is not full, need to read the remaining part */
if(Stream.error==MAD_ERROR_BUFLEN) {
continue;
} else {
printf("Something error!!\n");
/* play the next file */
audioInfo.mp3FileEndFlag = 1;
goto stop;
}
}
}
/* Once decoded the frame is synthesized to PCM samples. No errors
//.........这里部分代码省略.........
开发者ID:wjw890912,项目名称:Power-measurement,代码行数:101,代码来源:mp3.c
示例17: DEBUG_ASSERT
//.........这里部分代码省略.........
<< madChannelCount << "<>" << maxChannelCount
<< "in some MP3 frame headers:"
<< m_file.fileName();
}
maxChannelCount = math_max(madChannelCount, maxChannelCount);
const int samplingRateIndex = getIndexBySamplingRate(madSampleRate);
if (samplingRateIndex >= kSamplingRateCount) {
qWarning() << "Invalid sample rate:" << m_file.fileName()
<< madSampleRate;
// Abort
mad_header_finish(&madHeader);
return OpenResult::FAILED;
}
// Count valid frames separated by its sampling rate
headerPerSamplingRate[samplingRateIndex]++;
addSeekFrame(m_curFrameIndex, m_madStream.this_frame);
// Accumulate data from the header
sumBitrate += madHeader.bitrate;
// Update current stream position
m_curFrameIndex += madFrameLength;
DEBUG_ASSERT(m_madStream.this_frame);
DEBUG_ASSERT(0 <= (m_madStream.this_frame - m_pFileData));
} while (quint64(m_madStream.this_frame - m_pFileData) < m_fileSize);
mad_header_finish(&madHeader);
if (MAD_ERROR_NONE != m_madStream.error) {
// Unreachable code for recoverable errors
DEBUG_ASSERT(!MAD_RECOVERABLE(m_madStream.error));
if (MAD_ERROR_BUFLEN != m_madStream.error) {
qWarning() << "Unrecoverable MP3 header error:"
<< mad_stream_errorstr(&m_madStream);
// Abort
return OpenResult::FAILED;
}
}
if (m_seekFrameList.empty()) {
// This is not a working MP3 file.
qWarning() << "SSMP3: This is not a working MP3 file:"
<< m_file.fileName();
// Abort
return OpenResult::FAILED;
}
int mostCommonSamplingRateIndex = kSamplingRateCount; // invalid
int mostCommonSamplingRateCount = 0;
int differentRates = 0;
for (int i = 0; i < kSamplingRateCount; ++i) {
// Find most common sampling rate
if (mostCommonSamplingRateCount < headerPerSamplingRate[i]) {
mostCommonSamplingRateCount = headerPerSamplingRate[i];
mostCommonSamplingRateIndex = i;
differentRates++;
}
}
if (differentRates > 1) {
qWarning() << "Differing sampling rate in some headers:"
<< m_file.fileName();
for (int i = 0; i < kSamplingRateCount; ++i) {
开发者ID:PetrBarborka,项目名称:mixxx,代码行数:67,代码来源:soundsourcemp3.cpp
示例18: mp3_mad_stream_frame
int
mp3_mad_stream_frame (mp3_info_t *info) {
int eof = 0;
while (!eof && (info->mad_stream.buffer == NULL || info->buffer.decode_remaining <= 0)) {
// read more MPEG data if needed
if(info->mad_stream.buffer==NULL || info->mad_stream.error==MAD_ERROR_BUFLEN) {
// copy part of last frame to beginning
if (info->mad_stream.next_frame && info->mad_stream.bufend <= info->mad_stream.next_frame) {
eof = 1;
break;
}
if (info->mad_stream.next_frame != NULL) {
info->buffer.remaining = info->mad_stream.bufend - info->mad_stream.next_frame;
memmove (info->buffer.input, info->mad_stream.next_frame, info->buffer.remaining);
}
int size = READBUFFER - info->buffer.remaining;
int bytesread = 0;
uint8_t *bytes = info->buffer.input + info->buffer.remaining;
bytesread = deadbeef->fread (bytes, 1, size, info->buffer.file);
if (!bytesread) {
// add guard
eof = 1;
memset (bytes, 0, 8);
bytesread = 8;
}
if (bytesread < size) {
// end of file
size -= bytesread;
bytes += bytesread;
}
bytesread += info->buffer.remaining;
mad_stream_buffer(&info->mad_stream,info->buffer.input,bytesread);
if (info->mad_stream.buffer==NULL) {
// check sync bits
if (bytes[0] != 0xff || (bytes[1]&(3<<5)) != (3<<5)) {
trace ("mp3: read didn't start at frame boundary!\ncmp3_scan_stream is broken\n");
}
else {
trace ("mp3: streambuffer=NULL\n");
}
}
}
info->mad_stream.error=0;
// decode next frame
if(mad_frame_decode(&info->mad_frame, &info->mad_stream))
{
if(MAD_RECOVERABLE(info->mad_stream.error))
{
if(info->mad_stream.error!=MAD_ERROR_LOSTSYNC) {
// printf ("mp3: recoverable frame level error (%s)\n", MadErrorString(&info->stream));
}
if (info->buffer.lead_in_frames > 0) {
info->buffer.lead_in_frames--;
}
continue;
}
else {
if(info->mad_stream.error==MAD_ERROR_BUFLEN) {
// printf ("mp3: recoverable frame level error (%s)\n", MadErrorString(&info->stream));
continue;
}
else
{
// printf ("mp3: unrecoverable frame level error (%s).\n", MadErrorString(&info->stream));
return -1; // fatal error
}
}
}
mad_synth_frame(&info->mad_synth,&info->mad_frame);
if (info->buffer.lead_in_frames > 0) {
info->buffer.lead_in_frames--;
info->buffer.decode_remaining = 0;
continue;
}
info->info.fmt.samplerate = info->mad_frame.header.samplerate;
// synthesize single frame
info->buffer.decode_remaining = info->mad_synth.pcm.length;
deadbeef->streamer_set_bitrate (info->mad_frame.header.bitrate/1000);
break;
}
return eof;
}
开发者ID:dHRUSHIT,项目名称:deadbeef,代码行数:86,代码来源:mp3_mad.c
示例19: while
int Mp3Decoder::Read(u8 * buffer, int buffer_size, int pos UNUSED)
{
if(!file_fd)
return -1;
if(Format == VOICE_STEREO_16BIT)
buffer_size &= ~0x0003;
else
buffer_size &= ~0x0001;
u8 * write_pos = buffer;
u8 * write_end = buffer+buffer_size;
while(1)
{
while(SynthPos < Synth.pcm.length)
{
if(write_pos >= write_end)
return write_pos-buffer;
*((s16 *) write_pos) = FixedToShort(Synth.pcm.samples[0][SynthPos]);
write_pos += 2;
if(MAD_NCHANNELS(&Frame.header) == 2)
{
*((s16 *) write_pos) = FixedToShort(Synth.pcm.samples[1][SynthPos]);
write_pos += 2;
}
SynthPos++;
}
if(Stream.buffer == NULL || Stream.error == MAD_ERROR_BUFLEN)
{
u8 * ReadStart = ReadBuffer;
int ReadSize = SoundBlockSize*SoundBlocks;
int Remaining = 0;
if(Stream.next_frame != NULL)
{
Remaining = Stream.bufend - Stream.next_frame;
memmove(ReadBuffer, Stream.next_frame, Remaining);
ReadStart += Remaining;
ReadSize -= Remaining;
}
ReadSize = file_fd->read(ReadStart, ReadSize);
if(ReadSize <= 0)
{
GuardPtr = ReadStart;
memset(GuardPtr, 0, MAD_BUFFER_GUARD);
ReadSize = MAD_BUFFER_GUARD;
}
CurPos += ReadSize;
mad_stream_buffer(&Stream, ReadBuffer, Remaining+ReadSize);
}
if(mad_frame_decode(&Frame,&Stream))
{
if(MAD_RECOVERABLE(Stream.error))
{
if(Stream.error != MAD_ERROR_LOSTSYNC || !GuardPtr)
continue;
}
else
{
if(Stream.error != MAD_ERROR_BUFLEN)
return -1;
else if(Stream.error == MAD_ERROR_BUFLEN && GuardPtr)
return -1;
}
}
mad_timer_add(&Timer,Frame.header.duration);
mad_synth_frame(&Synth,&Frame);
SynthPos = 0;
}
return 0;
}
开发者ID:SuperrSonic,项目名称:WiiXplorer-SS,代码行数:79,代码来源:Mp3Decoder.cpp
|
请发表评论