Beispiel #1
0
bool RealSoundOgg::OpenStream(void* pData, int nMaxSize)
{
	if (m_bOpened) Close();

	m_nOggMaxSize = nMaxSize;
	ov_callbacks callbacks = {ReadCallback, SeekCallback, CloseCallback, TellCallback};

	if (ov_open_callbacks(pData, &m_vf, NULL, 0, callbacks) < 0) 
	{
		m_nOggMaxSize = 0;
		return false;
	}

	m_nLength = (int)ov_time_total(&m_vf, -1) * 1000;

	if (!CreateSoundBuffer())
	{
		m_nOggMaxSize = 0;
		return false;
	}

	m_bOpened = true;

	return true;
}
HRESULT CBSoundAVI::InitializeBuffer(PAVISTREAM Stream)
{
	if(!Stream) return E_FAIL;

	SetStreaming(true);
	m_Type = SOUND_SFX;
	m_Looping = false;

	m_AudioStream = Stream;

	LONG FormatSize;
	if(AVIStreamReadFormat(m_AudioStream, 0, NULL, &FormatSize)!=0) return E_FAIL;

	LPWAVEFORMAT Format = (LPWAVEFORMAT)new BYTE[FormatSize];
	if(AVIStreamReadFormat(m_AudioStream, 0, Format, &FormatSize)!=0){
		delete [] (BYTE*)Format;
		return E_FAIL;
	}
	
	m_TotalDataLength = AVIStreamLength(m_AudioStream) * Format->nBlockAlign;


	HRESULT ret;

	memcpy(&m_Format, Format, sizeof(PCMWAVEFORMAT));
	m_Format.wf.wFormatTag = WAVE_FORMAT_PCM;
	
	// create buffer
	ret = CreateSoundBuffer(m_TotalDataLength, (PCMWAVEFORMAT*)Format);

	
	delete [] (BYTE*)Format;

	return ret;
}
Beispiel #3
0
//---------------------------------------------------------------------------
void __fastcall StartPlay(const WAVEFORMATEXTENSIBLE * wfx, tTVPWaveLoopManager * manager)
{
	TBufferWriteLock lock;
	Manager = manager;

	CreateSoundBuffer(wfx);

	Playing = true;
	FillSecondaryBuffer();
	SoundBuffer->Play(0,0,DSBPLAY_LOOPING);
}
Beispiel #4
0
bool RealSoundOgg::Open(const char* szFileName)
{
	if (m_bOpened) Close();

	FILE* fp = fopen(szFileName, "rb");
	if (!fp) return false;

	ov_open(fp, &m_vf, NULL, 0);

	if (!CreateSoundBuffer())
	{
		fclose(fp);
		return false;
	}

	m_bOpened = true;

	return true;
}
Beispiel #5
0
CDSBuffer::CDSBuffer(const char *FileName, LPDIRECTSOUND lpDS, DWORD dwFlags)
{
	// Reset the sound buffer
	m_lpDSBuffer = NULL;
	
	// Reset the 3D buffer
	m_lpDS3DBuffer = NULL;
	
	// Open the wave file       
	FILE* pFile = fopen(FileName, "rb");
	if(!pFile)
		return;
	
	// Read in the wave header          
	WaveHeader wavHdr;
	if (fread(&wavHdr, sizeof(wavHdr), 1, pFile) != 1) 
	{
		fclose(pFile);
		return;
	}
	
	// Figure out the size of the data region
	DWORD dwSize = wavHdr.dwDSize;
	
	// Is this a stereo or mono file?
	BOOL bStereo = wavHdr.wChnls > 1 ? true : false;
	
	// Create the sound buffer for the wave file
	if(CreateSoundBuffer(lpDS, dwFlags, dwSize, wavHdr.dwSRate, wavHdr.BitsPerSample, wavHdr.wBlkAlign, bStereo))
	{
		// Read the data for the wave file into the sound buffer
		if (!ReadData(pFile, dwSize, sizeof(wavHdr)))
			;//MessageBox(g_hWnd,"Error - DS - Reading Data","Error",MB_OK);
		else if (dwFlags & DSBCAPS_CTRL3D)
		{
			// Get pointer to 3D buffer
			if (S_OK != m_lpDSBuffer->QueryInterface(IID_IDirectSound3DBuffer, (void **)&m_lpDS3DBuffer))
				MessageBox(g_hWnd,"DirectSound3DBuffer not available","Error",MB_OK);
		}
	}
	
	fclose(pFile);
}
Beispiel #6
0
BOOL CDirectSound :: Create(LPVOID pSoundData, CWnd * pWnd) {
	if(pWnd == 0)
		pWnd = AfxGetApp()->GetMainWnd();

	ASSERT(pWnd != 0);
	ASSERT(::IsWindow(pWnd->GetSafeHwnd()));

	ASSERT(pSoundData != 0);

	//////////////////////////////////////////////////////////////////
	// create direct sound object
	
	if( m_lpDirectSound == 0 ) {
		// Someone might use sounds for starting apps. This may cause
		// DirectSoundCreate() to fail because the driver is used by
		// anyone else. So wait a little before starting with the work ...
		HRESULT hRes = DS_OK;
		short nRes = 0;

		do {
			if( nRes )
				::Sleep(500);
			hRes = ::DirectSoundCreate(0, &m_lpDirectSound, 0);
			++nRes;
		} while( nRes < 10 && (hRes == DSERR_ALLOCATED || hRes == DSERR_NODRIVER) );

		if( hRes != DS_OK )
			return FALSE;
	
		m_lpDirectSound->SetCooperativeLevel(pWnd->GetSafeHwnd(), DSSCL_NORMAL);
	}

	ASSERT(m_lpDirectSound != 0);

	WAVEFORMATEX * pcmwf;
	if( ! GetWaveData(pSoundData, pcmwf, m_pTheSound, m_dwTheSound) ||
		! CreateSoundBuffer(pcmwf) ||
		! SetSoundData(m_pTheSound, m_dwTheSound) )
		return FALSE;

	return TRUE;
}
Beispiel #7
0
HRESULT CSBuffer::Extract(CSound *pDS, LONG lSize, char *ptr, int Num)
{
	HRESULT rval;

	// Release all memory, befor continue
	Release();
	
	// Check the Parameters
	if( ptr == NULL ) return DSERR_INVALIDPARAM;
	if( pDS == NULL ) return DSERR_INVALIDPARAM;
	if( pDS->GetDS() == NULL ) return DSERR_UNINITIALIZED;
	if( m_Streamed ) return DSERR_INVALIDPARAM;

	if( Num<1 ) Num = 1;
	
	m_pDS      = pDS;
	m_nBuffers = Num;
	m_Filename = NULL;
	
	if( strncmp( ptr, "RIFF", 4 ) || strncmp( ptr+8, "WAVE", 4 ) )
		return DSERR_BADFORMAT;

	DWORD hSize = *(DWORD*)(ptr+16);
	LPWAVEFORMATEX lpWav = (LPWAVEFORMATEX)(ptr+20);
	
	// skip all "fact" and search for the data
	// the fact stores the uncompressed filesize
	DWORD dSize = 0;
	ptr += 20 + hSize;
	do
	{
		if( dSize ) ptr += dSize + 8;
		    dSize = *(DWORD*)(ptr+4);
	} while( !strncmp( ptr, "fact", 4 ) );
	ptr += 8;

	// Is it compressed or a normal PCM Wave File
	if( lpWav->wFormatTag == WAVE_FORMAT_PCM )
	{
		// Create the sound buffer for the wave file
		rval = CreateSoundBuffer( dSize, (PCMWAVEFORMAT*)lpWav, Num );
		if(FAILED(rval)) return rval;
			
		// Read the data for the wave file into the sound buffer
		rval = ReadDataFromMemory( ptr, dSize );
		if(FAILED(rval)) return rval;
	}

		
	// Duplicate Buffers
	for( int i = 1; i < m_nBuffers; i++ )
	{
		rval = m_pDS->GetDS()->DuplicateSoundBuffer(m_lpDSB[0], &m_lpDSB[i]);
		if(FAILED(rval)) return rval;

		if( m_3d )
		{
			rval = m_lpDSB[0]->QueryInterface(IID_IDirectSound3DBuffer, (LPVOID *)&m_lp3dBuffer[i]);
			if(FAILED(rval)) return rval;
		}
	}
	
	return DS_OK;
	//return DSERR_UNSUPPORTED;
}