コード例 #1
0
ファイル: oggDlg_ds.cpp プロジェクト: otoboku/oggYSEDbgm
BOOL COggDlg::ReleaseDXSound(void)
{
	if(m_ds){
		Closeds();
		if(m_dsb3d != NULL){m_dsb3d->Release();m_dsb3d =NULL;}
		if(m_dsb != NULL) {m_dsb->Release();m_dsb=NULL;}
		if (m_dsb1 != NULL) { m_dsb1->Release(); m_dsb1 = NULL; }
		if(m_lpDS3DBuffer != NULL){m_lpDS3DBuffer->Release();}
		m_dsb =NULL;
		m_lpDS3DBuffer= NULL;
		if(m_p!=NULL){m_p->Release();m_p=NULL;}

		if(m_ds){
			m_ds->Release();
			m_ds = NULL;
		}
	}
	return TRUE;
}
コード例 #2
0
ファイル: snd_win.c プロジェクト: Jaegermeiste/quake2_322
/*
** DS_DestroyBuffers
*/
static void DS_DestroyBuffers( void )
{
	Com_Printf( "Destroying DirectSound 8 buffers\n" );
	if ( pDS )
	{
		Com_Printf( "...setting NORMAL coop level\n" );
#ifdef QDSNDCOMPILERHACK
		pDS->lpVtbl->SetCooperativeLevel( pDS, cl_hwnd, DSSCL_NORMAL );
#else
		pDS->SetCooperativeLevel(cl_hwnd, DSSCL_NORMAL);
#endif
	}

	if ( pDSBuf )
	{
		Com_Printf( "...stopping and releasing secondary buffer\n" );
#ifdef QDSNDCOMPILERHACK
		pDSBuf->lpVtbl->Stop(pDSBuf);
		pDSBuf->lpVtbl->Release(pDSBuf);
#else
		pDSBuf->Stop();
		pDSBuf->Release();
#endif
	}
	
	// only release primary buffer if it's not also the mixing buffer we just released
	if ( pDSPBuf && ( pDSBuf != pDSPBuf ) )
	{
		Com_Printf( "...releasing primary buffer\n" );
#ifdef QDSNDCOMPILERHACK
		pDSPBuf->lpVtbl->Stop(pDSPBuf);
		pDSPBuf->lpVtbl->Release(pDSPBuf);
#else
		pDSPBuf->Stop();
		pDSPBuf->Release();
#endif
	}

	pDSBuf = NULL;
	pDSPBuf = NULL;

	dma.buffer = NULL;
}
コード例 #3
0
ファイル: sound.cpp プロジェクト: process/Project-8
void InitDSound()
{
    int seconds = 1;

    DirectSoundCreate8(NULL, &ds8, NULL);
    ds8->SetCooperativeLevel(window.getWindowHwnd(), DSSCL_NORMAL);

    waveFormat.wFormatTag = WAVE_FORMAT_PCM;
    waveFormat.nChannels = 1;
    waveFormat.nSamplesPerSec = 44100;
    waveFormat.wBitsPerSample = 16;
    waveFormat.nBlockAlign = (waveFormat.wBitsPerSample/8)*waveFormat.nChannels;
    waveFormat.nAvgBytesPerSec = waveFormat.nSamplesPerSec * waveFormat.nBlockAlign;
    waveFormat.cbSize = 0;

    memset(&bufdesc, 0, sizeof(DSBUFFERDESC)); 
    bufdesc.dwSize = sizeof(DSBUFFERDESC); 
    bufdesc.dwFlags = DSBCAPS_STATIC | DSBCAPS_GLOBALFOCUS;
    bufdesc.dwBufferBytes = waveFormat.nAvgBytesPerSec * seconds;
    bufdesc.guid3DAlgorithm = GUID_NULL;
    bufdesc.lpwfxFormat = &waveFormat;
}
コード例 #4
0
ファイル: DirectSound.cpp プロジェクト: u-stone/code-database
//get the DIRECTSOUNDBUFFER8 interface
HRESULT CreateBaseBuffer(LPDIRECTSOUND8 lpDirectSound, LPDIRECTSOUNDBUFFER8 * ppDsb8){
	WAVEFORMATEX wfx;
	DSBUFFERDESC dsbdesc;
	LPDIRECTSOUNDBUFFER pDsb = NULL;
	HRESULT hr;

	//set up WAV buffer format
	memset(&wfx, 0, sizeof(WAVEFORMATEX));
	wfx.wFormatTag = WAVE_FORMAT_PCM;
	wfx.nChannels = 2;
	wfx.nSamplesPerSec = 22050;
	wfx.nBlockAlign = 4;
	wfx.nAvgBytesPerSec = wfx.nSamplesPerSec * wfx.nBlockAlign;
	wfx.wBitsPerSample = 16;

	//set up DSBUFFERDESC structure
	memset(&dsbdesc, 0, sizeof(DSBUFFERDESC));
	dsbdesc.dwSize = sizeof(DSBUFFERDESC);
	//the rule of using following flags is that use only what you will control
	dsbdesc.dwFlags = 
		DSBCAPS_CTRLPAN | 
		DSBCAPS_CTRLVOLUME |   //IDirectSound::SetVolume() is success only if this flag was set
		DSBCAPS_CTRLFREQUENCY | 
		DSBCAPS_GLOBALFOCUS; //ensure that even if the window is in the backgroud,that mean you can hear the sound when you lose the focus of the window
	dsbdesc.dwBufferBytes = 3 * wfx.nAvgBytesPerSec;//create a buffer that is big enough to hold 3 seconds of streaming data
	dsbdesc.lpwfxFormat = &wfx;//if the was not specified, ds will place it in hardware-controlled memory.
	//you can check the location of the buffer by using GetCaps() function, 
	//create buffer
	hr = lpDirectSound->CreateSoundBuffer(&dsbdesc, &pDsb, NULL);
	if (SUCCEEDED(hr)){
		hr = pDsb->QueryInterface(IID_IDirectSoundBuffer8, (LPVOID*)ppDsb8);
		pDsb->Release();
	}
	//the created buffer owned by device object,and released when device object release the resources
	//you can also create multiple buffer by using function IDirectSound8::DuplicateSoundBuffer(),but the memory is share with original buffer,so if one buffer changed,others will be reflected.

	return hr;
}
コード例 #5
0
ファイル: snd_win.c プロジェクト: Jaegermeiste/quake2_322
/*
==================
SNDDMA_InitDirect

Direct-Sound support
==================
*/
sndinitstat SNDDMA_InitDirect (void)
{
	DSCAPS			dscaps;
	HRESULT			hresult;

	dma.channels = CHANNELS;
	dma.samplebits = SAMPLEBITS;

	Com_Printf( "Initializing DirectSound 8\n");

	if ( !hInstDS )
	{
		Com_Printf( "...loading dsound.dll: " );

		hInstDS = LoadLibrary("dsound.dll");
		
		if (hInstDS == NULL)
		{
			Com_Printf ("failed\n");
			return SIS_FAILURE;
		}

		Com_Printf ("ok\n");
		pDirectSoundCreate8 = GetProcAddress(hInstDS,"DirectSoundCreate8");

		if (!pDirectSoundCreate8)
		{
			Com_Printf ("*** couldn't get DirectSound 8 process address ***\n");
			return SIS_FAILURE;
		}
	}

	Com_Printf( "...creating DirectSound 8 object: " );
	while ( ( hresult = pDirectSoundCreate8( NULL, &pDS, NULL ) ) != DS_OK )
	{
		if (hresult != DSERR_ALLOCATED)
		{
			Com_Printf( "failed\n" );
			return SIS_FAILURE;
		}

		if (MessageBox (NULL,
						"The sound hardware is in use by another application.\n\n"
					    "Select Retry to try to start sound again or Cancel to run with no sound.",
						"Sound not available",
						MB_RETRYCANCEL | MB_SETFOREGROUND | MB_ICONEXCLAMATION) != IDRETRY)
		{
			Com_Printf ("failed, hardware already in use\n" );
			return SIS_NOTAVAIL;
		}
	}
	Com_Printf( "ok\n" );

	dscaps.dwSize = sizeof(dscaps);

#ifdef QDSNDCOMPILERHACK
	if ( DS_OK != pDS->lpVtbl->GetCaps( pDS, &dscaps ) )
#else
	if ( DS_OK != pDS->GetCaps( &dscaps ) )
#endif
	{
		Com_Printf ("*** couldn't get DirectSound 8 caps ***\n");
	}

	if ( dscaps.dwFlags & DSCAPS_EMULDRIVER )
	{
		Com_Printf ("...no DirectSound 8 driver found\n" );
		FreeSound();
		return SIS_FAILURE;
	}

	if ( !DS_CreateBuffers() )
		return SIS_FAILURE;

	dsound_init = 1;

	Com_Printf("...completed successfully\n" );

	return SIS_SUCCESS;
}
コード例 #6
0
ファイル: snd_win.c プロジェクト: Jaegermeiste/quake2_322
/*
==================
FreeSound
==================
*/
void FreeSound (void)
{
	int		i;

	Com_Printf( "Shutting down sound system\n" );

	if ( pDS )
		DS_DestroyBuffers();

	if ( hWaveOut )
	{
		Com_Printf( "...resetting waveOut\n" );
		waveOutReset (hWaveOut);

		if (lpWaveHdr)
		{
			Com_Printf( "...unpreparing headers\n" );
			for (i=0 ; i< WAV_BUFFERS ; i++)
				waveOutUnprepareHeader (hWaveOut, lpWaveHdr+i, sizeof(WAVEHDR));
		}

		Com_Printf( "...closing waveOut\n" );
		waveOutClose (hWaveOut);

		if (hWaveHdr)
		{
			Com_Printf( "...freeing WAV header\n" );
			GlobalUnlock(hWaveHdr);
			GlobalFree(hWaveHdr);
		}

		if (hData)
		{
			Com_Printf( "...freeing WAV buffer\n" );
			GlobalUnlock(hData);
			GlobalFree(hData);
		}

	}

	if ( pDS )
	{
		Com_Printf( "...releasing DirectSound 8 object\n" );
#ifdef QDSNDCOMPILERHACK
		pDS->lpVtbl->Release(pDS);
#else
		pDS->Release();
#endif
	}

	if ( hInstDS )
	{
		Com_Printf( "...freeing dsound.dll\n" );
		FreeLibrary( hInstDS );
		hInstDS = NULL;
	}

	pDS = NULL;
	pDSBuf = NULL;
	pDSPBuf = NULL;
	hWaveOut = 0;
	hData = 0;
	hWaveHdr = 0;
	lpData = NULL;
	lpWaveHdr = NULL;
	dsound_init = 0;
	wav_init = 0;
}
コード例 #7
0
ファイル: snd_win.c プロジェクト: Jaegermeiste/quake2_322
/*
** DS_CreateBuffers
*/
static int DS_CreateBuffers( void )
{
	DSBUFFERDESC	dsbuf;
	DSBCAPS			dsbcaps;
	WAVEFORMATEX	pformat, format;
	DWORD			dwWrite;

	memset (&format, 0, sizeof(format));
	format.wFormatTag = WAVE_FORMAT_PCM;
    format.nChannels = dma.channels;
    format.wBitsPerSample = dma.samplebits;
    format.nSamplesPerSec = dma.speed;
    format.nBlockAlign = format.nChannels * format.wBitsPerSample / 8;
    format.cbSize = 0;
    format.nAvgBytesPerSec = format.nSamplesPerSec * format.nBlockAlign; 

	Com_Printf( "Creating DirectSound 8 buffers\n" );

	Com_Printf("...setting PRIORITY coop level: " );
#ifdef QDSNDCOMPILERHACK
	if ( DS_OK != pDS->lpVtbl->SetCooperativeLevel( pDS, cl_hwnd, DSSCL_PRIORITY ) )
#else
	if ( DS_OK != pDS->SetCooperativeLevel( cl_hwnd, DSSCL_PRIORITY ) )
#endif
	{
		Com_Printf ("failed\n");
		FreeSound ();
		return 0;
	}
	Com_Printf("ok\n" );

// get access to the primary buffer, if possible, so we can set the
// sound hardware format
	memset (&dsbuf, 0, sizeof(dsbuf));
	dsbuf.dwSize = sizeof(DSBUFFERDESC);
	dsbuf.dwFlags = DSBCAPS_PRIMARYBUFFER; // | DSBCAPS_CTRL3D;
	dsbuf.dwBufferBytes = 0;
	dsbuf.lpwfxFormat = NULL;

	memset(&dsbcaps, 0, sizeof(dsbcaps));
	dsbcaps.dwSize = sizeof(dsbcaps);
	primary_format_set = 0;
	
	if (!pDSPBuf)
	{
		Com_Printf( "...creating primary buffer: " );
#ifdef QDSNDCOMPILERHACK
		if (DS_OK == pDS->lpVtbl->CreateSoundBuffer(pDS, &dsbuf, &pDSPBuf, NULL))
#else
		if (DS_OK == pDS->CreateSoundBuffer(&dsbuf, &pDSPBuf, NULL))
#endif
		{
			pformat = format;

			Com_Printf( "ok\n" );
#ifdef QDSNDCOMPILERHACK
			if (DS_OK != pDSPBuf->lpVtbl->SetFormat (pDSPBuf, &pformat))
#else
			if (DS_OK != pDSPBuf->SetFormat (&pformat))
#endif
			{
				if (snd_firsttime)
					Com_Printf ("...setting primary sound format: failed\n");
			}
			else
			{
				if (snd_firsttime)
					Com_Printf ("...setting primary sound format: ok\n");

				primary_format_set = 1;
			}
		}
		else
			Com_Printf( "failed\n" );
	}

	if ( !primary_format_set || !s_primary->value)
	{
		// create the secondary buffer we'll actually work with
		memset (&dsbuf, 0, sizeof(DSBUFFERDESC));
		dsbuf.dwSize = sizeof(DSBUFFERDESC);
		dsbuf.dwFlags = DSBCAPS_CTRLFREQUENCY | DSBCAPS_GETCURRENTPOSITION2 | DSBCAPS_LOCHARDWARE; //| DSBCAPS_MUTE3DATMAXDISTANCE; // | DSBCAPS_CTRL3D;	
		//dsbuf.dwFlags |= DSBCAPS_CTRLVOLUME;			// Allow volume control
		//dsbuf.dwBufferBytes = format.nAvgBytesPerSec * SECONDARY_BUFFER_LEN_SECONDS;
		dsbuf.dwBufferBytes = SECONDARY_BUFFER_SIZE * s_buffersize->value;
		dsbuf.lpwfxFormat = &format;
		//dsbuf.guid3DAlgorithm = DS3DALG_DEFAULT;
		//dsbuf.guid3DAlgorithm = DS3DALG_HRTF_FULL;	// Use high quality 3D processing

		memset(&dsbcaps, 0, sizeof(dsbcaps));
		dsbcaps.dwSize = sizeof(dsbcaps);

		Com_Printf( "...creating secondary buffer: " );

		//pDSPBuf->QueryInterface(IID_IDirectSoundBuffer8, (LPVOID*) pDSBuf);
		//myDirectSoundIID = &IID_IDirectSoundBuffer8;
		//pDSPBuf->lpVtbl->QueryInterface(pDSPBuf, myDirectSoundIID, &pDSBuf);

		if (!pDSBuf)
		{
			//MessageBox (NULL, "Got Here!\n\n", "Quake II", MB_OK | MB_SETFOREGROUND | MB_ICONEXCLAMATION);
#ifdef QDSNDCOMPILERHACK
			if (DS_OK != pDS->lpVtbl->CreateSoundBuffer(pDS, &dsbuf, &pDSBuf, NULL))
#else
			if (DS_OK != pDS->CreateSoundBuffer(&dsbuf, &pDSBuf, NULL))
#endif
			//if (DS_OK != pDSPBuf->lpVtbl->QueryInterface(pDSPBuf, myDirectSoundIID, &pDSBuf))
			{
				Com_Printf( "failed\n" );
				Com_Printf( "Attempting to locate buffer in software...\n");
				dsbuf.dwFlags = DSBCAPS_CTRLFREQUENCY | DSBCAPS_GETCURRENTPOSITION2 | DSBCAPS_LOCSOFTWARE;
				//pDSBuf->lpVtbl->Release(pDSBuf);
				pDSBuf = NULL;
#ifdef QDSNDCOMPILERHACK
				if (DS_OK != pDS->lpVtbl->CreateSoundBuffer(pDS, &dsbuf, &pDSBuf, NULL))
#else
				if (DS_OK != pDS->CreateSoundBuffer(&dsbuf, &pDSBuf, NULL))
#endif
				//if (DS_OK != pDSPBuf->lpVtbl->QueryInterface(pDSPBuf, myDirectSoundIID, &pDSBuf))
				{
					// NeVo - try switching to primary
					s_primary->value = 1;
					Com_Printf( "failed\n" );
					Com_Printf( "Attempting fallback to primary buffer...\n");
					//pDSBuf->lpVtbl->Release(pDSBuf);
					pDSBuf = NULL;
					return DS_CreateBuffers();
					//FreeSound ();
					//return 0;
				}
				Com_Printf( "ok\n" );
				Com_Printf( "Sound Buffer in Software\n" );
			}
			else
			{
			Com_Printf( "ok\n" );
			Com_Printf( "Sound Buffer in Hardware\n" );
			}
		}

		dma.channels = format.nChannels;
		dma.samplebits = format.wBitsPerSample;
		dma.speed = format.nSamplesPerSec;

#ifdef QDSNDCOMPILERHACK
		if (DS_OK != pDSBuf->lpVtbl->GetCaps (pDSBuf, &dsbcaps))
#else
		if (DS_OK != pDSBuf->GetCaps (&dsbcaps))
#endif
		{
			Com_Printf ("*** GetCaps failed ***\n");
			FreeSound ();
			return 0;
		}

		Com_Printf ("...using secondary sound buffer\n");
	}
	else
	{
		Com_Printf( "...using primary buffer\n" );

		Com_Printf( "...setting WRITEPRIMARY coop level: " );
#ifdef QDSNDCOMPILERHACK
		if (DS_OK != pDS->lpVtbl->SetCooperativeLevel (pDS, cl_hwnd, DSSCL_WRITEPRIMARY))
#else
		if (DS_OK != pDS->SetCooperativeLevel (cl_hwnd, DSSCL_WRITEPRIMARY))
#endif
		{
			Com_Printf( "failed\n" );
			FreeSound ();
			return 0;
		}
		Com_Printf( "ok\n" );

#ifdef QDSNDCOMPILERHACK
		if (DS_OK != pDSPBuf->lpVtbl->GetCaps (pDSPBuf, &dsbcaps))
#else
		if (DS_OK != pDSPBuf->GetCaps (&dsbcaps))
#endif
		{
			Com_Printf ("*** GetCaps failed ***\n");
			return 0;
		}

		pDSBuf = pDSPBuf;
	}

	// Make sure mixer is active
	//if ( !s_primary->value)
#ifdef QDSNDCOMPILERHACK
		pDSBuf->lpVtbl->Play(pDSBuf, 0, 0, DSBPLAY_LOOPING);
#else
	pDSBuf->Play (0, 0, DSBPLAY_LOOPING);
#endif
	//else
	//	pDSPBuf->lpVtbl->Play(pDSPBuf, 0, 0, DSBPLAY_LOOPING);
	
	if (snd_firsttime)
		Com_Printf("   %d channel(s)\n"
		               "   %d bits/sample\n"
					   "   %d bytes/sec\n",
					   dma.channels, dma.samplebits, dma.speed);
	
	gSndBufSize = dsbcaps.dwBufferBytes;

	/* we don't want anyone to access the buffer directly w/o locking it first. */
	lpData = NULL; 

	//if ( !s_primary->value)
	//{
#ifdef QDSNDCOMPILERHACK
		pDSBuf->lpVtbl->Stop(pDSBuf);
		pDSBuf->lpVtbl->GetCurrentPosition(pDSBuf, &mmstarttime.u.sample, &dwWrite);
		pDSBuf->lpVtbl->Play(pDSBuf, 0, 0, DSBPLAY_LOOPING);
#else
		pDSBuf->Stop();
		pDSBuf->GetCurrentPosition(&mmstarttime.u.sample, &dwWrite);
		pDSBuf->Play(0, 0, DSBPLAY_LOOPING);
#endif
	//}
	//else
	//{
	//	pDSPBuf->lpVtbl->Stop(pDSPBuf);
	//	pDSPBuf->lpVtbl->GetCurrentPosition(pDSPBuf, &mmstarttime.u.sample, &dwWrite);
	//	pDSPBuf->lpVtbl->Play(pDSPBuf, 0, 0, DSBPLAY_LOOPING);
	//}
	
	dma.samples = gSndBufSize/(dma.samplebits/8);
	dma.samplepos = 0;
	dma.submission_chunk = 1;
	dma.buffer = (unsigned char *) lpData;
	sample16 = (dma.samplebits/8) - 1;

	return 1;
}
コード例 #8
0
ファイル: SoundWave.cpp プロジェクト: underkround/mazerts
// Create
// create 'empty' sound buffer into the memory
HRESULT CSoundWave::Create(    CSoundEngine& soundEngine,
                            DWORD dwFrequency, 
                            DWORD dwBitsPerSample,
                            DWORD dwChannels,
                            DWORD dwBytes,
                            DWORD dwDuplicates,
                            DWORD dwFlags)
{
    // set original freq
    m_OriginalFrequency = dwFrequency;

    HRESULT            hres;
    WAVEFORMATEX    wfx;
    DSBUFFERDESC    desc;

    // init the wave format
    ::memset(&wfx, 0, sizeof(WAVEFORMATEX));
    wfx.wFormatTag = WAVE_FORMAT_PCM;
    wfx.nChannels = (WORD)dwChannels;
    wfx.nSamplesPerSec = dwFrequency;
    wfx.wBitsPerSample = (WORD)dwBitsPerSample;
    wfx.nBlockAlign = wfx.wBitsPerSample / 8 * wfx.nChannels;
    wfx.nAvgBytesPerSec = wfx.nSamplesPerSec * wfx.nBlockAlign;

    // init the buffer desc
    ::memset(&desc, 0, sizeof(DSBUFFERDESC));
    desc.dwSize = sizeof(DSBUFFERDESC);
    desc.dwFlags = dwFlags;
    desc.dwBufferBytes = dwBytes;
    desc.lpwfxFormat = &wfx;

    // create sound buffer(s)...
    LPDIRECTSOUND8    pDS = soundEngine.GetDirectSound();
    m_ppDSB = new LPDIRECTSOUNDBUFFER8[dwDuplicates + 1];
    if (!m_ppDSB)
    {
        return E_OUTOFMEMORY;
    }

    // set pointers in array to NULL
    ::memset(m_ppDSB, 0, sizeof(LPDIRECTSOUNDBUFFER8) * (dwDuplicates + 1));
    m_dwBufferCount = dwDuplicates + 1;


    // create the first sound buffer
    // first sound buffer is special one,
    // it is the only one that actually contains
    // any sound data. The duplicate buffers have only
    // separate play positions, pointing into the data
    // in first buffer
    LPDIRECTSOUNDBUFFER        pDSB = NULL;
    hres = pDS->CreateSoundBuffer(&desc, &pDSB, NULL);
    if (FAILED(hres))
    {
        Release();
        return hres;
    }

    // query the latest sound buffer interface
    hres = pDSB->QueryInterface(    IID_IDirectSoundBuffer8,
                                    (void**)&m_ppDSB[0]);
    pDSB->Release();
    if (FAILED(hres))
    {
        Release();
        return hres;
    }


    // create the duplicates
    DWORD i;
    for (i=0; i<dwDuplicates; i++)
    {
        if ((dwFlags & DSBCAPS_CTRLFX))
        {
            // real time effects required, all duplicate buffers
            // must have their own wave data
            hres = pDS->CreateSoundBuffer(&desc, &pDSB, NULL);
        }
        else
        {
            // no real time effect required, use duplicate buffers
            // to save memory
            hres = pDS->DuplicateSoundBuffer(m_ppDSB[0], &pDSB);
        }

        if (SUCCEEDED(hres))
        {
            hres = pDSB->QueryInterface(    IID_IDirectSoundBuffer8,
                                            (void**)&m_ppDSB[i + 1]);
            pDSB->Release();
            if (FAILED(hres))
            {
                Release();
                return hres;
            }
        }
        else
        {
            if (FAILED(hres))
            {
                Release();
                return hres;
            }
        }
    }

    return S_OK;
}
コード例 #9
0
ファイル: sound.cpp プロジェクト: process/Project-8
void KillDSound()
{
    ds8->Release();
}
コード例 #10
0
ファイル: dsoundplay.cpp プロジェクト: JensenSung/Mcast
/**
 * @brief Creates the primary buffer and the secondary buffers.
 * @param[in] p_direct_sound_8 pointer to the IDirectSound8 interface. This interface is a factory for creating both the primary buffer and the secondary buffers.
 * @param[out] pp_primary_buffer pointer to the memory location which will be written with the primary buffer interface pointer.
 * @param[out] pp_secondary_buffer pointer to the memory location which will be written with the secondary buffer interface pointer. 
 * @param[in] p_wfe pointer to the WAVEFORMATEX structure. This parameter defines the buffer format (number of samples per second, how many bytes per sample and so on).
 * @param[in] single_buffer_size size of the single play buffer
 * @return
 */
static HRESULT create_buffers(LPDIRECTSOUND8 p_ds, 
    WAVEFORMATEX * p_wfex,
    size_t number_of_chunks,
    size_t single_buffer_size,
    LPDIRECTSOUNDBUFFER * pp_primary_sound_buffer, 
    LPDIRECTSOUNDBUFFER8 * pp_secondary_sound_buffer)
{
    HRESULT hr;
    DSBUFFERDESC bufferDesc;
    LPDIRECTSOUNDBUFFER lpDSB = NULL;

    if (NULL != *pp_primary_sound_buffer || NULL != *pp_secondary_sound_buffer)
    {
        debug_outputln("%s %4.4u : %p %p", __FILE__, __LINE__, *pp_primary_sound_buffer, *pp_secondary_sound_buffer);
        return E_INVALIDARG;
    }
    ZeroMemory(&bufferDesc, sizeof(bufferDesc));
    bufferDesc.dwSize = sizeof(bufferDesc);
    bufferDesc.dwFlags = DSBCAPS_PRIMARYBUFFER; 
    bufferDesc.guid3DAlgorithm = DS3DALG_DEFAULT;
    /* All others must be null for primary buffer */
    hr = p_ds->CreateSoundBuffer(&bufferDesc, pp_primary_sound_buffer, NULL);
    if (FAILED(hr))
    {
        debug_outputln("%s %4.4u : %x", __FILE__, __LINE__, hr);
        goto error;
    }
    hr = (*pp_primary_sound_buffer)->SetFormat(p_wfex);
    if (FAILED(hr))
    {
        debug_outputln("%s %4.4u : %8.8x", __FILE__, __LINE__, hr);
        goto error;
    }
    get_buffer_caps("Primary: ", *pp_primary_sound_buffer);
    /* Secondary buffer */
    bufferDesc.dwFlags = DSBCAPS_CTRLVOLUME /* The buffer has volume control capability. */ 
        | DSBCAPS_CTRLPAN /* The buffer has pan control capability. */ 
        | DSBCAPS_CTRLFREQUENCY /* The buffer has frequency control capability. */ 
        | DSBCAPS_GLOBALFOCUS /* With this flag set, an application using DirectSound can continue to play its buffers if the user switches focus to another application, even if the new application uses DirectSound. */ 
        | DSBCAPS_CTRLPOSITIONNOTIFY; /* The buffer has position notification capability. */

    /* double buffering - one buffer being played, whereas the other is being filled in */
    bufferDesc.dwBufferBytes = number_of_chunks * single_buffer_size;
    bufferDesc.lpwfxFormat = p_wfex;
    hr = p_ds->CreateSoundBuffer(&bufferDesc, &lpDSB, NULL);
    if (FAILED(hr))
    {
        debug_outputln("%s %4.4u : %x", __FILE__, __LINE__, hr);
        goto error;
    }
    hr = lpDSB->QueryInterface(IID_IDirectSoundBuffer8, (LPVOID*)pp_secondary_sound_buffer);
    if (FAILED(hr))
    {
        debug_outputln("%s %4.4u : %x", __FILE__, __LINE__, hr);
        goto error;
    }
    get_buffer_caps("Secondary: ", *pp_secondary_sound_buffer);
    if (NULL != lpDSB)
    {
        lpDSB->Release();
        lpDSB = NULL;
    }
    return hr;
error:
    if (NULL != *pp_secondary_sound_buffer)
    {
        (*pp_secondary_sound_buffer)->Release();
        *pp_secondary_sound_buffer = NULL;
    }
    if (NULL != *pp_primary_sound_buffer)
    {
        (*pp_primary_sound_buffer)->Release();
        *pp_primary_sound_buffer = NULL;
    }
    if (NULL != lpDSB)
    {
        lpDSB->Release();
        lpDSB = NULL;
    }
    return hr;
}
コード例 #11
0
ファイル: tbSound.cpp プロジェクト: BackupTheBerlios/aigine
// ******************************************************************
// Laden einer WAV-Datei
LPDIRECTSOUNDBUFFER tbLoadWAVFile(LPDIRECTSOUND8 pDSound,
								  tbVFile* pVFile,
								  DWORD dwFlags,
								  GUID GUID3DAlgorithm)
{
	HRESULT				hResult;
	tbRIFFHeader		RIFFHeader;
	tbWAVChunkHeader	ChunkHeader;
	BOOL				bFormatChunkRead = FALSE;
	BOOL				bDataChunkRead = FALSE;
	DWORD				dwNumBytesToRead;
	WAVEFORMATEX		WaveFormat;
	void*				pSoundData = NULL;
	DSBUFFERDESC		BufferDesc;
	LPDIRECTSOUNDBUFFER	pSoundBuffer;
	void*				pSoundBufferData;
	DWORD				dwSoundBufferDataSize;


	// Parameter prüfen
	if(pDSound == NULL)	TB_ERROR_NULL_POINTER("pDSound", NULL);
	if(pVFile == NULL)	TB_ERROR_NULL_POINTER("pVFile", NULL);


    // RIFF-Header lesen und prüfen
	if(pVFile->Read(sizeof(tbRIFFHeader), &RIFFHeader)) TB_ERROR("Fehler beim Lesen des RIFF-Headers!", NULL);
	if(strnicmp(RIFFHeader.acRIFF, "RIFF", 4)) TB_ERROR("RIFF-Signatur nicht gefunden!", NULL);
	if(strnicmp(RIFFHeader.acFormat, "WAVE", 4)) TB_ERROR("WAVE-Signatur nicht gefunden - die Datei ist keine WAV-Datei!", NULL);

	// ------------------------------------------------------------------

	// WAV-Chunks einlesen
	while(TRUE)
	{
		// Chunk-Header lesen. Bei einem Lesefehler haben wir das Dateiende erreicht.
		if(pVFile->Read(sizeof(tbWAVChunkHeader), &ChunkHeader)) break;

		if(!strnicmp(ChunkHeader.acType, "fmt ", 4))
		{
			// Es ist der Format-Chunk!
			// Prüfen, ob die Größe der Daten in Ordnung ist. Wenn sie größer ist als
			// die Größe der WAVEFORMATEX-Struktur, dann lassen wir die restlichen Bytes weg.
			dwNumBytesToRead = TB_MIN(ChunkHeader.dwDataSize, sizeof(WAVEFORMATEX));
			if(pVFile->Read(dwNumBytesToRead, &WaveFormat)) TB_ERROR("Fehler beim Lesen des Soundformats!", NULL);
			bFormatChunkRead = TRUE;
		}
		else if(!strnicmp(ChunkHeader.acType, "data", 4))
		{
			// Es ist der Daten-Chunk!
			// Genügend Speicher reservieren und dann die Daten lesen.
			pSoundData = tbMemAlloc(ChunkHeader.dwDataSize);
			if(pSoundData == NULL) TB_ERROR_OUT_OF_MEMORY(NULL);
			if(pVFile->Read(ChunkHeader.dwDataSize, pSoundData)) TB_ERROR("Fehler beim Lesen der Sounddaten!", NULL);
			bDataChunkRead = TRUE;
		}
		else
		{
			// Unbekannter Chunk - überspringen
			pVFile->Seek(TB_VFSO_CURSOR, ChunkHeader.dwDataSize);
		}
	}

	// Prüfen, ob alle wichtigen Chunks vorhanden waren
	if(!(bFormatChunkRead && bDataChunkRead))
	{
		// Fehler!
		TB_SAFE_MEMFREE(pSoundData);
		TB_ERROR("Die Chunks \"fmt \" und \"data\" müssen beide vorhanden sein!", NULL);
	}

	// ------------------------------------------------------------------

	// DSBUFFERDESC-Struktur ausfüllen
	BufferDesc.dwSize			= sizeof(DSBUFFERDESC);
	BufferDesc.dwFlags			= dwFlags;
	BufferDesc.dwBufferBytes	= tbMemGetSize(pSoundData);
	BufferDesc.dwReserved		= 0;
	BufferDesc.lpwfxFormat		= &WaveFormat;
	BufferDesc.guid3DAlgorithm	= GUID3DAlgorithm;

	// Puffer erstellen
	if(FAILED(hResult = pDSound->CreateSoundBuffer(&BufferDesc,
		                                           &pSoundBuffer,
												   NULL)))
	{
		// Fehler!
		TB_ERROR_DIRECTX("pDSound->CreateSoundBuffer", hResult, NULL);
	}

	// ------------------------------------------------------------------

	// Puffer komplett sperren
	hResult = pSoundBuffer->Lock(0, 0, &pSoundBufferData, &dwSoundBufferDataSize, NULL, NULL, DSBLOCK_ENTIREBUFFER);
	if(FAILED(hResult))
	{
		// Fehler!
		TB_SAFE_MEMFREE(pSoundData);
		TB_SAFE_RELEASE(pSoundBuffer);
		TB_ERROR_DIRECTX("pSoundBuffer->Lock", hResult, NULL);
	}

	// Die Daten hineinschreiben und den Puffer entsperren
	memcpy(pSoundBufferData, pSoundData, TB_MIN(tbMemGetSize(pSoundData), (int)(dwSoundBufferDataSize)));
	pSoundBuffer->Unlock(pSoundBufferData, dwSoundBufferDataSize, NULL, 0);

	// Die Sounddaten freigeben
	TB_SAFE_MEMFREE(pSoundData);

	// Den Soundpuffer zurückliefern
	return pSoundBuffer;
}
コード例 #12
0
ファイル: Utils.cpp プロジェクト: bao-boyle/CZPlayer
bool DS_addDeviceRef(signed int deviceID)
{
    HWND ownerWindow;
    HRESULT res = DS_OK;
    LPDIRECTSOUND8 devPlay;
    LPDIRECTSOUNDCAPTURE8 devCapture;
    LPGUID lpGuid = NULL;

    if (g_audioDeviceCache[deviceID].dev == NULL)
    {
        /* Create DirectSound */
        //TRACE1("Creating DirectSound object for device %d\n", deviceID);
        lpGuid = &(g_audioDeviceCache[deviceID].guid);
        if (isEqualGUID(lpGuid, NULL))
        {
            lpGuid = NULL;
        }
        if (g_audioDeviceCache[deviceID].isSource)
        {
#if 0
            //CoInitialize(NULL);
            res = DirectSoundCreate8(lpGuid, &devPlay, NULL);		//生成DirectSound接口对象
#else
            res = CoInitializeEx(NULL, 0);
            res = CoCreateInstance(CLSID_DirectSound8,
                NULL,
                CLSCTX_INPROC_SERVER,
                IID_IDirectSound8,
                (LPVOID*)&devPlay);
            devPlay->Initialize(NULL);
#endif

            g_audioDeviceCache[deviceID].dev = (void*) devPlay;
        }
        else
        {
            res = DirectSoundCaptureCreate8(lpGuid, &devCapture, NULL);
            g_audioDeviceCache[deviceID].dev = (void*) devCapture;
        }
        g_audioDeviceCache[deviceID].refCount = 0;
        if (FAILED(res))
        {
            ERROR1("DS_addDeviceRef: ERROR: Failed to create DirectSound: %s", TranslateDSError(res));
            g_audioDeviceCache[deviceID].dev = NULL;
            return false;
        }
        if (g_audioDeviceCache[deviceID].isSource)
        {
            ownerWindow = GetForegroundWindow();
            if (ownerWindow == NULL)
            {
                ownerWindow = GetDesktopWindow();
            }
            //TRACE0("DS_addDeviceRef: Setting cooperative level\n");
            res = devPlay->SetCooperativeLevel(ownerWindow, DSSCL_PRIORITY);	//设置应用程序对声音设备的合作级别
            if (FAILED(res))
            {
                ERROR1("DS_addDeviceRef: ERROR: Failed to set cooperative level: %s", TranslateDSError(res));
                return false;
            }
        }
    }
    g_audioDeviceCache[deviceID].refCount++;
    return true;
}
コード例 #13
0
ファイル: snddx.cpp プロジェクト: BlueSplash/svn-desmume
int SNDDXInit(int buffersize)
{
	DSBUFFERDESC dsbdesc;
	WAVEFORMATEX wfx;
	HRESULT ret;
	char tempstr[512];

	if (FAILED(ret = DirectSoundCreate8(NULL, &lpDS8, NULL)))
	{
		sprintf(tempstr, "DirectSound8Create error: %s - %s", DXGetErrorString8(ret), DXGetErrorDescription8(ret));
		MessageBox (NULL, tempstr, "Error",  MB_OK | MB_ICONINFORMATION);
		return -1;
	}

	if (FAILED(ret = lpDS8->SetCooperativeLevel(MainWindow->getHWnd(), DSSCL_PRIORITY)))
	{
		sprintf(tempstr, "IDirectSound8_SetCooperativeLevel error: %s - %s", DXGetErrorString8(ret), DXGetErrorDescription8(ret));
		MessageBox (NULL, tempstr, "Error",  MB_OK | MB_ICONINFORMATION);
		return -1;
	}

	memset(&dsbdesc, 0, sizeof(dsbdesc));
	dsbdesc.dwSize = sizeof(DSBUFFERDESC);
	dsbdesc.dwFlags = DSBCAPS_PRIMARYBUFFER;
	dsbdesc.dwBufferBytes = 0;
	dsbdesc.lpwfxFormat = NULL;

	if (FAILED(ret = lpDS8->CreateSoundBuffer(&dsbdesc, &lpDSB, NULL)))
	{
		sprintf(tempstr, "Error when creating primary sound buffer: %s - %s", DXGetErrorString8(ret), DXGetErrorDescription8(ret));
		MessageBox (NULL, tempstr, "Error",  MB_OK | MB_ICONINFORMATION);
		return -1;
	}

	soundbufsize = buffersize * 2; // caller already multiplies buffersize by 2
	soundoffset = 0;

	memset(&wfx, 0, sizeof(wfx));
	wfx.wFormatTag = WAVE_FORMAT_PCM;
	wfx.nChannels = 2;
	wfx.nSamplesPerSec = DESMUME_SAMPLE_RATE;
	wfx.wBitsPerSample = 16;
	wfx.nBlockAlign = (wfx.wBitsPerSample / 8) * wfx.nChannels;
	wfx.nAvgBytesPerSec = wfx.nSamplesPerSec * wfx.nBlockAlign;

	if (FAILED(ret = lpDSB->SetFormat(&wfx)))
	{
		sprintf(tempstr, "IDirectSoundBuffer8_SetFormat error: %s - %s", DXGetErrorString8(ret), DXGetErrorDescription8(ret));
		MessageBox (NULL, tempstr, "Error",  MB_OK | MB_ICONINFORMATION);
		return -1;
	}

	memset(&dsbdesc, 0, sizeof(dsbdesc));
	dsbdesc.dwSize = sizeof(DSBUFFERDESC);
	dsbdesc.dwFlags = DSBCAPS_GLOBALFOCUS | DSBCAPS_STICKYFOCUS |
		DSBCAPS_CTRLVOLUME | DSBCAPS_GETCURRENTPOSITION2 |
		DSBCAPS_LOCHARDWARE;
	dsbdesc.dwBufferBytes = soundbufsize;
	dsbdesc.lpwfxFormat = &wfx;

	if (FAILED(ret = lpDS8->CreateSoundBuffer(&dsbdesc, &lpDSB2, NULL)))
	{
		if (ret == DSERR_CONTROLUNAVAIL ||
			ret == DSERR_INVALIDCALL ||
			ret == E_FAIL || 
			ret == E_NOTIMPL)
		{
			// Try using a software buffer instead
			dsbdesc.dwFlags = DSBCAPS_GLOBALFOCUS | DSBCAPS_STICKYFOCUS |
				DSBCAPS_CTRLVOLUME | DSBCAPS_GETCURRENTPOSITION2 |
				DSBCAPS_LOCSOFTWARE;

			if (FAILED(ret = lpDS8->CreateSoundBuffer(&dsbdesc, &lpDSB2, NULL)))
			{
				sprintf(tempstr, "Error when creating secondary sound buffer: %s - %s", DXGetErrorString8(ret), DXGetErrorDescription8(ret));
				MessageBox (NULL, tempstr, "Error",  MB_OK | MB_ICONINFORMATION);
				return -1;
			}
		}
		else
		{
			sprintf(tempstr, "Error when creating secondary sound buffer: %s - %s", DXGetErrorString8(ret), DXGetErrorDescription8(ret));
			MessageBox (NULL, tempstr, "Error",  MB_OK | MB_ICONINFORMATION);
			return -1;
		}
	}

	lpDSB2->Play(0, 0, DSBPLAY_LOOPING);

	if ((stereodata16 = new s16[soundbufsize / sizeof(s16)]) == NULL)
		return -1;

	memset(stereodata16, 0, soundbufsize);

	soundvolume = DSBVOLUME_MAX;
	issoundmuted = 0;

	doterminate = false;
	terminated = false;
	CreateThread(0,0,SNDDXThread,0,0,0);

	return 0;
}
コード例 #14
0
int SNDDMA_InitDS ()
{
	HRESULT			hresult;
	DSBUFFERDESC	dsbuf;
	DSBCAPS			dsbcaps;
	WAVEFORMATEX	format;

	Com_Printf( "Initializing DirectSound\n");

    // Create IDirectSound using the primary sound device
    if( FAILED( hresult = DirectSoundCreate8(NULL, &pDS, NULL) ) ) {
		Com_Printf ("failed\n");
		SNDDMA_Shutdown ();
		return false;
	}

	hresult = pDS->Initialize(NULL);

	Com_DPrintf( "ok\n" );

	Com_DPrintf("...setting DSSCL_PRIORITY coop level: " );

	if ( DS_OK != pDS->SetCooperativeLevel( g_wv.hWnd, DSSCL_PRIORITY ) )	{
		Com_Printf ("failed\n");
		SNDDMA_Shutdown ();
		return false;
	}
	Com_DPrintf("ok\n" );


	// create the secondary buffer we'll actually work with
	dma.channels = 2;
	dma.samplebits = 16;

//	if (s_khz->integer == 44)
//		dma.speed = 44100;
//	else if (s_khz->integer == 22)
//		dma.speed = 22050;
//	else
//		dma.speed = 11025;

	dma.speed = 22050;
	memset (&format, 0, sizeof(format));
	format.wFormatTag = WAVE_FORMAT_PCM;
    format.nChannels = dma.channels;
    format.wBitsPerSample = dma.samplebits;
    format.nSamplesPerSec = dma.speed;
    format.nBlockAlign = format.nChannels * format.wBitsPerSample / 8;
    format.cbSize = 0;
    format.nAvgBytesPerSec = format.nSamplesPerSec*format.nBlockAlign; 

	memset (&dsbuf, 0, sizeof(dsbuf));
	dsbuf.dwSize = sizeof(DSBUFFERDESC);

	// Micah: take advantage of 2D hardware.if available.
	dsbuf.dwFlags = DSBCAPS_LOCHARDWARE;
	dsbuf.dwFlags |= DSBCAPS_GETCURRENTPOSITION2;
	dsbuf.dwBufferBytes = SECONDARY_BUFFER_SIZE;
	dsbuf.lpwfxFormat = &format;
	
	memset(&dsbcaps, 0, sizeof(dsbcaps));
	dsbcaps.dwSize = sizeof(dsbcaps);
	
	Com_DPrintf( "...creating secondary buffer: " );
	if (DS_OK == pDS->CreateSoundBuffer(&dsbuf, &pDSBuf, NULL)) {
		Com_Printf( "locked hardware.  ok\n" );
	}
	else {
		// Couldn't get hardware, fallback to software.
		dsbuf.dwFlags = DSBCAPS_LOCSOFTWARE;
		dsbuf.dwFlags |= DSBCAPS_GETCURRENTPOSITION2;
		if (DS_OK != pDS->CreateSoundBuffer(&dsbuf, &pDSBuf, NULL)) {
			Com_Printf( "failed\n" );
			SNDDMA_Shutdown ();
			return false;
		}
		Com_DPrintf( "forced to software.  ok\n" );
	}
		
	// Make sure mixer is active
	if ( DS_OK != pDSBuf->Play(0, 0, DSBPLAY_LOOPING) ) {
		Com_Printf ("*** Looped sound play failed ***\n");
		SNDDMA_Shutdown ();
		return false;
	}

	// get the returned buffer size
	if ( DS_OK != pDSBuf->GetCaps (&dsbcaps) ) {
		Com_Printf ("*** GetCaps failed ***\n");
		SNDDMA_Shutdown ();
		return false;
	}
	
	gSndBufSize = dsbcaps.dwBufferBytes;

	dma.channels = format.nChannels;
	dma.samplebits = format.wBitsPerSample;
	dma.speed = format.nSamplesPerSec;
	dma.samples = gSndBufSize/(dma.samplebits/8);
	dma.submission_chunk = 1;
	dma.buffer = NULL;			// must be locked first

	sample16 = (dma.samplebits/8) - 1;

	SNDDMA_BeginPainting ();
	if (dma.buffer)
		memset(dma.buffer, 0, dma.samples * dma.samplebits/8);
	SNDDMA_Submit ();
	return 1;
}
コード例 #15
0
bool DirectSound::init(long sampleRate)
{
	HRESULT hr;
	DWORD freq;
	DSBUFFERDESC dsbdesc;
	int i;

	hr = CoCreateInstance( CLSID_DirectSound8, NULL, CLSCTX_INPROC_SERVER, IID_IDirectSound8, (LPVOID *)&pDirectSound );
	if( hr != S_OK ) {
		systemMessage( IDS_CANNOT_CREATE_DIRECTSOUND, NULL, hr );
		return false;
	}

	pDirectSound->Initialize( &DSDEVID_DefaultPlayback );
	if( hr != DS_OK ) {
		systemMessage( IDS_CANNOT_CREATE_DIRECTSOUND, NULL, hr );
		return false;
	}

	if( FAILED( hr = pDirectSound->SetCooperativeLevel( theApp.m_pMainWnd->GetSafeHwnd(), DSSCL_EXCLUSIVE ) ) ) {
		systemMessage( IDS_CANNOT_SETCOOPERATIVELEVEL, _T("Cannot SetCooperativeLevel %08x"), hr );
		return false;
	}


	// Create primary sound buffer
	ZeroMemory( &dsbdesc, sizeof(DSBUFFERDESC) );
	dsbdesc.dwSize = sizeof(DSBUFFERDESC);
	dsbdesc.dwFlags = DSBCAPS_PRIMARYBUFFER;
	if( dsoundDisableHardwareAcceleration ) {
		dsbdesc.dwFlags |= DSBCAPS_LOCSOFTWARE;
	}

	if( FAILED( hr = pDirectSound->CreateSoundBuffer( &dsbdesc, &dsbPrimary, NULL ) ) ) {
		systemMessage(IDS_CANNOT_CREATESOUNDBUFFER, _T("Cannot CreateSoundBuffer %08x"), hr);
		return false;
	}

	freq = sampleRate;
	// calculate the number of samples per frame first
	// then multiply it with the size of a sample frame (16 bit * stereo)
	soundBufferLen = ( freq / 60 ) * 4;
	soundBufferTotalLen = soundBufferLen * 10;
	soundNextPosition = 0;

	ZeroMemory( &wfx, sizeof(WAVEFORMATEX) );
	wfx.wFormatTag = WAVE_FORMAT_PCM;
	wfx.nChannels = 2;
	wfx.nSamplesPerSec = freq;
	wfx.wBitsPerSample = 16;
	wfx.nBlockAlign = wfx.nChannels * wfx.wBitsPerSample / 8;
	wfx.nAvgBytesPerSec = wfx.nSamplesPerSec * wfx.nBlockAlign;

	if( FAILED( hr = dsbPrimary->SetFormat( &wfx ) ) ) {
		systemMessage( IDS_CANNOT_SETFORMAT_PRIMARY, _T("CreateSoundBuffer(primary) failed %08x"), hr );
		return false;
	}


	// Create secondary sound buffer
	ZeroMemory( &dsbdesc, sizeof(DSBUFFERDESC) );
	dsbdesc.dwSize = sizeof(DSBUFFERDESC);
	dsbdesc.dwFlags = DSBCAPS_GETCURRENTPOSITION2 | DSBCAPS_CTRLPOSITIONNOTIFY | DSBCAPS_GLOBALFOCUS;
	if( dsoundDisableHardwareAcceleration ) {
		dsbdesc.dwFlags |= DSBCAPS_LOCSOFTWARE;
	}
	dsbdesc.dwBufferBytes = soundBufferTotalLen;
	dsbdesc.lpwfxFormat = &wfx;

	if( FAILED( hr = pDirectSound->CreateSoundBuffer( &dsbdesc, &dsbSecondary, NULL ) ) ) {
		systemMessage( IDS_CANNOT_CREATESOUNDBUFFER, _T("CreateSoundBuffer(secondary) failed %08x"), hr );
		return false;
	}

	if( FAILED( hr = dsbSecondary->SetCurrentPosition( 0 ) ) ) {
		systemMessage( 0, _T("dsbSecondary->SetCurrentPosition failed %08x"), hr );
		return false;
	}


	if( SUCCEEDED( hr = dsbSecondary->QueryInterface( IID_IDirectSoundNotify8, (LPVOID*)&dsbNotify ) ) ) {
		dsbEvent = CreateEvent( NULL, FALSE, FALSE, NULL );
		DSBPOSITIONNOTIFY notify[10];
		for( i = 0; i < 10; i++ ) {
			notify[i].dwOffset = i * soundBufferLen;
			notify[i].hEventNotify = dsbEvent;
		}

		if( FAILED( dsbNotify->SetNotificationPositions( 10, notify ) ) ) {
			dsbNotify->Release();
			dsbNotify = NULL;
			CloseHandle(dsbEvent);
			dsbEvent = NULL;
		}
	}


	// Play primary buffer
	if( FAILED( hr = dsbPrimary->Play( 0, 0, DSBPLAY_LOOPING ) ) ) {
		systemMessage( IDS_CANNOT_PLAY_PRIMARY, _T("Cannot Play primary %08x"), hr );
		return false;
	}

	return true;
}
コード例 #16
0
ファイル: DirectSound.cpp プロジェクト: FreshLeaf8865/mumble
void DXAudioOutput::run() {
	HRESULT hr;
	DSBUFFERDESC        dsbdesc;
	WAVEFORMATEXTENSIBLE wfx;
	WAVEFORMATEXTENSIBLE wfxSet;
	int ns = 0;
	unsigned int chanmasks[32];

	LPDIRECTSOUND8             pDS = NULL;
	LPDIRECTSOUNDBUFFER       pDSBPrimary = NULL;
	LPDIRECTSOUNDBUFFER       pDSBOutput = NULL;
	LPDIRECTSOUNDNOTIFY8       pDSNotify = NULL;

	DWORD	dwBufferSize;
	DWORD	dwLastWritePos;
	DWORD	dwLastPlayPos;
	DWORD	dwTotalPlayPos;
	int iLastwriteblock;
	LPVOID aptr1, aptr2;
	DWORD nbytes1, nbytes2;

	int playblock;
	int nowriteblock;
	DWORD dwPlayPosition, dwWritePosition;

	unsigned int iByteSize;

	bool bOk;
	DWORD dwSpeakerConfig;

	bool failed = false;

	bOk = false;
	DWORD dwMask = 0;
	bool bHead = false;

	ZeroMemory(&dsbdesc, sizeof(DSBUFFERDESC));
	dsbdesc.dwSize  = sizeof(DSBUFFERDESC);
	dsbdesc.dwFlags = DSBCAPS_PRIMARYBUFFER;

	if (! g.s.qbaDXOutput.isEmpty()) {
		LPGUID lpguid = reinterpret_cast<LPGUID>(g.s.qbaDXOutput.data());
		if (FAILED(hr = DirectSoundCreate8(lpguid, &pDS, NULL))) {
			failed = true;
		}
	}

	if (! pDS && FAILED(hr = DirectSoundCreate8(&DSDEVID_DefaultVoicePlayback, &pDS, NULL))) {
		qWarning("DXAudioOutput: DirectSoundCreate failed: hr=0x%08lx", hr);
		goto cleanup;
	} else if (FAILED(hr = pDS->SetCooperativeLevel(g.mw->winId(), DSSCL_PRIORITY))) {
		qWarning("DXAudioOutput: SetCooperativeLevel failed: hr=0x%08lx", hr);
		goto cleanup;
	} else if (FAILED(hr = pDS->CreateSoundBuffer(&dsbdesc, &pDSBPrimary, NULL))) {
		qWarning("DXAudioOutput: CreateSoundBuffer (Primary) failed: hr=0x%08lx", hr);
		goto cleanup;
	}

	pDS->GetSpeakerConfig(&dwSpeakerConfig);


	switch (DSSPEAKER_CONFIG(dwSpeakerConfig)) {
		case DSSPEAKER_HEADPHONE:
			dwMask = KSAUDIO_SPEAKER_STEREO;
			bHead = true;
			break;
		case DSSPEAKER_MONO:
			dwMask = KSAUDIO_SPEAKER_MONO;
			break;
		case DSSPEAKER_QUAD:
			dwMask = KSAUDIO_SPEAKER_QUAD;
			break;
		case DSSPEAKER_STEREO:
			dwMask = KSAUDIO_SPEAKER_STEREO;
			break;
		case DSSPEAKER_SURROUND:
			dwMask = KSAUDIO_SPEAKER_SURROUND;
			break;
		case DSSPEAKER_5POINT1:
			dwMask = KSAUDIO_SPEAKER_5POINT1;
			break;
		case DSSPEAKER_7POINT1:
			dwMask = KSAUDIO_SPEAKER_7POINT1;
			break;
		case DSSPEAKER_7POINT1_SURROUND:
			dwMask = KSAUDIO_SPEAKER_7POINT1_SURROUND;
			break;
		case DSSPEAKER_5POINT1_SURROUND:
			dwMask = KSAUDIO_SPEAKER_5POINT1_SURROUND;
			break;
		default:
			dwMask = 0;
			break;
	}

	if (! g.s.doPositionalAudio())
		dwMask = KSAUDIO_SPEAKER_MONO;

	for (int i=0;i<32;i++) {
		if (dwMask & (1 << i)) {
			chanmasks[ns++] = 1 << i;
		}
	}

	iMixerFreq = SAMPLE_RATE;
	iChannels = ns;
	eSampleFormat = SampleShort;

	iByteSize = iFrameSize * sizeof(short) * ns;

	ZeroMemory(&wfxSet, sizeof(wfxSet));
	wfxSet.Format.wFormatTag = WAVE_FORMAT_PCM;

	ZeroMemory(&wfx, sizeof(wfx));
	wfx.Format.wFormatTag = WAVE_FORMAT_PCM;
	wfx.Format.nChannels = qMax(ns, 1);
	wfx.Format.nSamplesPerSec = SAMPLE_RATE;
	wfx.Format.nBlockAlign = sizeof(short) * wfx.Format.nChannels;
	wfx.Format.nAvgBytesPerSec = wfx.Format.nSamplesPerSec * wfx.Format.nBlockAlign;
	wfx.Format.wBitsPerSample = 16;

	if (FAILED(hr = pDSBPrimary->SetFormat(reinterpret_cast<WAVEFORMATEX *>(&wfx)))) {
		qWarning("DXAudioOutput: SetFormat failed: hr=0x%08lx", hr);
		goto cleanup;
	}
	if (FAILED(hr = pDSBPrimary->GetFormat(reinterpret_cast<WAVEFORMATEX *>(&wfxSet), sizeof(wfxSet), NULL))) {
		qWarning("DXAudioOutput: GetFormat failed: hr=0x%08lx", hr);
		goto cleanup;
	}

	qWarning("DXAudioOutput: Primary buffer of %ld Hz, %d channels, %d bits",wfxSet.Format.nSamplesPerSec,wfxSet.Format.nChannels,wfxSet.Format.wBitsPerSample);

	ZeroMemory(&wfx, sizeof(wfx));
	wfx.Format.wFormatTag = WAVE_FORMAT_EXTENSIBLE;
	wfx.Format.nChannels = ns;
	wfx.Format.nSamplesPerSec = SAMPLE_RATE;
	wfx.Format.nBlockAlign = sizeof(short) * wfx.Format.nChannels;
	wfx.Format.nAvgBytesPerSec = wfx.Format.nSamplesPerSec * wfx.Format.nBlockAlign;
	wfx.Format.wBitsPerSample = 16;
	wfx.Format.cbSize = 32;
	wfx.Samples.wValidBitsPerSample = wfx.Format.wBitsPerSample;
	wfx.dwChannelMask = dwMask;
	wfx.SubFormat = KSDATAFORMAT_SUBTYPE_PCM;

	ZeroMemory(&dsbdesc, sizeof(DSBUFFERDESC));
	dsbdesc.dwSize          = sizeof(DSBUFFERDESC);
	dsbdesc.dwFlags         = DSBCAPS_GLOBALFOCUS|DSBCAPS_GETCURRENTPOSITION2;
	dsbdesc.dwFlags	 |= DSBCAPS_CTRLPOSITIONNOTIFY;
	dsbdesc.dwBufferBytes = wfx.Format.nChannels * iFrameSize * sizeof(short) * NBLOCKS;
	dsbdesc.lpwfxFormat     = reinterpret_cast<WAVEFORMATEX *>(&wfx);

	if (FAILED(hr = pDS->CreateSoundBuffer(&dsbdesc, &pDSBOutput, NULL))) {
		qWarning("DXAudioOutputUser: CreateSoundBuffer (Secondary) failed: hr=0x%08lx", hr);
		goto cleanup;
	}


	if (FAILED(hr = pDSBOutput->QueryInterface(IID_IDirectSoundNotify, reinterpret_cast<void **>(&pDSNotify)))) {
		qWarning("DXAudioOutputUser: QueryInterface (Notify) failed: hr=0x%08lx", hr);
		goto cleanup;
	}

	qWarning("DXAudioOutputUser: New %dHz output buffer of %ld bytes", SAMPLE_RATE, dsbdesc.dwBufferBytes);

	if (failed)
		g.mw->msgBox(tr("Opening chosen DirectSound Output failed. Default device will be used."));

	initializeMixer(chanmasks, bHead);

	if (FAILED(hr = pDSBOutput->Lock(0, 0, &aptr1, &nbytes1, &aptr2, &nbytes2, DSBLOCK_ENTIREBUFFER))) {
		qWarning("DXAudioOutputUser: Initial Lock failed: hr=0x%08lx", hr);
		goto cleanup;
	}

	dwBufferSize = nbytes1 + nbytes2;
	if (aptr1)
		ZeroMemory(aptr1, nbytes1);
	if (aptr2)
		ZeroMemory(aptr2, nbytes2);

	if (FAILED(hr = pDSBOutput->Unlock(aptr1, nbytes1, aptr2, nbytes2))) {
		qWarning("DXAudioOutputUser: Initial Unlock failed: hr=0x%08lx", hr);
		goto cleanup;
	}

	if (FAILED(hr = pDSBOutput->Play(0, 0, DSBPLAY_LOOPING))) {
		qWarning("DXAudioOutputUser: Play failed: hr=0x%08lx", hr);
		goto cleanup;
	}

	dwLastWritePos = 0;
	dwLastPlayPos = 0;
	dwTotalPlayPos = 0;

	iLastwriteblock = (NBLOCKS - 1 + g.s.iOutputDelay) % NBLOCKS;

	bOk = true;

	while (bRunning && ! FAILED(hr)) {
		if (FAILED(hr = pDSBOutput->GetCurrentPosition(&dwPlayPosition, &dwWritePosition))) {
			qWarning("DXAudioOutputUser: GetCurrentPosition failed: hr=0x%08lx", hr);
			break;
		}

		playblock = dwWritePosition / iByteSize;
		nowriteblock = (playblock + g.s.iOutputDelay + 1) % NBLOCKS;

		for (int block=(iLastwriteblock + 1) % NBLOCKS;(!FAILED(hr)) && (block!=nowriteblock);block=(block + 1) % NBLOCKS) {
			iLastwriteblock = block;

			if (FAILED(hr = pDSBOutput->Lock(block * iByteSize, iByteSize, &aptr1, &nbytes1, &aptr2, &nbytes2, 0))) {
				qWarning("DXAudioOutput: Lock block %u (%d bytes) failed: hr=0x%08lx",block, iByteSize, hr);
				break;
			}
			if (aptr2 || nbytes2) {
				qWarning("DXAudioOutput: Split buffer");
				break;
			}
			if (!aptr1 || ! nbytes1) {
				qWarning("DXAudioOutput: Zerolock");
				break;
			}
			if (! mix(reinterpret_cast<short *>(aptr1), iFrameSize))
				ZeroMemory(aptr1, iByteSize);

			if (FAILED(hr = pDSBOutput->Unlock(aptr1, nbytes1, aptr2, nbytes2))) {
				qWarning("DXAudioOutput: Unlock %p(%lu) %p(%lu) failed: hr=0x%08lx",aptr1,nbytes1,aptr2,nbytes2,hr);
				break;
			}

			if (FAILED(hr = pDSBOutput->GetCurrentPosition(&dwPlayPosition, &dwWritePosition))) {
				qWarning("DXAudioOutputUser: GetCurrentPosition failed: hr=0x%08lx", hr);
				break;
			}

			playblock = dwWritePosition / iByteSize;
			nowriteblock = (playblock + g.s.iOutputDelay + 1) % NBLOCKS;
		}
		if (! FAILED(hr))
			msleep(19);
	}

	if (FAILED(hr)) {
		g.mw->msgBox(tr("Lost DirectSound output device."));
	}
cleanup:
	if (! bOk) {
		g.mw->msgBox(tr("Opening chosen DirectSound Output failed. No audio will be heard."));
		return;
	}

	if (pDSNotify)
		pDSNotify->Release();
	if (pDSBOutput) {
		pDSBOutput->Stop();
		pDSBOutput->Release();
	}
	if (pDSBPrimary)
		pDSBPrimary->Release();
	if (pDS)
		pDS->Release();
}
コード例 #17
0
ファイル: test.cpp プロジェクト: BackupTheBerlios/flamenco
int main()
{
    using namespace flamenco;
    
    LPDIRECTSOUND8 directSound;
    
    // Создаем интерфейс DirectSound.
    check_directx(DirectSoundCreate8(&GUID_NULL, &directSound, NULL));
    check_directx(directSound->SetCooperativeLevel(GetForegroundWindow(), DSSCL_PRIORITY));
    
    // Получаем первичный буфер.
    LPDIRECTSOUNDBUFFER primaryBuffer = NULL;
    DSBUFFERDESC descr;
    ZeroMemory(&descr, sizeof(DSBUFFERDESC));
    descr.dwSize = sizeof(DSBUFFERDESC);
    descr.dwFlags = DSBCAPS_PRIMARYBUFFER;
    descr.lpwfxFormat = NULL;
    check_directx(directSound->CreateSoundBuffer(&descr, &primaryBuffer, NULL));
    
    // Изменяем формат первичного буфера.
    WAVEFORMATEX wfx;
    ZeroMemory(&wfx, sizeof(WAVEFORMATEX));
    wfx.cbSize          = sizeof(WAVEFORMATEX);
    wfx.wFormatTag      = WAVE_FORMAT_PCM;
    wfx.nChannels       = 2;
    wfx.nSamplesPerSec  = FREQUENCY;
    wfx.wBitsPerSample  = 16;
    wfx.nBlockAlign     = wfx.wBitsPerSample / 8 * wfx.nChannels;
    wfx.nAvgBytesPerSec = (u32)wfx.nSamplesPerSec * wfx.nBlockAlign;
    check_directx(primaryBuffer->SetFormat(&wfx));
    primaryBuffer->Release();
    
    
    // Формат буфера микшера.
    const u32 MIXER_BUFFER_SIZE_IN_BYTES = MIXER_BUFFER_SIZE_IN_SAMPLES * sizeof(s16);
    // Размер звукового буфера должен быть больше 100 ms, иначе GetCurrentPosition()
    // будет выдавать неправильные данные.
    const u32 SOUND_BUFFER_SIZE_IN_BYTES = 10 * MIXER_BUFFER_SIZE_IN_BYTES;
    DSBUFFERDESC desc;
    ZeroMemory(&desc, sizeof(DSBUFFERDESC));
    desc.dwSize          = sizeof(DSBUFFERDESC);
    desc.dwFlags         = DSBCAPS_LOCSOFTWARE | DSBCAPS_GETCURRENTPOSITION2 | DSBCAPS_GLOBALFOCUS;
    desc.dwBufferBytes   = SOUND_BUFFER_SIZE_IN_BYTES;
    desc.guid3DAlgorithm = DS3DALG_DEFAULT;
    desc.lpwfxFormat     = &wfx;
    
    // Создаем буфер.
    LPDIRECTSOUNDBUFFER soundBuffer = NULL;
    check_directx(directSound->CreateSoundBuffer(&desc, &soundBuffer, NULL));
    
    //reference<stream<ogg_decoder> > sound = stream<ogg_decoder>::create(std::auto_ptr<source>(new file_source("input.ogg")));
    
    // Инициализация flamenco.
    mixer & mixer = mixer::singleton();
    
    reference<sound_stream_base> sound = stream<wavpack_decoder>::create(std::auto_ptr<source>(new file_source("input.wv")));
    //assert(!src.get());
    mixer.attach(sound);
    /*
    
    reference<pin> sine = sine::create(400);
    reference<ogg> wave = ogg::create("input.ogg");
    reference<pin> noise = noise::create();
    
    reference<volume_pan> vp = volume_pan::create(sound, 1.0f, 0.0f);
    
    //mixer.attach(sine);
    mixer.attach(vp);
    //mixer.attach(noise);
    */
    
    // Заполнение звукового буфера.
    s16 * bufferPtr;
    u32 bufferSize;
    check_directx(soundBuffer->Lock(0, 0, reinterpret_cast<void **>(&bufferPtr), &bufferSize,
                                    NULL, NULL, DSBLOCK_ENTIREBUFFER));
    // Заполняем обе половинки буфера.
    mixer.mix(bufferPtr);
    mixer.mix(bufferPtr + MIXER_BUFFER_SIZE_IN_SAMPLES);
    check_directx(soundBuffer->Unlock(bufferPtr, bufferSize, NULL, 0));
    
    // Проигрываем звук и дописываем данные по ходу.
    soundBuffer->Play(0, 0, DSBPLAY_LOOPING);
    u32 writeOffset = MIXER_BUFFER_SIZE_IN_BYTES * 2;
    while (true)
    {
        u32 cursorPos;
        soundBuffer->GetCurrentPosition(&cursorPos, NULL);
        
        // Определяем, нужно ли дописать очередную порцию данных.
        u32 offset = (SOUND_BUFFER_SIZE_IN_BYTES + writeOffset - cursorPos) % SOUND_BUFFER_SIZE_IN_BYTES;
        if (offset > MIXER_BUFFER_SIZE_IN_BYTES)
        {
            check_directx(soundBuffer->Lock(writeOffset, MIXER_BUFFER_SIZE_IN_BYTES,
                              reinterpret_cast<void **>(&bufferPtr), &bufferSize,
                              NULL, NULL, 0));
            mixer.mix(bufferPtr);
            check_directx(soundBuffer->Unlock(bufferPtr, bufferSize, NULL, 0));
            writeOffset = (writeOffset + MIXER_BUFFER_SIZE_IN_BYTES) % SOUND_BUFFER_SIZE_IN_BYTES;
        }
        // Не нужно опрашивать GetCurrentPosition() слишком часто.
        Sleep(LATENCY_MSEC >> 1);
        
        if (_kbhit())
        {
            switch (_getch())
            {
            case '+':
                //vp->pan.set(vp->pan() + 0.1f);
                continue;
            
            case '-':
                //vp->pan.set(vp->pan() - 0.1f);
                continue;
            
            case 'l':
                sound->looping.set(!sound->looping());
                continue;
            }
            // Если нажата любая другая клавиша - выходим.
            break;
        }
    }
    
    // Освобождение ресурсов.
    soundBuffer->Release();
    directSound->Release();
}
コード例 #18
0
ファイル: Sound.cpp プロジェクト: torso/gamelad
BOOL NewSoundBuffer(SOUNDBUFFER *pSoundBuffer)
{
	DSBPOSITIONNOTIFY	dsbpn[3];
	DSBUFFERDESC		dsbd;
	WAVEFORMATEX		wfx;
	DWORD				dw;


	wfx.wFormatTag = WAVE_FORMAT_PCM;
	wfx.nChannels = 2;
	wfx.nSamplesPerSec = 22050;
	wfx.wBitsPerSample = 8;
	wfx.nBlockAlign = wfx.wBitsPerSample / 8 * wfx.nChannels;
	wfx.nAvgBytesPerSec = wfx.nSamplesPerSec * wfx.nBlockAlign;

	ZeroMemory(&dsbd, sizeof(dsbd));
	dsbd.dwSize = sizeof(dsbd);
	dsbd.dwFlags = DSBCAPS_GETCURRENTPOSITION2 | DSBCAPS_GLOBALFOCUS | DSBCAPS_CTRLPOSITIONNOTIFY;
	dsbd.lpwfxFormat = &wfx;
	dsbd.dwBufferBytes = BufferSize * 3;

	if (lpds->CreateSoundBuffer(&dsbd, &pSoundBuffer->lpdsb, NULL))
	{
		return true;
	}

	if (!(pSoundBuffer->hEvent[0] = CreateEvent(NULL, false, false, NULL)))
	{
		DestroySoundBuffer(pSoundBuffer);
		return true;
	}
	if (!(pSoundBuffer->hEvent[1] = CreateEvent(NULL, false, false, NULL)))
	{
		DestroySoundBuffer(pSoundBuffer);
		return true;
	}
	if (!(pSoundBuffer->hEvent[2] = CreateEvent(NULL, false, false, NULL)))
	{
		DestroySoundBuffer(pSoundBuffer);
		return true;
	}

	if (pSoundBuffer->lpdsb->QueryInterface(IID_IDirectSoundNotify, (void **)&pSoundBuffer->lpdsn))
	{
		DestroySoundBuffer(pSoundBuffer);
		return true;
	}

	dsbpn[0].hEventNotify = pSoundBuffer->hEvent[0];
	dsbpn[0].dwOffset = 0;
	dsbpn[1].hEventNotify = pSoundBuffer->hEvent[1];
	dsbpn[1].dwOffset = BufferSize;
	dsbpn[2].hEventNotify = pSoundBuffer->hEvent[2];
	dsbpn[2].dwOffset = BufferSize * 2;
	if (pSoundBuffer->lpdsn->SetNotificationPositions(3, dsbpn))
	{
		DestroySoundBuffer(pSoundBuffer);
		return true;
	}

	InitializeCriticalSection(&pSoundBuffer->csSound);

	if (!CreateThread(NULL, NULL, SoundThreadProc, pSoundBuffer, NULL, &dw))
	{
		DestroySoundBuffer(pSoundBuffer);
		return true;
	}

	return false;
}
コード例 #19
0
ファイル: AsukaLib.cpp プロジェクト: naka2/asukalib
/*** DLLメイン関数 ***/
BOOL APIENTRY DllMain( HANDLE hModule, DWORD  ul_reason_for_call, LPVOID lpReserved)
{
    CHAR path[512],file[128],ext[64];
    switch(ul_reason_for_call) {
    case DLL_PROCESS_DETACH:
        GetModuleFileName(NULL, path,MAX_PATH-1);
        DEBUG_OUT("AsukaLibは Module %s から切り離されました\n",path);
        DestroyMenu(MainPopup);
        if(D3D8inst) FreeLibrary(D3D8inst);
        if(DI8inst) FreeLibrary(DI8inst);
        if(DS8inst) FreeLibrary(DS8inst);
        if(MainDI8) MainDI8->Release();// DirectInputは明示的に生成したからRelease
        if(MainDS8) MainDS8->Release();//
        if(bIniLoaded) SaveIniData(&Ini);
        ReleaseSoundBufferChain();
        return TRUE;
    case DLL_PROCESS_ATTACH:
        bIniLoaded = FALSE;
        GetModuleFileName(NULL, path,MAX_PATH-1);
        DEBUG_OUT("AsukaLibは Module %s から呼び出されました\n",path);
        hDLL = hModule;
        break;
    default:
        return TRUE;
    }



    GetModuleFileName(NULL,path,MAX_PATH-1);
    _splitpath_s(path,NULL,0,NULL,0,file,ARRAYSIZE(file),ext,ARRAYSIZE(ext));
    strcat_s(file,ARRAYSIZE(file),ext);
    if(lstrcmpi(file,TARGET_EXE) != 0) {
        DEBUG_OUT("%sによるDLL呼び出しなのでフック中止(Target: %s)\n",file,TARGET_EXE);
        return TRUE;
    }

    LoadIniData(&Ini);
    bIniLoaded = TRUE;

    // ポップアップメニューのロード
    MainPopup = LoadMenu((HINSTANCE)hModule,MAKEINTRESOURCE(ID_POPUPMENU));
    SubPopup = GetSubMenu(MainPopup,0);

    // Iniからデフォルト状態の復帰
    CheckMenuItem(SubPopup,IDM_MUTE_BGM,Ini.BGMMute?MF_CHECKED:MF_UNCHECKED);
    CheckMenuItem(SubPopup,IDM_MUTE_SE,Ini.SEMute?MF_CHECKED:MF_UNCHECKED);
    CheckMenuItem(SubPopup,IDM_LOCK_CONFIG,Ini.LockConfig?MF_CHECKED:MF_UNCHECKED);
    CheckMenuItem(SubPopup,IDC_SAVEWINDOWSET,Ini.SaveWindowSettings?MF_CHECKED:MF_UNCHECKED);
    CheckMenuItem(SubPopup,IDM_RESIZABLE,Ini.WindowResizable?MF_CHECKED:MF_UNCHECKED);
    CheckMenuItem(SubPopup,IDM_HOLDASPECTRATIO,Ini.HoldAspectRatio?MF_CHECKED:MF_UNCHECKED);
    EnableMenuItem(SubPopup,IDM_HOLDASPECTRATIO,Ini.WindowResizable?MF_ENABLED:MF_GRAYED);
    EnableMenuItem(SubPopup,IDM_SIZE_640,Ini.WindowResizable?MF_ENABLED:MF_GRAYED);
    EnableMenuItem(SubPopup,IDM_SIZE_800,Ini.WindowResizable?MF_ENABLED:MF_GRAYED);
    EnableMenuItem(SubPopup,IDM_SIZE_960,Ini.WindowResizable?MF_ENABLED:MF_GRAYED);

    // Direct3Dをロード
    GetSystemDirectory(path,ARRAYSIZE(path));
    strcat_s(path,ARRAYSIZE(path),"\\d3d8.dll");
    D3D8inst = LoadLibrary(path);
    fpD3DCreate8 = (FuncPtrDirect3DCreate8)GetProcAddress(D3D8inst, "Direct3DCreate8");

    // DirectInput8をロード
    GetSystemDirectory(path,ARRAYSIZE(path));
    strcat_s(path,ARRAYSIZE(path),"\\dinput8.dll");
    DI8inst = LoadLibrary(path);
    fpDI8Create = (FuncPtrDirectInput8Create)GetProcAddress(DI8inst, "DirectInput8Create");

    // DirectSound8をロード
    GetSystemDirectory(path,ARRAYSIZE(path));
    strcat_s(path,ARRAYSIZE(path),"\\dsound.dll");
    DS8inst = LoadLibrary(path);
    fpDSCreate8 = (FuncPtrDirectSoundCreate8)GetProcAddress(DS8inst, "DirectSoundCreate8");

    return TRUE;
}