示例#1
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;
}
示例#2
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;
}
示例#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 *) 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;
}
示例#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);
}
示例#5
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
    }
示例#6
0
文件: mad_plugin.c 项目: azuwis/mpd
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);
}
示例#7
0
文件: mp3.c 项目: ecthiender/mocp-git
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;
}
uint8_t ADM_AudiocodecMP3::beginDecompress( void )
{
        mad_stream_init(Stream);
        mad_frame_init(Frame);
        mad_synth_init(Synth);
        _head=_tail=0;
        return 1;
}
示例#9
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_);
}
示例#10
0
文件: mp3.c 项目: ecthiender/mocp-git
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;
}
示例#11
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);
}
示例#12
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;
}
示例#13
0
void mpgDecoder::reset( )
{
#ifdef HAVE_MAD
	madFile->reset();
    mad_timer_reset( currentPositionTimer );
	mad_stream_init( madStream );
	mad_frame_init( madFrame );
	frameCounter = 0;
#endif
}
MADDecoder::MADDecoder() :
	stereo(false),
	bytes_per_frame(0),
	rate(0),
	sample(0)
{
	mad_stream_init(&Stream);
	mad_frame_init(&Frame);
	mad_synth_init(&Synth);
}
示例#15
0
void MP3Decoder::mp3_init() {
    if (!_isInited) {
        /* libmad初始化 */
        mad_stream_init(&Stream);
        mad_frame_init(&Frame);
        mad_synth_init(&Synth);
        _isInited = true;
    }

}
示例#16
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);
}
示例#17
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;
}
示例#18
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;
}
示例#19
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
}
示例#20
0
文件: mp3.c 项目: tedkulp/bossogg
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);
}
示例#21
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();
}
示例#22
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;
}
示例#23
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;
}
示例#24
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;
}
示例#25
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;
}
示例#26
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();
}
示例#27
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);
}
示例#28
0
static int control(sh_audio_t *sh,int cmd,void* arg, ...){
  mad_decoder_t *this = sh->context;
    // various optional functions you MAY implement:
    switch(cmd){
      case ADCTRL_RESYNC_STREAM:
	this->have_frame=0;
	mad_synth_init  (&this->synth);
	mad_stream_init (&this->stream);
	mad_frame_init  (&this->frame);
	return CONTROL_TRUE;
      case ADCTRL_SKIP_FRAME:
        this->have_frame=read_frame(sh);
	return CONTROL_TRUE;
    }
  return CONTROL_UNKNOWN;
}
示例#29
0
int Mp3Decoder::Rewind()
{
    mad_synth_finish(&Synth);
    mad_frame_finish(&Frame);
    mad_stream_finish(&Stream);
    mad_timer_reset(&Timer);
    mad_stream_init(&Stream);
    mad_frame_init(&Frame);
    mad_synth_init(&Synth);
    SynthPos = 0;
    GuardPtr = NULL;

    if(!file_fd)
        return -1;

    return SoundDecoder::Rewind();
}
ADM_AudiocodecMP3::ADM_AudiocodecMP3( uint32_t fourcc,WAVHeader *info,uint32_t extraLength,uint8_t *extraData) :   ADM_Audiocodec(fourcc)
{
        if((fourcc!=WAV_MP3) && (fourcc!=WAV_MP2))
            ADM_assert(0); 
        if(fourcc==WAV_MP2) printf("Mpeg1/2 audio codec created\n");
        _stream=(void *)ADM_alloc(sizeof( mad_stream));
        _frame=(void *)ADM_alloc(sizeof( mad_frame));
        _synth=(void *)ADM_alloc(sizeof( mad_synth));
        
        
        mad_stream_init(Stream);
        mad_frame_init(Frame);
        mad_synth_init(Synth);
        
        _head=_tail=0;

}