Example #1
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;
}
AudioSourceMpg123::AudioSourceMpg123(const char* filename) : AudioSource(filename)
{
	rate_ = 0;
	channelCount_ = 0;
	sampleCount_ = 0;

	int err = MPG123_OK;
	mpg123_handle* mh = mpg123_new(NULL, &err);

	if (mh == NULL || err != MPG123_OK)
		return;

/*	if (mpg123_open(mh, filename) != MPG123_OK)
	{
		mpg123_delete(mh);
		return;
	} */
	G_FILE* file = g_fopen(filename, "rb");
	if (file == NULL)
	{
		mpg123_delete(mh);
		return;
	}
	mpg123_replace_reader_handle(mh, mpg123read, mpg123lseek, mpg123cleanup);
	if (mpg123_open_handle(mh, file) != MPG123_OK)
	{
		mpg123_delete(mh);
		return;
	}

	int  channels = 0, encoding = 0;
	long rate = 0;

	if (mpg123_getformat(mh, &rate, &channels, &encoding) !=  MPG123_OK)
	{
		mpg123_delete(mh);
		return;
	}

	// Signed 16 is the default output format anyways (encoding == MPG123_ENC_SIGNED_16); 
	// it would actually by only different if we forced it.

	// Ensure that this output format will not change (it could, when we allow it).
	mpg123_format_none(mh);
	mpg123_format(mh, rate, channels, encoding);

	rate_ = rate;
	channelCount_ = channels;
	mpg123_scan(mh);
	sampleCount_ = mpg123_length(mh);

	mpg123_close(mh);
	mpg123_delete(mh);
}
Example #3
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;
}
Example #4
0
bool nuiAudioDecoderPrivate::Init()
{
    int err = MPG123_OK;
    if (sMpg123Counter == 0)
    {
        // init mpg123 library
        err = mpg123_init();
        if (err != MPG123_OK)
            return false;
        sMpg123Counter++;
    }

    // new handle
    mpHandle = mpg123_new(NULL, &err);
    if (!mpHandle)
        return false;

    // open decoder and prepare for direct feeding
    err = mpg123_open_feed(mpHandle);
    if (err != MPG123_OK)
    {
        mpg123_delete(mpHandle);
        mpHandle = NULL;
        return false;
    }

    return true;
}
Example #5
0
File: scan.c Project: 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;
}
Example #6
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;
}
Example #7
0
void safe_exit(int code)
{
	char *dummy, *dammy;

	dump_close();
#ifdef HAVE_TERMIOS
	if(param.term_ctrl)
		term_restore();
#endif
	if(have_output) exit_output(ao, intflag);

	if(mh != NULL) mpg123_delete(mh);

	if(cleanup_mpg123) mpg123_exit();

	httpdata_free(&htd);

#ifdef WANT_WIN32_UNICODE
	win32_cmdline_free(argc, argv); /* This handles the premature argv == NULL, too. */
#endif
#if defined (WANT_WIN32_SOCKETS)
	win32_net_deinit();
#endif
	/* It's ugly... but let's just fix this still-reachable memory chunk of static char*. */
	split_dir_file("", &dummy, &dammy);
	exit(code);
}
//------------------------------------------------------------
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;
}
Example #9
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;
}
Example #10
0
static void ReturnWaveToPool( SYS_Wave* wave )
{
	assert( wave );

	// remove wave from usedList.
	if ( wave->prev )
		wave->prev->next = wave->next;
	if ( wave->next )
		wave->next->prev = wave->prev;
	if ( usedList == wave )
		usedList = wave->next;
	if ( wave->mh )
		mpg123_delete(wave->mh);
	
	// add wave to head of freeList
	wave->next = freeList;
	wave->prev = 0;
	if ( freeList )
		freeList->prev = wave;
	freeList = wave;

#ifdef SYS_SOUNDDEBUG
	soundsLoaded--;
	soundsFree++;
#endif

}
//--------------------------------------------------------------
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;
}
Example #12
0
File: tpod.c Project: 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;
    }
  }
}
Example #13
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);
	}
}
Example #14
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;
    }
}
Example #15
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);
	}
}
Example #16
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);
}
//------------------------------------------------------------
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;
}
//------------------------------------------------------------
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;
}
Example #19
0
void cleanup(mpg123_handle *mh)
{
	/* It's really to late for error checks here;-) */
	mpg123_close(mh);
	mpg123_delete(mh);
	mpg123_exit();
}
Example #20
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");
}
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 */
}
Example #22
0
File: mpeg.c Project: 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;
    }
}
Example #23
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;
}
Example #24
0
AudioStreamerMpg123::AudioStreamerMpg123(AudioSourceMpg123* source, int loops) : AudioStreamer(source, loops)
{
	handle_ = NULL;

	int err = MPG123_OK;
	mpg123_handle* mh = mpg123_new(NULL, &err);

	if (mh == NULL || err != MPG123_OK)
		return;

/*	if (mpg123_open(mh, source->fileName()) != MPG123_OK)
	{
		mpg123_delete(mh);
		return;
	}*/
	G_FILE* file = g_fopen(source->fileName(), "rb");
	if (file == NULL)
	{
		mpg123_delete(mh);
		return;
	}
	mpg123_replace_reader_handle(mh, mpg123read, mpg123lseek, mpg123cleanup);
	if (mpg123_open_handle(mh, file) != MPG123_OK)
	{
		mpg123_delete(mh);
		return;
	}


	int  channels = 0, encoding = 0;
	long rate = 0;

	if (mpg123_getformat(mh, &rate, &channels, &encoding) !=  MPG123_OK)
	{
		mpg123_delete(mh);
		return;
	}

	// Signed 16 is the default output format anyways (encoding == MPG123_ENC_SIGNED_16); 
	// it would actually by only different if we forced it.

	// Ensure that this output format will not change (it could, when we allow it).
	mpg123_format_none(mh);
	mpg123_format(mh, rate, channels, encoding);

	handle_ = mh;
}
int main(int argc, char **argv)
{
	int ret = 0;
	size_t errs[2] = {0, 0};
	size_t errs_ntom[2] = {0, 0};

	if(argc < arg_total)
	{
		fprintf(stderr, "\nUsage: %s <decoder> <preframes> <mpeg audio file>\n\n", argv[0]);
		return -1;
	}
	mpg123_init();
	m = mpg123_new(argv[arg_decoder], NULL);
	mpg123_param(m, MPG123_RESYNC_LIMIT, -1, 0);

	if(mpg123_param(m, MPG123_PREFRAMES, atol(argv[arg_preframes]), 0) == MPG123_OK)
	printf("Testing library with preframes set to %li\n", atol(argv[arg_preframes]));

	filename = argv[arg_file];
	ret = check_seeking(errs);

	if(ret == 0)
	{
		printf("Now with NtoM resampling to 33333 Hz!");
		mpg123_param(m, MPG123_FORCE_RATE, 33333, 0);
		ret = check_seeking(errs_ntom);
	}
	else fprintf(stderr, "Some failure occured! Unable to test properly!");

	printf("\n");
	printf("1to1 indexed seek errors: %"SIZE_P" / %"SIZE_P"\n", (size_p)errs[0],(size_p)samples);
	printf("1to1 non-indexed seek errors: %"SIZE_P" / %"SIZE_P"\n", (size_p)errs[1],(size_p)samples);
	printf("NtoM indexed seek errors: %"SIZE_P" / %"SIZE_P"\n", (size_p)errs_ntom[0],(size_p)samples);
	printf("NtoM non-indexed seek errors: %"SIZE_P" / %"SIZE_P"\n", (size_p)errs_ntom[1],(size_p)samples);
	printf("Errors in getting first sample again: %"SIZE_P"\n", first_sample_errs);
	printf("\n");

	if(ret == 0)
	{

		if(first_sample_errs == 0 && errs[0] == 0 && errs[1] == 0 && errs_ntom[0] == 0 && errs_ntom[1] == 0)
		{
			printf("Congratulations, all seeks were accurate!\n");
			printf("But be warned: Not _all_ sample offsets have been tested. This result just means that the basic mechanism of sample-accurate seeking seems to work.\n");
		}
		else
		{
			printf("There have been some errors. For layer 3 files, this may be due to too low MPG123_PREFRAMES.\n");
			ret = -1;
		}

	}
	else fprintf(stderr, "Some bad failure during checking!\n");

	mpg123_delete(m);
	mpg123_exit();

	return ret;
}
Example #26
0
void gaudio_Mp3Close(g_id gid)
{
    GGMp3Handle *handle = (GGMp3Handle*)gid;

    mpg123_close(handle->mh);
    mpg123_delete(handle->mh);
    delete handle;
}
Example #27
0
static void uninit(struct dec_audio *da)
{
    struct ad_mpg123_context *con = da->priv;

    mpg123_close(con->handle);
    mpg123_delete(con->handle);
    mpg123_exit();
}
Example #28
0
static void S_MP3_CodecCloseStream (snd_stream_t *stream)
{
	mp3_priv_t *priv = (mp3_priv_t *) stream->priv;
	mpg123_close(priv->handle);
	mpg123_delete(priv->handle);
	Z_Free(stream->priv);
	S_CodecUtilClose(&stream);
}
Example #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;
}
Example #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;
}