Exemplo n.º 1
0
static audio_decoder_t *open_plugin (audio_decoder_class_t *class_gen, xine_stream_t *stream) {

  mad_decoder_t *this ;

  this = (mad_decoder_t *) malloc (sizeof (mad_decoder_t));

  this->audio_decoder.decode_data         = mad_decode_data;
  this->audio_decoder.reset               = mad_reset;
  this->audio_decoder.discontinuity       = mad_discontinuity;
  this->audio_decoder.dispose             = mad_dispose;

  this->output_open     = 0;
  this->bytes_in_buffer = 0;
  this->preview_mode    = 0;

  this->xstream         = stream;

  mad_synth_init  (&this->synth);
  mad_stream_init (&this->stream);
  mad_frame_init  (&this->frame);

#ifdef LOG
  printf ("libmad: init\n"); 
#endif

  return &this->audio_decoder;
}
Exemplo n.º 2
0
static int mp3_seek_seconds_offset_brute(double npt)
{
	int pos;

	pos = (int) ((double) g_info.samples * (npt) / g_info.duration);

	if (pos < 0) {
		pos = 0;
	}

	dbg_printf(d, "%s: jumping to %d frame, offset %08x", __func__, pos,
			   (int) mp3info.frameoff[pos]);
	dbg_printf(d, "%s: frame range (0~%u)", __func__,
			   (unsigned) g_info.samples);

	if (pos >= g_info.samples) {
		__end();
		return -1;
	}

	if (mp3_data.use_buffer)
		buffered_reader_seek(mp3_data.r, mp3info.frameoff[pos]);
	else
		xrIoLseek(mp3_data.fd, mp3info.frameoff[pos], PSP_SEEK_SET);

	mad_stream_finish(&stream);
	mad_stream_init(&stream);

	if (pos <= 0)
		g_play_time = 0.0;
	else
		g_play_time = npt;

	return 0;
}
Exemplo n.º 3
0
static audio_decoder_t *open_plugin (audio_decoder_class_t *class_gen, xine_stream_t *stream) {

  mad_decoder_t *this ;

  this = (mad_decoder_t *) calloc(1, sizeof(mad_decoder_t));

  this->audio_decoder.decode_data         = mad_decode_data;
  this->audio_decoder.reset               = mad_reset;
  this->audio_decoder.discontinuity       = mad_discontinuity;
  this->audio_decoder.dispose             = mad_dispose;

  this->output_open     = 0;
  this->bytes_in_buffer = 0;
  this->preview_mode    = 0;

  this->xstream         = stream;

  mad_synth_init  (&this->synth);
  mad_stream_init (&this->stream);
  mad_frame_init  (&this->frame);

  this->stream.options = MAD_OPTION_IGNORECRC;

  lprintf ("init\n");

  return &this->audio_decoder;
}
Exemplo n.º 4
0
void
mp3_mad_init (mp3_info_t *info) {
    mad_stream_init(&info->mad_stream);
    mad_stream_options (&info->mad_stream, MAD_OPTION_IGNORECRC);
    mad_frame_init(&info->mad_frame);
    mad_synth_init(&info->mad_synth);
}
Exemplo n.º 5
0
bool CodecMpeg1::LoadLibmad()
{
#ifdef HAVE_LIBMAD
  if((mpeg1_mad_handle=dlopen("libmad.so",RTLD_NOW))!=NULL) {
    //
    // Initialize Library
    //
    *(void **)(&mad_stream_init)=dlsym(mpeg1_mad_handle,"mad_stream_init");
    *(void **)(&mad_frame_init)=dlsym(mpeg1_mad_handle,"mad_frame_init");
    *(void **)(&mad_synth_init)=dlsym(mpeg1_mad_handle,"mad_synth_init");
    *(void **)(&mad_stream_buffer)=dlsym(mpeg1_mad_handle,"mad_stream_buffer");
    *(void **)(&mad_frame_decode)=dlsym(mpeg1_mad_handle,"mad_frame_decode");
    *(void **)(&mad_header_decode)=dlsym(mpeg1_mad_handle,"mad_header_decode");
    *(void **)(&mad_synth_frame)=dlsym(mpeg1_mad_handle,"mad_synth_frame");
    *(void **)(&mad_frame_mute)=dlsym(mpeg1_mad_handle,"mad_frame_mute");
    *(void **)(&mad_synth_mute)=dlsym(mpeg1_mad_handle,"mad_synth_mute");
    *(void **)(&mad_stream_sync)=dlsym(mpeg1_mad_handle,"mad_stream_sync");
    *(void **)(&mad_frame_finish)=dlsym(mpeg1_mad_handle,"mad_frame_finish");
    *(void **)(&mad_stream_finish)=dlsym(mpeg1_mad_handle,"mad_stream_finish");
    *(void **)(&mad_header_init)=dlsym(mpeg1_mad_handle,"mad_header_init");

    //
    // Initialize Instance
    //
    mad_stream_init(&mpeg1_mad_stream);
    mad_synth_init(&mpeg1_mad_synth);
    mad_frame_init(&mpeg1_mad_frame);
    memset(&mpeg1_mad_header,0,sizeof(mpeg1_mad_header));

    return true;
  }
#endif  // HAVE_LIBMAD
  return false;
}
Exemplo n.º 6
0
static void *mp3_open_stream (struct io_stream *stream)
{
	struct mp3_data *data;

	data = (struct mp3_data *)xmalloc (sizeof(struct mp3_data));
	data->ok = 1;
	decoder_error_init (&data->error);

	/* Reset information about the file */
	data->freq = 0;
	data->channels = 0;
	data->skip_frames = 0;
	data->bitrate = -1;
	data->io_stream = stream;
	data->duration = -1;

	data->size = (off_t)-1;

	mad_stream_init (&data->stream);
	mad_frame_init (&data->frame);
	mad_synth_init (&data->synth);

	if (options_get_int("Mp3IgnoreCRCErrors"))
			mad_stream_options (&data->stream,
				MAD_OPTION_IGNORECRC);
	
	return data;
}
Exemplo n.º 7
0
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);
}
Exemplo n.º 8
0
    size_t MadDecoder::start(FILE* handle)
    {
        handle_ = handle;

        decodeBuffer_.resize(bufferSize_, false);
        ASSERT(decodeBuffer_.size() == bufferSize_);
        unsigned char* buffer = decodeBuffer_.getHead();

        int64 durationMsec = getDurationMs(buffer, bufferSize_);

        mad_stream_init(&madStream_);
        mad_frame_init(&madFrame_);
        mad_synth_init(&madSynth_);
        mad_timer_reset(&madTimer_);

        // Decode at least one valid frame to find out the input format.
        // The decoded frame will be saved off so that it can be processed later.
        //
        size_t bytesRead = fread(buffer, (size_t)1, bufferSize_, handle_);
        if (bytesRead != bufferSize_ && ferror(handle_))
            THROW(std::exception, "%s", strerror(errno));
        mad_stream_buffer(&madStream_, buffer, bytesRead);

        // Find a valid frame before starting up.
        // This make sure that we have a valid MP3 
        // and also skips past ID3v2 tags at the beginning of the audio file.
        //
        madStream_.error = MAD_ERROR_NONE;
        while (mad_frame_decode(&madFrame_, &madStream_))
        {
            // check whether input buffer needs a refill 
            if (madStream_.error == MAD_ERROR_BUFLEN) {

                if (readMpgFile() == false) break;              // eof
                else continue;
            }
            consumeId3Tag();    // consume any ID3 tags

            // FIXME: We should probably detect when we've read
            // a bunch of non-ID3 data and still haven't found a
            // frame.  In that case we can abort early without
            // scanning the whole file.
            //
            madStream_.error = MAD_ERROR_NONE;
        }

        if (madStream_.error) {
            THROW(std::exception, "No valid MP3 frame found");
        }

        mad_timer_add(&madTimer_, madFrame_.header.duration);
        mad_synth_frame(&madSynth_, &madFrame_);

        //unsigned int precision_ = 16;
        currentFrame_ = 0;
        numMpegFrames_ = 0;
        initialized_ = true;

        return (size_t)(durationMsec * .001 * getSampleRate() + .5);  // number of sample frames
    }
Exemplo n.º 9
0
static void
mp3_data_init(struct mp3_data *data, struct decoder *decoder,
	      struct input_stream *input_stream)
{
	data->mute_frame = MUTEFRAME_NONE;
	data->highest_frame = 0;
	data->max_frames = 0;
	data->frame_offsets = NULL;
	data->times = NULL;
	data->current_frame = 0;
	data->drop_start_frames = 0;
	data->drop_end_frames = 0;
	data->drop_start_samples = 0;
	data->drop_end_samples = 0;
	data->found_xing = false;
	data->found_first_frame = false;
	data->decoded_first_frame = false;
	data->decoder = decoder;
	data->input_stream = input_stream;
	data->layer = 0;

	mad_stream_init(&data->stream);
	mad_stream_options(&data->stream, MAD_OPTION_IGNORECRC);
	mad_frame_init(&data->frame);
	mad_synth_init(&data->synth);
	mad_timer_reset(&data->timer);
}
Exemplo n.º 10
0
uint8_t ADM_AudiocodecMP3::beginDecompress( void )
{
        mad_stream_init(Stream);
        mad_frame_init(Frame);
        mad_synth_init(Synth);
        _head=_tail=0;
        return 1;
}
Exemplo n.º 11
0
static struct mp3_data *mp3_open_internal (const char *file,
		const int buffered)
{
	struct mp3_data *data;

	data = (struct mp3_data *)xmalloc (sizeof(struct mp3_data));
	data->ok = 0;
	decoder_error_init (&data->error);

	/* Reset information about the file */
	data->freq = 0;
	data->channels = 0;
	data->skip_frames = 0;
	data->bitrate = -1;
	data->avg_bitrate = -1;

	/* Open the file */
	data->io_stream = io_open (file, buffered);
	if (io_ok(data->io_stream)) {
		data->ok = 1;
		
		data->size = io_file_size (data->io_stream);

		mad_stream_init (&data->stream);
		mad_frame_init (&data->frame);
		mad_synth_init (&data->synth);

		if (options_get_int("Mp3IgnoreCRCErrors"))
				mad_stream_options (&data->stream,
					MAD_OPTION_IGNORECRC);
		
		data->duration = count_time_internal (data);
		mad_frame_mute (&data->frame);
		data->stream.next_frame = NULL;
		data->stream.sync = 0;
		data->stream.error = MAD_ERROR_NONE;

		if (io_seek(data->io_stream, SEEK_SET, 0) == (off_t)-1) {
			decoder_error (&data->error, ERROR_FATAL, 0,
						"seek failed");
			io_close (data->io_stream);
			mad_stream_finish (&data->stream);
			mad_frame_finish (&data->frame);
			mad_synth_finish (&data->synth);
			data->ok = 0;
		}

		data->stream.error = MAD_ERROR_BUFLEN;
	}
	else {
		decoder_error (&data->error, ERROR_FATAL, 0, "Can't open: %s",
				io_strerror(data->io_stream));
		io_close (data->io_stream);
	}

	return data;
}
Exemplo n.º 12
0
static void mad_init_decoder(struct mad_local_data *data)
{
	if (!data)
		return;

	mad_synth_init  (&data->synth);
	mad_stream_init (&data->stream);
	mad_frame_init  (&data->frame);
}
Exemplo n.º 13
0
static int mp_init (int samplerate)
{
  mad_stream_init (&Stream);
  mad_frame_init (&Frame);
  mad_synth_init (&Synth);
  mad_header_init (&Header);
  mp_samplerate_target = samplerate;
  return 1;
}
Exemplo n.º 14
0
static void
init_mad_decoder (mp3d_prc_t * ap_prc)
{
  assert (ap_prc);
  mad_stream_init (&ap_prc->stream_);
  mad_frame_init (&ap_prc->frame_);
  mad_synth_init (&ap_prc->synth_);
  mad_timer_reset (&ap_prc->timer_);
}
Exemplo n.º 15
0
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);
}
Exemplo n.º 16
0
void MP3Decoder::mp3_init() {
    if (!_isInited) {
        /* libmad初始化 */
        mad_stream_init(&Stream);
        mad_frame_init(&Frame);
        mad_synth_init(&Synth);
        _isInited = true;
    }

}
MADDecoder::MADDecoder() :
	stereo(false),
	bytes_per_frame(0),
	rate(0),
	sample(0)
{
	mad_stream_init(&Stream);
	mad_frame_init(&Frame);
	mad_synth_init(&Synth);
}
Exemplo n.º 18
0
void mpgDecoder::reset( )
{
#ifdef HAVE_MAD
	madFile->reset();
    mad_timer_reset( currentPositionTimer );
	mad_stream_init( madStream );
	mad_frame_init( madFrame );
	frameCounter = 0;
#endif
}
Exemplo n.º 19
0
void XMp3Decomp::initMad()
{
	finishMad();
	m_isInitMad = true;
	m_firstBuf = true;
	mad_stream_init(&Stream);
	mad_frame_init(&Frame);
	mad_synth_init(&Synth);
	mad_timer_reset(&Timer);
}
Exemplo n.º 20
0
static int mp_init (music_player_t *music, int samplerate)
{
	mp_player_t *mp = (mp_player_t*)music;
  mad_stream_init (&mp->Stream);
  mad_frame_init (&mp->Frame);
  mad_synth_init (&mp->Synth);
  mad_header_init (&mp->Header);
  mp->mp_samplerate_target = samplerate;
  return 1;
}
Exemplo n.º 21
0
void MP3_Init()
{
# ifndef LINUX_MODE
    samplesInOutput = 0;
    isPlaying = 0;
    /* First the structures used by libmad must be initialized. */
    mad_stream_init(&Stream);
    mad_frame_init(&Frame);
    mad_synth_init(&Synth);
    mad_timer_reset(&Timer);
# endif
}
Exemplo n.º 22
0
static void
MP3_Restart()
{
  memset(OutputBuffer, 0, OUTPUT_BUFFER_SIZE);
  samplesInOutput = 0;

  mad_stream_init(&Stream);
  mad_frame_init(&Frame);
  mad_synth_init(&Synth);
  mad_timer_reset(&Timer);
  MP3_getInfo();
}
Exemplo n.º 23
0
madfile_t *mad_js_init() {
  madfile_t *mf;

  mf = malloc(sizeof(madfile_t));
  mf->position = 0;
  mad_stream_init(&mf->stream);
  mad_frame_init(&mf->frame);
  mad_synth_init(&mf->synth);
  mf->buf = (unsigned char*)malloc(BUFFER_SIZE);

  return mf;
}
Exemplo n.º 24
0
static void mp3_init (mp3_s *mp3)
{
  mp3->out_ptr = mp3->out_buf;
  mp3->out_buf_end = mp3->out_buf + BUF_SIZE;
  mp3->frame_count = 0;
  mp3->status = 0;
  mp3->start = 0;
  mad_stream_init (&mp3->stream);
  mad_frame_init (&mp3->frame);
  mad_synth_init (&mp3->synth);
  mad_timer_reset (&mp3->timer);
}
Exemplo n.º 25
0
bool ADM_AudiocodecMP3::resetAfterSeek( void )
{
        mad_synth_finish(Synth);
        mad_frame_finish(Frame);
        mad_stream_finish(Stream);

        mad_stream_init(Stream);
        mad_frame_init(Frame);
        mad_synth_init(Synth);
        _head=_tail=0;
        return 1;
}
Exemplo n.º 26
0
MADTranscode::MADTranscode() :
        m_decodedBufferCapacity( 32 * 1024 ),
        m_mpegInitialised( false )
{
    qDebug() << "Initialising MAD Transcoding";

    mad_stream_init( &stream );
    mad_frame_init( &frame );
    mad_synth_init( &synth );
    timer = mad_timer_zero;
    last_timer = mad_timer_zero;
}
Exemplo n.º 27
0
bool CMpegAudioDecoder::OpenDecoder()
{
	CloseDecoder();

	mad_stream_init(&m_MadStream);
	mad_frame_init(&m_MadFrame);
	mad_synth_init(&m_MadSynth);

	m_bInitialized = true;
	m_bDecodeError = false;

	return true;
}
Exemplo n.º 28
0
static int preinit(sh_audio_t *sh){

  mad_decoder_t *this = calloc(1, sizeof(mad_decoder_t));
  sh->context = this;

  mad_synth_init  (&this->synth);
  mad_stream_init (&this->stream);
  mad_frame_init  (&this->frame);

  sh->audio_out_minsize=2*4608;
  sh->audio_in_minsize=4096;

  return 1;
}
Exemplo n.º 29
0
Mp3Decoder::Mp3Decoder(const u8 * snd, int len)
    : SoundDecoder(snd, len)
{
    SoundType = SOUND_MP3;
    ReadBuffer = NULL;
    mad_timer_reset(&Timer);
    mad_stream_init(&Stream);
    mad_frame_init(&Frame);
    mad_synth_init(&Synth);

    if(!file_fd)
        return;

    OpenFile();
}
Exemplo n.º 30
0
static void mad_reset (audio_decoder_t *this_gen) {

  mad_decoder_t *this = (mad_decoder_t *) this_gen;

  mad_synth_finish (&this->synth);
  mad_frame_finish (&this->frame);
  mad_stream_finish(&this->stream);

  this->pts = 0;
  this->bytes_in_buffer = 0;
  this->preview_mode = 0;

  mad_synth_init  (&this->synth);
  mad_stream_init (&this->stream);
  mad_frame_init  (&this->frame);
}