/// <summary>
/// Called instead of a constructor to acquire a WaveWriter
/// </summary>
/// <remarks>
/// Be sure to call Stop to close the object
/// </remarks>
/// <param name="fileName">Name the file to write to</param>
/// <param name="WaveFormat">Pointer to a WAVEFORMATEX structure describing the audio stream</param>
WaveWriter * WaveWriter::Start(const string& fileName,  const WAVEFORMATEX * WaveFormat )
{

    HANDLE fileHandle = CreateFile(fileName.c_str(), GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 
    FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, 
    NULL);

    if (fileHandle == NULL)
    {
        return NULL;
    }

    WaveWriter * writer = new WaveWriter(fileHandle, WaveFormat);
    //StringCchCopy(writer->m_szFilename, _countof(writer->m_szFilename), "xxxxxxxxxxxxxx.wav");

    // Yes, we do this twice.... Once to advance the write pointer so we don't lose any samples,
    // and then once to put in the right length.
    writer->WriteFileHeader();

    return writer;
}
示例#2
0
void WriteSample(s16 r, s16 l)
{

#if 0
	#if HOST_OS==OS_WINDOWS
		#ifdef LOG_SOUND
		rawout.Write(l,r);
		#endif

		if (!asRingFreeCount())
		{
			//printf("Buffer overrun\n");
			if (settings.aica.LimitFPS)
			{
				//speed_limit.Wait();
			}
			else
				return;
		}

		gen_samples++;
		//while limit on, 128 samples done, there is a buffer ready to be service AND speed is too fast then wait
		if (settings.aica.LimitFPS==1 && gen_samples>128)
		{
			for(;asRingUsedCount()>BufferSampleCount && (os_GetSeconds()-time_last)<=time_diff;)
				;
			gen_samples=0;
			time_last=os_GetSeconds();
		}
	#else
		if (!asRingFreeCount())
		{
			if (settings.aica.LimitFPS)
			{
				while(!asRingFreeCount()) ;
			}
			else
				return;
		}
	#endif
#endif


	const u32 ptr=(WritePtr+1)%RingBufferSampleCount;
	RingBuffer[ptr].r=r;
	RingBuffer[ptr].l=l;
	WritePtr=ptr;

	if (WritePtr==(SAMPLE_COUNT-1))
	{
		os_Push(RingBuffer,SAMPLE_COUNT,settings.aica.LimitFPS);
	}
}
示例#3
0
void WriteSample(s16 r, s16 l)
{
	#ifdef LOG_SOUND
	rawout.Write(l,r);
	#endif

	speed_limit.Reset();
	if (!asRingFreeCount())
	{
		if (settings.LimitFPS)
		{
			speed_limit.Wait();
		}
		else
			return;
	}

	gen_samples++;
	//while limit on, 128 samples done, there is a buffer ready to be service AND speed is too fast then wait ;p
	while (settings.LimitFPS==1 && gen_samples>128 && asRingUsedCount()>BufferSampleCount && QueryPerformanceCounter(&time_now) && (time_now.QuadPart-time_last.QuadPart)<=time_diff.QuadPart )
	{
		__noop;
	}

	if (settings.LimitFPS==1 && gen_samples>128)
	{
		gen_samples=0;
		QueryPerformanceCounter(&time_last);
	}

	const u32 ptr=(WritePtr+1)%RingBufferSampleCount;
	RingBuffer[ptr].r=r;
	RingBuffer[ptr].l=l;
	WritePtr=ptr;
	//if (0==(WritePtr&255))
	//printf("write done %d %d \n",ReadPtr,WritePtr);
}