예제 #1
0
static void* mpglib_callback(snd_stream_hnd_t hnd, int size, int * actual) {
	//static	int frames = 0;
	int ret, rsize;

	/* Check for file not started or file finished */
	if (mp3_fd == 0)
		return NULL;

	/* Dump the last PCM packet */
	pcm_empty(pcm_discard);

	/* Loop decoding until we have a full buffer */
	while (pcm_count < size) {
		//printf("decoding previously loaded frame into %08x, %d bytes possible\n", pcm_ptr, PCM_WATER - pcm_count);
		
		ret = decodeMP3(&mp, NULL, 0, pcm_ptr, PCM_WATER - pcm_count, &rsize);
		//ret = decodeMP3_clipchoice(&mp, NULL, 0, pcm_ptr, &rsize, synth_1to1_mono, synth_1to1);
		//printf("ret was %s, size is %d\n", ret == MP3_OK ? "OK" : "ERROR", rsize);
		
		if (ret != MP3_OK) {
			//printf("Refilling the buffer\n");
			// Pull in some more data (and check for EOF) 
			if (bs_fill() < 0) {
				printf("Decode completed\r\n");
				goto errorout;
			}
			//printf("trying decode again...\n");
			ret = decodeMP3(&mp, bs_buffer, BS_SIZE, pcm_ptr, PCM_WATER - pcm_count, &rsize);
			//ret = decodeMP3_clipchoice(&mp, bs_ptr, BS_SIZE, pcm_ptr, &size, synth_1to1_mono, synth_1to1);
			//printf("ret was %s, size is %d\n", ret == MP3_OK ? "OK" : "ERROR", rsize);
			//bs_ptr += (8*1024); bs_count -= (8*1024);
		}

		pcm_ptr += rsize; pcm_count += rsize;
		//frames++;
		
		/*if (!(frames % 64)) {
			printf("Decoded %d frames    \r", frames);
		}*/
	}

	pcm_discard = *actual = size;

	/* Got it successfully */
	return pcm_buffer;

errorout:
	fs_close(mp3_fd); mp3_fd = 0;
	return NULL;
}
예제 #2
0
/* This callback is called each time the sndstream driver needs
   some more data. It will tell us how much it needs in bytes. */
static void* mpglib_callback(int req_size) {
	int size, ret;
	
	/* Check for file not started or file finished */
	if (mp3_fd == 0)
		return NULL;

	/* Dump the last PCM packet */
	pcm_empty(req_size);

	/* Loop decoding until we have a full buffer */
	while (pcm_count < req_size) {
		/* Decode frames until we run out of data or space */
		printf("decoding previously loaded frame into %08x, %d bytes possible\n",
			pcm_ptr, PCM_WATER - pcm_count);
		ret = decodeMP3(&mp, NULL, 0,
			pcm_ptr, PCM_WATER - pcm_count,
			&size);
		printf("ret was %s, size is %d\n",
			ret == MP3_OK ? "OK" : "ERROR", size);
		if (ret != MP3_OK) {
			printf("Refilling the buffer\n");
			/* Pull in some more data (and check for EOF) */
			if (bs_fill() < 0) {
				printf("Decode completed\r\n");
				goto errorout;
			}
			printf("trying decode again...\n");
			ret = decodeMP3(&mp, bs_buffer, BS_SIZE,
				pcm_ptr, PCM_WATER - pcm_count,
				&size);
			printf("ret was %s, size is %d\n",
				ret == MP3_OK ? "OK" : "ERROR", size);
		}

		pcm_ptr += size; pcm_count += size;

		/* frames++;
		if (!(frames % 64)) {
			printf("Decoded %d frames    \r", frames);
		}*/
	}

	/* Got it successfully */
	return pcm_buffer;

errorout:
	fs_close(mp3_fd); mp3_fd = 0;
	return NULL;
}
예제 #3
0
/* This callback is called each time the sndstream driver needs
   some more data. It will tell us how much it needs in bytes. */
static void* xing_callback(snd_stream_hnd_t hnd, int size, int * actual) {
	static	int frames = 0;
	IN_OUT	x;

	/* Check for file not started or file finished */
	if (mp3_fd == 0)
		return NULL;

	/* Dump the last PCM packet */
	pcm_empty(pcm_discard);

	/* Loop decoding until we have a full buffer */
	while (pcm_count < size) {
		/* Pull in some more data (and check for EOF) */
		if (bs_fill() < 0 || bs_count < frame_bytes) {
			printf("Decode completed\r\n");
			goto errorout;
		}

		/* Decode a frame */
		x = audio_decode(&mpeg, bs_ptr, (short*)pcm_ptr);
		if (x.in_bytes <= 0) {
			printf("Bad sync in MPEG file\r\n");
			goto errorout;
		}

		bs_ptr += x.in_bytes; bs_count -= x.in_bytes;
		pcm_ptr += x.out_bytes; pcm_count += x.out_bytes;
		
		frames++;
		/*if (!(frames % 64)) {
			printf("Decoded %d frames    \r", frames);
		}*/
	}

	pcm_discard = *actual = size;

	/* Got it successfully */
	return pcm_buffer;

errorout:
	fs_close(mp3_fd); mp3_fd = 0;
	return NULL;
}
예제 #4
0
/* This callback is called each time the sndstream driver needs
   some more data. It will tell us how much it needs in bytes. */
static void* mpg123_callback(snd_stream_hnd_t hnd, int size, int * actual) {
	//static	int frames = 0;
	size_t done = 0;
	int err = 0;

#ifdef BS_SIZE
	/* Check for file not started or file finished */
	if (mp3_fd == 0)
		return NULL;
#endif

	/* Dump the last PCM packet */
	pcm_empty(pcm_discard);

	/* Loop decoding until we have a full buffer */
	while (pcm_count < size) {
		
#ifdef BS_SIZE		
		/* Pull in some more data (and check for EOF) */
		
		if (bs_fill() < 0 || bs_count < decinfo.framesize) {
			printf("snd_mp3_server: Decode completed\r\n");
			goto errorout;
		}
		err = mpg123_decode(mh, bs_ptr, decinfo.framesize, pcm_ptr, size, &done); 
#else
		err = mpg123_read(mh, pcm_ptr, size, &done);
#endif

		switch(err) {
			case MPG123_DONE:
				printf("snd_mp3_server: Decode completed\r\n");
				goto errorout;
			case MPG123_NEED_MORE:
				printf("snd_mp3_server: MPG123_NEED_MORE\n");
				break;
			case MPG123_ERR:
				printf("snd_mp3_server: %s\n", (char*)mpg123_strerror(mh));
				goto errorout;
				break;
			default:
				break;
		}
		
#ifdef BS_SIZE
		bs_ptr += decinfo.framesize; bs_count -= decinfo.framesize;
#endif
		pcm_ptr += done; pcm_count += done;
		
		//frames++;
		//if (!(frames % 64)) {
			//printf("Decoded %d frames    \r", frames);
		//}
	}

	pcm_discard = *actual = size;

	/* Got it successfully */
	return pcm_buffer;

errorout:
#ifdef BS_SIZE
	fs_close(mp3_fd); mp3_fd = 0;
#endif
	return NULL;
}