Ejemplo n.º 1
0
int soundStart(unsigned long ulWaveIndex)
{
	if(9<ulWaveIndex)
		ulWaveIndex=0; // safety check

	//g_ucPowerUpWav g_ucSoundWav9
    //if(WaveOpen((unsigned long *) sWaveClips[ulWaveIndex].pucWav,&xWaveHeader) == WAVE_OK)
    if(WaveOpen((unsigned long *) sWaveClips[ulWaveIndex].pucWav, &xWaveHeader)==0)
    //if(WaveOpen((unsigned long *) mk_ucSoundWav8, &xWaveHeader)==0)
    {
        WavePlayStart(&xWaveHeader);
        bWavPlaying = true;
        currentSongByteLength = getSoundSize(ulWaveIndex);
        // Re-enable vContinueSound()
        SchedulerTaskEnable(0, false);
    }

    return ulWaveIndex;
}
/* ------------------------------------------------------------------------------------ */
int StreamingAudio::Create(char *szFileName)
{
	int nError = 0;

	if(CCD->GetLogging())
	{
		char szDebug[512];
		sprintf(szDebug, "[INFO] Loaded %s", szFileName);
		CCD->ReportError(szDebug, false);
	}

	// Sanity check parameters
	if(szFileName == NULL)
		return RGF_FAILURE;										// Wrong.

// changed RF064
	int len = strlen(szFileName)-4;
	if(stricmp((szFileName+len),".mp3") == 0)
	{
		if(Mpeg3 != NULL)
			return RGF_FAILURE;
		Mpeg3 = new CMp3Manager;
		Mpeg3->OpenMediaFile(szFileName);
		mp3 = true;
		m_fActive = true;

		// start a timer for this stream.

		MMRESULT nTimer = timeSetEvent(125, 5, &TimerFunction, (DWORD)this,
										TIME_PERIODIC | TIME_CALLBACK_FUNCTION);

		if(nTimer == NULL)
		{
			CCD->ReportError("[WARNING] StreamingAudio: Timer callback set-up failed", false);
			return RGF_FAILURE;									// Timer startup failed.
		}

		m_nTimerID = nTimer;					// Save timer ID
		return RGF_SUCCESS;
	}

	mp3 = false;

	if(stricmp((szFileName+len), ".ogg") == 0)
	{
		if(Ogg != NULL)
			return RGF_FAILURE;

		Ogg = new OggAudio(m_pDS);
		Ogg->Load(szFileName);
		ogg = true;
		m_fActive = true;
		return RGF_SUCCESS;
	}

	ogg = false;

	//	start a timer for this stream.
	MMRESULT nTimer = timeSetEvent(125, 5, &TimerFunction, (DWORD)this,
						TIME_PERIODIC | TIME_CALLBACK_FUNCTION);

	if(nTimer == NULL)
	{
		CCD->ReportError("[WARNING] StreamingAudio: Timer callback set-up failed", false);
		return RGF_FAILURE;									// Timer startup failed.
	}

	m_nTimerID = nTimer;									// Save timer ID
// end change RF064

	//	Check for stream availability
	if(m_pStream != NULL)
		return RGF_FAILURE;									// Already loaded!

	// Open up the WAVE file.
	nError = WaveOpen(szFileName, &m_hWaveFile, &m_pWaveFormat,	&m_rRiffData);

	if(nError != RGF_SUCCESS)
	{
		char szBug[128];
		sprintf(szBug, "[WARNING] File %s - Line %d: Failed to open wave file '%s'\n(Note: streamig audio can't be placed in VFS)",
				__FILE__, __LINE__, szFileName);
		CCD->ReportError(szBug, false);
		return RGF_FAILURE;									// Problem here, too!
	}

	// Get current position in file, which will be the start of the
	// ..WAVE data.
	m_nDataPosition = mmioSeek(m_hWaveFile, 0, SEEK_CUR);
	m_nDataSize = m_rRiffData.cksize;						// Save data size

	// Fetch DirectSound interface we want
	LPDIRECTSOUND pDSIF;
	nError = m_pDS->QueryInterface(IID_IDirectSound, (LPVOID *)&pDSIF);

	// Create a DSound buffer to stream into
	DSBUFFERDESC theDesc;

	memset(&theDesc, 0, sizeof(DSBUFFERDESC));
	theDesc.dwSize = sizeof(DSBUFFERDESC);
	theDesc.dwBufferBytes = kBufferSize;
	theDesc.lpwfxFormat = m_pWaveFormat;
	theDesc.dwFlags = DSBCAPS_CTRLVOLUME;

	nError = pDSIF->CreateSoundBuffer(&theDesc, &m_pStream, NULL);

	pDSIF->Release();									// Done w/ this.

	if(nError != 0)										// Error!  Sick out.
	{
		char szBug[128];
		sprintf(szBug, "StreamingAudio: Failed to create buffer for '%s'\n", szFileName);
		OutputDebugString(szBug);
		mmioClose(m_hWaveFile, 0);
		m_hWaveFile = NULL;
		delete m_pWaveFormat;
		m_pWaveFormat = NULL;
		return RGF_FAILURE;
	}

	m_nOffset = 0;								// Start at top of buffer
// changed RF064
	//m_fActive = true;							// Set as active
// end change RF064
	PumpWave(kBufferSize);				// Initial buffer load

	return RGF_SUCCESS;
}