#include <v_lib.h>

int main()
{
	void *buffer;
	u32_t len;
	vhandle_t wave, out;
	logStartConsoleLog();
	logUpperLevel(LOG_TRACE);
	wave=wavOpenRead("../../samples/media/guide.wav");
	if(wave == NULL)
		return -1;
	conPrintf("%s, %d samples per second, %d bits per sample\n",
		wavNumChannels(wave) == 1 ? "mono" : "stereo",
		wavSamplingFrequency(wave),
		wavBitsPerSample(wave));
	len=(wavBitsPerSample(wave)*wavNumChannels(wave)>>3)*
		wavNumSamples(wave);
	if(!fileControl(wave,pctl_map_ispace,&buffer))
	{
		conPuts("Unable to map input space of source.\n");
		fileClose(wave);
		return -1;
	}
	out=wavOpenWrite("test.wav",wavNumChannels(wave),
		wavSamplingFrequency(wave),wavBitsPerSample(wave));
	fileWrite(out,buffer,len);
	fileClose(wave);
	fileClose(out);
	
	memPrintStats();
	return 0;
}
