#include <v_lib.h>

/*
 * Support for ESounD is now in LibV itself.
 */
 
int main(int argc,char *argv[])
{
	file_t in;
	u32_t len;
	u8_t buf[4096];
	vhandle_t wp;
	if(argc != 2)
	{
		printf("usage: %s <mp3 file>\n",argv[0]);
		return -1;
	}
	logStartConsoleLog();
	logUpperLevel(LOG_TRACE);
	wp=wavePlaybackOpen(2,44100,16);
	if(!wp)
		return -1;
	in=mp3Open(argv[1]);
	if(!in)
	{
		fileClose(wp);
		return -1;
	}
	do
	{
		len=fileRead(in,buf,4096);
		fileWrite(wp,buf,len);
	} while(len);
	{
		int arg = 0;
		do
		{
			fileControl(wp,pctl_waveout_get_pending_samples,&arg);
			timeDelay(1);
		}
		while(arg);
	}
	fileClose(in);
	fileClose(wp);
	
	return 0;
}
