Esempio n. 1
0
void mad_js_close(madfile_t *mf) {
  mad_synth_finish(&mf->synth);
  mad_frame_finish(&mf->frame);
  mad_stream_finish(&mf->stream);
  free(mf->buf);
  free(mf);
}
Esempio n. 2
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);
}
Esempio n. 3
0
void LibMadWrapper::close() noexcept
{

    if (this->synth.hasValue)
    {
        mad_synth_finish(&this->synth.Value);
        this->synth.hasValue = false;
    }

    if (this->frame.hasValue)
    {
        mad_frame_finish(&this->frame.Value);
        this->frame.hasValue = false;
    }

    if (this->stream != nullptr)
    {
        mad_stream_finish(this->stream);
        delete this->stream;
        this->stream = nullptr;
    }

    if (this->mpegbuf != nullptr)
    {
        munmap(this->mpegbuf, this->mpeglen);
        this->mpegbuf = nullptr;
        this->mpeglen = 0;
    }

    if (this->infile != nullptr)
    {
        fclose(this->infile);
        this->infile = nullptr;
    }
}
Esempio n. 4
0
static void uninit(sh_audio_t *sh){
  mad_decoder_t *this = sh->context;
  mad_synth_finish (&this->synth);
  mad_frame_finish (&this->frame);
  mad_stream_finish(&this->stream);
  free(sh->context);
}
Esempio n. 5
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;
}
Esempio n. 6
0
    void MadDecoder::finish()
    {
        mad_synth_finish(&madSynth_);
        mad_frame_finish(&madFrame_);
        mad_stream_finish(&madStream_);

        initialized_ = false;
    }
Esempio n. 7
0
void Mp3Decoder::uninit(sh_audio_t *sh)
{
    mad_decoder_t *mad_dec = (mad_decoder_t *) sh->context;
    mad_synth_finish (&mad_dec->synth);
    mad_frame_finish (&mad_dec->frame);
    mad_stream_finish(&mad_dec->stream);
    free(sh->context);
}
Esempio n. 8
0
MADTranscode::~MADTranscode()
{
    qDebug() << Q_FUNC_INFO;

    mad_synth_finish( &synth );
    mad_frame_finish( &frame );
    mad_stream_finish( &stream );
}
Esempio n. 9
0
void FreeTune() {
    if (FBptr)
		free(FBptr);

    mad_synth_finish(&synth);
    mad_frame_finish(&frame);
    mad_stream_finish(&stream);
};
Esempio n. 10
0
static void mp3_finish (mp3_s *mp3)
{
  mad_synth_finish (&mp3->synth);
  mad_frame_finish (&mp3->frame);
  mad_stream_finish (&mp3->stream);

  fclose (mp3->file);
}
Esempio n. 11
0
static void
deinit_mad_decoder (mp3d_prc_t * ap_prc)
{
  assert (ap_prc);
  mad_synth_finish (&ap_prc->synth_);
  mad_frame_finish (&ap_prc->frame_);
  mad_stream_finish (&ap_prc->stream_);
}
Esempio n. 12
0
static void mp_shutdown (music_player_t *music)
{
       mp_player_t *mp = (mp_player_t*)music;            
  mad_synth_finish (&mp->Synth);
  mad_frame_finish (&mp->Frame);
  mad_stream_finish (&mp->Stream);
  mad_header_finish (&mp->Header);
}
Esempio n. 13
0
static void mp_shutdown (void)
{
                   
  mad_synth_finish (&Synth);
  mad_frame_finish (&Frame);
  mad_stream_finish (&Stream);
  mad_header_finish (&Header);
}
Esempio n. 14
0
uint8_t ADM_AudiocodecMP3::endDecompress( void )
{
    mad_synth_finish(Synth);
    mad_frame_finish(Frame);
    mad_stream_finish(Stream);
    _head=_tail=0;
    return 1;
}
RageSoundReader_MP3::~RageSoundReader_MP3()
{
	mad_synth_finish( &mad->Synth );
	mad_frame_finish( &mad->Frame );
	mad_stream_finish( &mad->Stream );

	delete mad;
}
Esempio n. 16
0
void CodecMpeg1::FreeLibmad()
{
#ifdef HAVE_LIBMAD
  mad_frame_finish(&mpeg1_mad_frame);
  mad_synth_finish(&mpeg1_mad_synth);
  mad_stream_finish(&mpeg1_mad_stream);
  dlclose(mpeg1_mad_handle);
#endif  // HAVE_LIBMAD
}
Esempio n. 17
0
static void mp3_data_finish(struct mp3_data *data)
{
	mad_synth_finish(&data->synth);
	mad_frame_finish(&data->frame);
	mad_stream_finish(&data->stream);

	g_free(data->frame_offsets);
	g_free(data->times);
}
Esempio n. 18
0
void
mad_closeFile(mad_data *mp3_mad) {
  SDL_FreeRW(mp3_mad->rw);
  mad_stream_finish(&mp3_mad->stream);
  mad_frame_finish(&mp3_mad->frame);
  mad_synth_finish(&mp3_mad->synth);

  free(mp3_mad);
}
Esempio n. 19
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;
}
Esempio n. 20
0
void MP3Decoder::mp3_uninit() {
    if (_isInited) {
        mad_synth_finish(&Synth);
        mad_frame_finish(&Frame);
        mad_stream_finish(&Stream);
        _isInited = false;
    }

}
Esempio n. 21
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);
}
Esempio n. 22
0
void CMpegAudioDecoder::CloseDecoder()
{
	if (m_bInitialized) {
		mad_synth_finish(&m_MadSynth);
		mad_frame_finish(&m_MadFrame);
		mad_stream_finish(&m_MadStream);

		m_bInitialized = false;
	}
}
Esempio n. 23
0
/*****************************************************************************
 * CloseFilter : deallocate data structures
 *****************************************************************************/
static void CloseFilter( vlc_object_t *p_this )
{
    filter_t *p_filter = (filter_t *)p_this;
    filter_sys_t *p_sys = p_filter->p_sys;

    mad_synth_finish( &p_sys->mad_synth );
    mad_frame_finish( &p_sys->mad_frame );
    mad_stream_finish( &p_sys->mad_stream );
    free( p_sys );
}
Esempio n. 24
0
void XMp3Decomp::finishMad()
{
	if (m_isInitMad)
	{
		mad_synth_finish(&Synth);
		mad_frame_finish(&Frame);
		mad_stream_finish(&Stream);
		m_isInitMad = false;
	}
}
Esempio n. 25
0
void MAD_WRAPPER_delete( MAD_WRAPPER *mad )
{
	mad_synth_finish( &mad->Synth );
	mad_frame_finish( &mad->Frame );
	mad_stream_finish( &mad->Stream );

    delete[] mad->input_buf;
    delete[] mad->output_buf;
    SDL_FreeRW( mad->src );
    delete mad;
}
Esempio n. 26
0
ADM_AudiocodecMP3::~ADM_AudiocodecMP3( )
{
    mad_synth_finish(Synth);
    mad_frame_finish(Frame);
    mad_stream_finish(Stream);
    ADM_dealloc(_stream);
    ADM_dealloc(_frame);
    ADM_dealloc(_synth);
    _synth=_synth=_stream=NULL;
    
}
Esempio n. 27
0
File: mp3.cpp Progetto: Glyth/xoreos
void MP3Stream::deinitStream() {
	if (_state == MP3_STATE_INIT)
		return;

	// Deinit MAD
	mad_synth_finish(&_synth);
	mad_frame_finish(&_frame);
	mad_stream_finish(&_stream);

	_state = MP3_STATE_EOS;
}
Esempio n. 28
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;
}
Esempio n. 29
0
void
mad_closeFile(mad_data *mp3_mad)
{
  mad_stream_finish(&mp3_mad->stream);
  mad_frame_finish(&mp3_mad->frame);
  mad_synth_finish(&mp3_mad->synth);

  if (mp3_mad->freesrc) {
    SDL_RWclose(mp3_mad->src);
  }
  SDL_free(mp3_mad);
}
Esempio n. 30
0
void Mp3PspStream::deinitStream() {
	DEBUG_ENTER_FUNC();

	if (_state == MP3_STATE_INIT)
		return;

	// Deinit MAD
	mad_header_finish(&_header);
	mad_stream_finish(&_stream);

	_state = MP3_STATE_EOS;
}