Exemplo n.º 1
0
static void
gst_mpg123_audio_dec_flush (GstAudioDecoder * dec, gboolean hard)
{
  int error;
  GstMpg123AudioDec *mpg123_decoder;

  hard = hard;

  GST_LOG_OBJECT (dec, "Flushing decoder");

  mpg123_decoder = GST_MPG123_AUDIO_DEC (dec);

  g_assert (mpg123_decoder->handle != NULL);

  /* Flush by reopening the feed */
  mpg123_close (mpg123_decoder->handle);
  error = mpg123_open_feed (mpg123_decoder->handle);

  if (G_UNLIKELY (error != MPG123_OK)) {
    GST_ELEMENT_ERROR (dec, LIBRARY, INIT, (NULL),
        ("Error while reopening mpg123 feed: %s",
            mpg123_plain_strerror (error)));
    mpg123_close (mpg123_decoder->handle);
    mpg123_delete (mpg123_decoder->handle);
    mpg123_decoder->handle = NULL;
  }

  mpg123_decoder->has_next_audioinfo = FALSE;

  /* opening/closing feeds do not affect the format defined by the
   * mpg123_format() call that was made in gst_mpg123_audio_dec_set_format(),
   * and since the up/downstream caps are not expected to change here, no
   * mpg123_format() calls are done */
}
Exemplo n.º 2
0
Mpg123Input::Mpg123Input(const QString &fileName)
{
    handle=new Handle;

    QByteArray fName=QFile::encodeName(fileName);
    bool ok=false;
    int result;
    handle->mpg123 = mpg123_new(NULL, &result);
    if (handle->mpg123 &&
        MPG123_OK==mpg123_open(handle->mpg123, fName.constData()) &&
        MPG123_OK==mpg123_getformat(handle->mpg123, &handle->rate, &handle->channels, &handle->encoding) &&
        MPG123_OK==mpg123_format_none(handle->mpg123) &&
        MPG123_OK==mpg123_format(handle->mpg123, handle->rate, handle->channels, MPG123_ENC_FLOAT_32)) {

        mpg123_close(handle->mpg123);
        if (MPG123_OK==mpg123_open(handle->mpg123, fName.constData()) &&
            MPG123_OK==mpg123_getformat(handle->mpg123, &handle->rate, &handle->channels, &handle->encoding)) {
            ok=true;
        }
    }

    if (!ok) {
        if (handle->mpg123) {
            mpg123_close(handle->mpg123);
            mpg123_delete(handle->mpg123);
            handle->mpg123 = NULL;
        }
        delete handle;
        handle = 0;
    }
}
Exemplo n.º 3
0
static void libmpg123_shutdown() {
	
	if(mh != NULL) {
		mpg123_close(mh);
	}
	
    mpg123_exit();

#ifdef BS_SIZE
	if (bs_buffer) {
		free(bs_buffer);
		bs_buffer = NULL;
	}
#endif
	if (pcm_buffer) {
		free(pcm_buffer);
		pcm_buffer = NULL;
	}
#ifdef BS_SIZE
	if (mp3_fd) {
		fs_close(mp3_fd);
		mp3_fd = 0;
	}
#endif
}
Exemplo n.º 4
0
//------------------------------------------------------------
void ofOpenALSoundPlayer::unload(){
	stop();
	ofRemoveListener(ofEvents().update,this,&ofOpenALSoundPlayer::update);

	// Only lock the thread where necessary.
	{
		std::unique_lock<std::mutex> lock(mutex);

		// Delete sources before buffers.
		alDeleteSources(sources.size(),&sources[0]);
		alDeleteBuffers(buffers.size(),&buffers[0]);

		sources.clear();
		buffers.clear();
	}

	// Free resources and close file descriptors.
#ifdef OF_USING_MPG123
	if(mp3streamf){
		mpg123_close(mp3streamf);
		mpg123_delete(mp3streamf);
	}
	mp3streamf = 0;
#endif

	if(streamf){
		sf_close(streamf);
	}
	streamf = 0;

	bLoadedOk = false;
}
Exemplo n.º 5
0
int attribute_align_arg mpg123_open_feed(mpg123_handle *mh)
{
	if(mh == NULL) return MPG123_ERR;

	mpg123_close(mh);
	return open_feed(mh);
}
Exemplo n.º 6
0
int attribute_align_arg mpg123_open_fd(mpg123_handle *mh, int fd)
{
	if(mh == NULL) return MPG123_ERR;

	mpg123_close(mh);
	return open_stream(mh, NULL, fd);
}
Exemplo n.º 7
0
/* plain file access, no http! */
int attribute_align_arg mpg123_open(mpg123_handle *mh, const char *path)
{
	if(mh == NULL) return MPG123_ERR;

	mpg123_close(mh);
	return open_stream(mh, path, -1);
}
Exemplo n.º 8
0
Arquivo: mpeg.c Projeto: d99kris/namp
void mpeg_close(int fd)
{
    if((handle != NULL) && (fd != -1))
    {
        if(handle->buf != NULL)
        {
            free(handle->buf);
            handle->buf = NULL;
        }

        if(handle->device != NULL)
        {
            ao_close(handle->device);
            handle->device = NULL;
        }

        if(handle->mh != NULL)
        {
            mpg123_close(handle->mh);
            mpg123_delete(handle->mh);
            handle->mh = NULL;
        }

        free(handle);
        handle = NULL;
    }
}
Exemplo n.º 9
0
int main(int argc, char *argv[]){

	if(argc < 2)
		return 0;

	ao_initialize();

	mpg123_init();
	mh = mpg123_new(NULL, NULL);
	mpg123_open_feed(mh);

	CURL *curl = curl_easy_init();
	curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, play_stream);
	curl_easy_setopt(curl, CURLOPT_URL, argv[1]);
	curl_easy_perform(curl);
	curl_easy_cleanup(curl);

	mpg123_close(mh);
	mpg123_delete(mh);
	mpg123_exit();

	ao_close(dev);
	ao_shutdown();

	return 0;
}
Exemplo n.º 10
0
//--------------------------------------------------------------
void ofxSoundFile::close(){
#ifdef OF_USING_SNDFILE
	if(sndFile){
		sf_close(sndFile);
		sndFile = NULL;
	}
	samples_read = 0;
#endif
#ifdef OF_USING_LAD
	if ( audioDecoder )
		delete audioDecoder;
	audioDecoder = NULL;
#endif
#ifdef OF_USING_MPG123
	if(mp3File){
		mpg123_close(mp3File);
		mpg123_delete(mp3File);
		mp3File = NULL;
	}
#endif
	channels = 1;
	duration = 0; //in secs
	samplerate = 0;
	samples = 0;
}
Exemplo n.º 11
0
void MusicPlayer::play(const char *filename)
	{
#ifdef USE_OGG
	stb_vorbis_close(v);
        stb_vorbis_alloc t;
	t.alloc_buffer=this->buf;
	t.alloc_buffer_length_in_bytes=STB_BUFSIZE;
	// stb_vorbis has char* pointer even though it is not really writing to buffer
	v = stb_vorbis_open_filename((char *)filename, &error, &t);
#endif

#ifdef USE_MP3
	mpg123_close(mh);
	error = mpg123_open(mh, filename);

	if (!error)
		{
		error = mpg123_getformat(mh, &rate, &channels, &encoding);

		rate = AUDIO_FREQUENCY;
		channels = 2;

		mpg123_format_none(mh);
		mpg123_format(mh, rate, channels, encoding);

		}
#endif
	}
Exemplo n.º 12
0
/***********************************************************************
 *           MPEG3_StreamClose
 *
 */
static	LRESULT	MPEG3_StreamClose(PACMDRVSTREAMINSTANCE adsi)
{
    mpg123_close(((AcmMpeg3Data*)adsi->dwDriver)->mh);
    mpg123_delete(((AcmMpeg3Data*)adsi->dwDriver)->mh);
    HeapFree(GetProcessHeap(), 0, (void*)adsi->dwDriver);
    return MMSYSERR_NOERROR;
}
Exemplo n.º 13
0
void CLOSE()
{
	mpg123_close(musicfile);
	mpg123_delete(musicfile);
	if ( fd > -1 )
	{
		close( fd );
		fd = -1;
	}

	if ( Type == 2 )
	{
		delete[] data;
		if ( f )
			url_fclose(f);
		f = NULL;
	}

	if ( Type == 2 )
		unloadCURL();

	IsPlaying = false;

	pix = QImage();
	id3Str.clear();

	_DATA_BUFF = 0;
}
Exemplo n.º 14
0
Arquivo: scan.c Projeto: 5py/libmpg123
int main(int argc, char **argv)
{
	mpg123_handle *m;
	int i;
	if(argc < 2)
	{
		fprintf(stderr, "\nI will give you the estimated and exact sample lengths of MPEG audio files.\n");
		fprintf(stderr, "\nUsage: %s <mpeg audio file list>\n\n", argv[0]);
		return -1;
	}
	mpg123_init();
	m = mpg123_new(NULL, NULL);
	mpg123_param(m, MPG123_RESYNC_LIMIT, -1, 0); /* New in library version 0.0.1 . */
	for(i = 1; i < argc; ++i)
	{
		off_t a, b;
		
		mpg123_open(m, argv[i]);

		a = mpg123_length(m);		
		mpg123_scan(m);
		b = mpg123_length(m);

		mpg123_close(m);

		printf("File %i: estimated %li vs. scanned %li\n", i, (long)a, (long)b);
	}

	mpg123_delete(m);
	mpg123_exit();
	return 0;
}
Exemplo n.º 15
0
/*****************************************************************************
 * MPG123Open
 *****************************************************************************/
static int MPG123Open( decoder_t *p_dec )
{
    decoder_sys_t *p_sys = p_dec->p_sys;

    /* Create our mpg123 handle */
    if( ( p_sys->p_handle = mpg123_new( NULL, NULL ) ) == NULL )
    {
        msg_Err( p_dec, "mpg123 error: can't create handle" );
        return VLC_EGENERIC;
    }

    /* Open a new bitstream */
    if( mpg123_open_feed( p_sys->p_handle ) != MPG123_OK )
    {
        msg_Err( p_dec, "mpg123 error: can't open feed" );
        mpg123_delete( p_sys->p_handle );
        return VLC_EGENERIC;
    }

    /* Disable resync stream after error */
    mpg123_param( p_sys->p_handle, MPG123_ADD_FLAGS, MPG123_NO_RESYNC, 0 );

    /* Setup output format */
    mpg123_format_none( p_sys->p_handle );

    int i_ret = MPG123_OK;
    if( p_dec->fmt_in.audio.i_rate != 0 )
    {
        i_ret =  mpg123_format( p_sys->p_handle, p_dec->fmt_in.audio.i_rate,
                                MPG123_MONO | MPG123_STEREO,
                                MPG123_ENC_FLOAT_32 );
    }
    else
    {
        /* The rate from the input is unknown. Tell mpg123 to accept all rates
         * to avoid conversion on their side */
        static const long mp3_rates[] = {
            8000, 11025, 12000, 16000, 22050, 24000, 32000, 44100, 48000,
        };
        for( size_t i = 0;
            i < sizeof(mp3_rates) / sizeof(*mp3_rates) && i_ret == MPG123_OK;
            ++i )
        {
            i_ret =  mpg123_format( p_sys->p_handle, mp3_rates[i],
                                    MPG123_MONO | MPG123_STEREO,
                                    MPG123_ENC_FLOAT_32 );
        }
    }
    if( i_ret != MPG123_OK )
    {
        msg_Err( p_dec, "mpg123 error: %s",
                 mpg123_strerror( p_sys->p_handle ) );
        mpg123_close( p_sys->p_handle );
        mpg123_delete( p_sys->p_handle );
        return VLC_EGENERIC;
    }

    p_sys->b_opened = true;
    return VLC_SUCCESS;
}
Exemplo n.º 16
0
bool MPG123Decoder::seek(size_t ms_offset, bool ms, bool mayrestart)
{
	int enc, channels;
	long srate;

	if (!mayrestart || ms_offset > 0)
	{
		if (mpg123_getformat(MPG123, &srate, &channels, &enc) == MPG123_OK)
		{
			size_t smp_offset = ms ? (size_t)((double)ms_offset / 1000. * srate) : ms_offset;
			if (mpg123_seek(MPG123, (off_t)smp_offset, SEEK_SET) >= 0)
			{
				Done = false;
				return true;
			}
		}
		return false;
	}
	else
	{
		// Restart the song instead of rewinding. A rewind seems to cause distortion when done repeatedly.
		// offset is intentionally ignored here.
		if (MPG123)
		{
			mpg123_close(MPG123);
			mpg123_delete(MPG123);
			MPG123 = 0;
		}
		Reader.Seek(0, FileReader::SeekSet);
		// Do not call open with our own reader variable, that would be catastrophic.
		auto reader = std::move(Reader);
		return open(reader);
	}
}
Exemplo n.º 17
0
int test_whence(const char* path, int scan_before)
{
	int err = MPG123_OK;
	mpg123_handle* mh = NULL;
	off_t length, pos;

	mh = mpg123_new(NULL, &err );
	if(mh == NULL) return -1;

	err = mpg123_open(mh, path );
	if(err != MPG123_OK) return -1;

	if(scan_before) mpg123_scan(mh);

	pos = mpg123_seek( mh, 0, SEEK_END);
	if(pos < 0){ error1("seek failed: %s", mpg123_strerror(mh)); return -1; }

	pos = mpg123_tell(mh);
	length = mpg123_length(mh);

	/* Later: Read samples and compare different whence values with identical seek positions. */

	mpg123_close(mh);
	mpg123_delete(mh);

	fprintf(stdout, "length %"OFF_P" vs. pos %"OFF_P"\n", length, pos);

	return (pos == length) ? 0 : -1;
}
Exemplo n.º 18
0
static void destroy(void* _mp3_info) 
{
  mp3_t* mp3_info = (mp3_t* ) _mp3_info;
  
  post_event(mp3_info->player_control, INTERNAL_CMD_DESTROY, -1);
  pthread_join(mp3_info->player_thread, NULL);
  
  aodev_close(mp3_info->ao_handle);
  aodev_destroy(mp3_info->ao_handle);
  
  mpg123_close(mp3_info->handle);
  mpg123_delete(mp3_info->handle);
  
  audio_event_fifo_destroy(mp3_info->player_control);
  
  mp3_stream_fifo_destroy(mp3_info->stream_fifo);
  
  mc_free(mp3_info->file_or_url);
  
  mc_free(mp3_info->buffer);
  
  psem_destroy(mp3_info->length_set);
  psem_destroy(mp3_info->stream_ready);
  
  mc_free(mp3_info);
  
  log_debug("DETROY OK");
}
Exemplo n.º 19
0
Arquivo: tpod.c Projeto: grafoo/tpod
void play_stream(char *stream_uri) {

  ch = curl_easy_init();
  if (ch) {
    curl_easy_setopt(ch, CURLOPT_URL, stream_uri);
    curl_easy_setopt(ch, CURLOPT_FOLLOWLOCATION, 1L);
    curl_easy_setopt(ch, CURLOPT_WRITEFUNCTION, write_callback);
    curl_easy_setopt(ch, CURLOPT_PROGRESSFUNCTION, progress_callback);
    curl_easy_setopt(ch, CURLOPT_NOPROGRESS,
                     0L); // make curl use the progress_callback

    mh = mpg123_new(NULL, NULL);
    if (mh) {
      mpg123_open_feed(mh);

      curl_easy_perform(ch);
      curl_easy_cleanup(ch);

      mpg123_close(mh);
      mpg123_delete(mh);

      ao_close(device);

      playback_stop = 0;
    }
  }
}
//------------------------------------------------------------
bool ofOpenALSoundPlayer::mpg123ReadFile(string path,vector<short> & buffer,vector<float> & fftAuxBuffer){
	int err = MPG123_OK;
	mpg123_handle * f = mpg123_new(NULL,&err);
	if(mpg123_open(f,path.c_str())!=MPG123_OK){
		ofLogError("ofOpenALSoundPlayer") << "mpg123ReadFile(): couldn't read \"" << path << "\"";
		return false;
	}

	mpg123_enc_enum encoding;
	long int rate;
	mpg123_getformat(f,&rate,&channels,(int*)&encoding);
	if(encoding!=MPG123_ENC_SIGNED_16){
		ofLogError("ofOpenALSoundPlayer") << "mpg123ReadFile(): " << getMpg123EncodingString(encoding)
			<< " encoding for \"" << path << "\"" << " unsupported, expecting MPG123_ENC_SIGNED_16";
		return false;
	}
	samplerate = rate;

	size_t done=0;
	size_t buffer_size = mpg123_outblock( f );
	buffer.resize(buffer_size/2);
	while(mpg123_read(f,(unsigned char*)&buffer[buffer.size()-buffer_size/2],buffer_size,&done)!=MPG123_DONE){
		buffer.resize(buffer.size()+buffer_size/2);
	};
	buffer.resize(buffer.size()-(buffer_size/2-done/2));
	mpg123_close(f);
	mpg123_delete(f);

	fftAuxBuffer.resize(buffer.size());
	for(int i=0;i<(int)buffer.size();i++){
		fftAuxBuffer[i] = float(buffer[i])/32565.f;
	}
	duration = float(buffer.size()/channels) / float(samplerate);
	return true;
}
Exemplo n.º 21
0
bool MPG123Decoder::seek(size_t ms_offset, bool ms, bool mayrestart)
{
	int enc, channels;
	long srate;

	if (!mayrestart || ms_offset > 0)
	{
		if (mpg123_getformat(MPG123, &srate, &channels, &enc) == MPG123_OK)
		{
			size_t smp_offset = ms ? (size_t)((double)ms_offset / 1000. * srate) : ms_offset;
			if (mpg123_seek(MPG123, (off_t)smp_offset, SEEK_SET) >= 0)
			{
				Done = false;
				return true;
			}
		}
		return false;
	}
	else
	{
		// Restart the song instead of rewinding. A rewind seems to cause distortion when done repeatedly.
		// offset is intentionally ignored here.
		if (MPG123)
		{
			mpg123_close(MPG123);
			mpg123_delete(MPG123);
			MPG123 = 0;
		}
		Reader->Seek(0, SEEK_SET);
		return open(Reader);
	}
}
Exemplo n.º 22
0
int stream_open(stream *stream, const char *url)
{
    fprintf(stderr, "stream_open: %s\n", url);
    stream->url = sdsnew(url);

    response *response = resolve_stream(url);

    if (response == NULL) {
        return -1;
    }

    if (stream->fd > 3 && fd_is_valid(stream->fd)) {
        close(stream->fd);
        mpg123_close(stream->mpg123);
    }
    
    stream->fd = response->fd;
    free_response(response);

    if (mpg123_open_fd(stream->mpg123, stream->fd) != MPG123_OK) {
        return -1;
    }
    
    return 0;
}
//------------------------------------------------------------
bool ofOpenALSoundPlayer_TimelineAdditions::mpg123ReadFile(string path,vector<short> & buffer,vector<float> & fftAuxBuffer){
	int err = MPG123_OK;
	mpg123_handle * f = mpg123_new(NULL,&err);
	if(mpg123_open(f,path.c_str())!=MPG123_OK){
		ofLog(OF_LOG_ERROR,"ofOpenALSoundPlayer_TimelineAdditions: couldnt read " + path);
		return false;
	}

	int encoding;
	long int rate;
	mpg123_getformat(f,&rate,&channels,&encoding);
	if(encoding!=MPG123_ENC_SIGNED_16){
		ofLog(OF_LOG_ERROR,"ofOpenALSoundPlayer_TimelineAdditions: unsupported encoding");
		return false;
	}
	samplerate = rate;

	size_t done=0;
	size_t buffer_size = mpg123_outblock( f );
	buffer.resize(buffer_size/2);
	while(mpg123_read(f,(unsigned char*)&buffer[buffer.size()-buffer_size/2],buffer_size,&done)!=MPG123_DONE){
		buffer.resize(buffer.size()+buffer_size/2);
	};
	buffer.resize(buffer.size()-(buffer_size/2-done/2));
	mpg123_close(f);
	mpg123_delete(f);

	fftAuxBuffer.resize(buffer.size());
	for(int i=0;i<(int)buffer.size();i++){
		fftAuxBuffer[i] = float(buffer[i])/32565.f;
	}
	duration = float(buffer.size()/channels) / float(samplerate);
	return true;
}
Exemplo n.º 24
0
void cleanup(mpg123_handle *mh)
{
	/* It's really to late for error checks here;-) */
	mpg123_close(mh);
	mpg123_delete(mh);
	mpg123_exit();
}
Exemplo n.º 25
0
int attribute_align_arg mpg123_open_handle(mpg123_handle *mh, void *handle)
{
	struct wrap_data* ioh;

	if(mh == NULL) return MPG123_ERR;

	mpg123_close(mh);
	ioh = mh->wrapperdata;
	if(ioh != NULL && ioh->iotype == IO_HANDLE && ioh->r_h_read != NULL)
	{
		/* Wrap the custom handle into my handle. */
		int err;
		err = MPG123_LARGENAME(mpg123_replace_reader_handle)(mh, wrap_read, wrap_lseek, wrap_io_cleanup);
		if(err != MPG123_OK) return MPG123_ERR;

		ioh->handle = handle;
		/* No extra error handling, keep behaviour of the original open_handle. */
		return open_stream_handle(mh, ioh);
	}
	else
	{
		/* This is an error ... you need to prepare the I/O before using it. */
		mh->err = MPG123_BAD_CUSTOM_IO;
		return MPG123_ERR;
	}
}
Exemplo n.º 26
0
int attribute_align_arg mpg123_open_fd(mpg123_handle *mh, int fd)
{
	struct wrap_data* ioh;

	if(mh == NULL) return MPG123_ERR;

	mpg123_close(mh);
	ioh = mh->wrapperdata;
	if(ioh != NULL && ioh->iotype == IO_FD)
	{
		int err;
		err = MPG123_LARGENAME(mpg123_replace_reader_handle)(mh, wrap_read, wrap_lseek, wrap_io_cleanup);
		if(err != MPG123_OK) return MPG123_ERR;

		/* The above call implied mpg123_close() already */

		/* Store the real file descriptor inside the handle. */
		ioh->fd = fd;
		/* Initiate I/O operating on my handle now. */
		err = open_stream_handle(mh, ioh);
		if(err != MPG123_OK)
		{
			wrap_io_cleanup(ioh);
			return MPG123_ERR;
		}
		/* All fine... */
		return MPG123_OK;
	}
	else return MPG123_LARGENAME(mpg123_open_fd)(mh, fd);
}
Exemplo n.º 27
0
/* Reader replacement prepares the hidden handle storage for next mpg123_open_fd() or plain mpg123_open(). */
int attribute_align_arg mpg123_replace_reader(mpg123_handle *mh, ssize_t (*r_read) (int, void *, size_t), long (*r_lseek)(int, long, int) )
{
	struct wrap_data* ioh;

	if(mh == NULL) return MPG123_ERR;

	mpg123_close(mh);
	ioh = wrap_get(mh);
	if(ioh == NULL) return MPG123_ERR;

	/* If both callbacks are NULL, switch totally to internal I/O, else just use fallback for at most half of them. */
	if(r_read == NULL && r_lseek == NULL)
	{
		/* Only the type is actually important to disable the code. */
		ioh->iotype = 0;
		ioh->fd = -1;
		ioh->r_read = NULL;
		ioh->r_lseek = NULL;
	}
	else
	{
		ioh->iotype = IO_FD;
		ioh->fd = -1; /* On next mpg123_open_fd(), this gets a value. */
		ioh->r_read = r_read != NULL ? r_read : fallback_read;
		ioh->r_lseek = r_lseek != NULL ? r_lseek : fallback_lseek;
	}

	/* The real reader replacement will happen while opening. */
	return MPG123_OK;
}
Exemplo n.º 28
0
SharedPtr<Decoder> Mpg123DecoderFactory::createDecoder(SharedPtr<std::istream> file)
{
    if(!mIsInited)
        return SharedPtr<Decoder>(nullptr);

    mpg123_handle *mpg123 = mpg123_new(0, 0);
    if(mpg123)
    {
        if(mpg123_replace_reader_handle(mpg123, r_read, r_lseek, 0) == MPG123_OK &&
           mpg123_open_handle(mpg123, file.get()) == MPG123_OK)
        {
            int enc, channels;
            long srate;

            if(mpg123_getformat(mpg123, &srate, &channels, &enc) == MPG123_OK)
            {
                if((channels == 1 || channels == 2) && srate > 0 &&
                   mpg123_format_none(mpg123) == MPG123_OK &&
                   mpg123_format(mpg123, srate, channels, MPG123_ENC_SIGNED_16) == MPG123_OK)
                {
                    // All OK
                    return SharedPtr<Decoder>(new Mpg123Decoder(file, mpg123, channels, srate));
                }
            }
            mpg123_close(mpg123);
        }
        mpg123_delete(mpg123);
    }

    return SharedPtr<Decoder>(nullptr);
}
Exemplo n.º 29
0
static uint8_t * ReadMP3(Sound_t * Sound, const uint8_t * InData, size_t FileSize){
    mpg123_handle *mh;
    if(mpg123_init() != MPG123_OK || (mh = mpg123_new(NULL, NULL)) == NULL){
        mpg123_exit();
        return NULL;
    }

    long rate;
    int channels, encoding;
    unsigned samples;
    size_t OutSize;
    uint8_t * OutData;

    if(mpg123_format_none(mh) != MPG123_OK ||
        mpg123_format(mh, 44100, MPG123_MONO | MPG123_STEREO, MPG123_ENC_SIGNED_16) != MPG123_OK ||
        mpg123_open_feed(mh) != MPG123_OK ||
        mpg123_feed(mh, InData, FileSize) != MPG123_OK ||
        mpg123_set_filesize(mh, FileSize) != MPG123_OK ||
        mpg123_getformat(mh, &rate, &channels, &encoding) != MPG123_OK ||
        (samples = mpg123_length(mh)) == 0 ||
        (OutData = (uint8_t*) malloc(OutSize = samples * channels * 2)) == NULL
    ){
        mpg123_close(mh);
        mpg123_delete(mh);
        mpg123_exit();
        return NULL;
    }

    size_t decoded;
    mpg123_read(mh, OutData, OutSize, &decoded);
    mpg123_close(mh);
    mpg123_delete(mh);
    mpg123_exit();

    if(decoded != OutSize){
        free(OutData);
        return NULL;
    }

    Sound->Channels = channels;
    Sound->SamplingRate = rate;
    Sound->BitDepth = 16;
    Sound->Duration = samples;
    Sound->Data = OutData;
    return OutData;
}
Exemplo n.º 30
-1
bool FileFormatSupport( const char *fileE )
{
	FILE *f = qmp_fopen( fileE, "rb" );
	if ( !f )
		return 0;

	int _DATA_BUFF;
	if ( !getDataBuff( f, (size_t(*)(void *, size_t, size_t, void *))fread, _DATA_BUFF, NULL ) )
	{
		fclose(f);
		return false;
	}
	int TagSize = _DATA_BUFF - DATA_BUFF;

	bool loaded(0);
	mpg123_handle *mus = mpg123_new(NULL, NULL);
	mpg123_open_feed( mus );
	fseek(f,TagSize,0);
	char *data = new char[DATA_BUFF];
	int bread = fread( data, 1, DATA_BUFF, f );
	fclose(f);
	mpg123_decode( mus, (const unsigned char*)data, bread, 0,0,0 );
	delete[] data;
	loaded = getMusInfo( mus, 0,0,0,0,0, -1, "" );
	mpg123_close(mus);
	mpg123_delete(mus);
	return loaded;
}