예제 #1
0
static int Detect()
{
	DX_Context ds;
    g_lpDSDevice = NULL;
    sysMemZero(g_pDSHandles, DSOUNDMAXBUFFER * sizeof(DS_handle));
    ds.lpGUID = NULL;

    if (RLX.Audio.WaveDeviceId)
    {
       ds.index = 0;
       ds.mode = 1;
       DirectSoundEnumerate((LPDSENUMCALLBACKA)DSEnumCallback, &ds);
    }

    if (SYS_DXTRACE(DirectSoundCreate(ds.lpGUID, &g_lpDSDevice, NULL)))
    {
       if (ds.lpGUID)
       {
			ds.lpGUID = NULL;
			RLX.Audio.WaveDeviceId = 0;
       }
	   if (SYS_DXTRACE(DirectSoundCreate(ds.lpGUID, &g_lpDSDevice, NULL)))
		   return -1;
    }
    return 0;
}
static gboolean
gst_directsound_sink_open (GstAudioSink * asink)
{
  GstDirectSoundSink *dsoundsink;
  HRESULT hRes;

  dsoundsink = GST_DIRECTSOUND_SINK (asink);

  /* create and initialize a DirecSound object */
  if (FAILED (hRes = DirectSoundCreate (NULL, &dsoundsink->pDS, NULL))) {
    GST_ELEMENT_ERROR (dsoundsink, RESOURCE, OPEN_READ,
        ("gst_directsound_sink_open: DirectSoundCreate: %s",
            DXGetErrorString9 (hRes)), (NULL));
    return FALSE;
  }

  if (FAILED (hRes = IDirectSound_SetCooperativeLevel (dsoundsink->pDS,
              GetDesktopWindow (), DSSCL_PRIORITY))) {
    GST_ELEMENT_ERROR (dsoundsink, RESOURCE, OPEN_READ,
        ("gst_directsound_sink_open: IDirectSound_SetCooperativeLevel: %s",
            DXGetErrorString9 (hRes)), (NULL));
    return FALSE;
  }

  return TRUE;
}
예제 #3
0
CString DSound::Init()
{
	HRESULT hr;
	if( FAILED( hr = DirectSoundCreate(NULL, &m_pDS, NULL) ) )
		return hr_ssprintf( hr, "DirectSoundCreate" );

#ifndef _XBOX
	static bool bShownInfo = false;
	if( !bShownInfo )
	{
		bShownInfo = true;
		DirectSoundEnumerate( EnumCallback, 0 );

		DSCAPS Caps;
		Caps.dwSize = sizeof(Caps);
		HRESULT hr;
		if( FAILED(hr = m_pDS->GetCaps(&Caps)) )
		{
			LOG->Warn( hr_ssprintf(hr, "m_pDS->GetCaps failed") );
		}
		else
		{
			LOG->Info( "DirectSound sample rates: %i..%i %s", Caps.dwMinSecondarySampleRate, Caps.dwMaxSecondarySampleRate,
				(Caps.dwFlags & DSCAPS_CONTINUOUSRATE)?"(continuous)":"" );
		}
	}

	/* Try to set primary mixing privileges */
	hr = m_pDS->SetCooperativeLevel( GetDesktopWindow(), DSSCL_PRIORITY );
#endif

	SetPrimaryBufferMode();

	return "";
}
예제 #4
0
static BOOL DS_IsPresent(void)
{
	if(DirectSoundCreate(NULL,&pSoundCard,NULL)!=DS_OK)
		return 0;
	SAFE_RELEASE(pSoundCard);
	return 1;
}
예제 #5
0
파일: Sound.cpp 프로젝트: zouv/VGE_demo
bool CDxSound::Initialize(HWND hWnd)
{
	//初始化DirectSound设备
	if(DS_OK!=DirectSoundCreate(NULL,&m_dsound,NULL))
		return false;
	if(DS_OK!=m_dsound->SetCooperativeLevel(hWnd,DSSCL_PRIORITY))
		return false;

	//建立主缓冲区
	DSBUFFERDESC dsbDesc;
	ZeroMemory(&dsbDesc,sizeof(dsbDesc));
	dsbDesc.dwSize=sizeof(DSBUFFERDESC);
	dsbDesc.dwFlags=DSBCAPS_CTRLVOLUME|DSBCAPS_CTRLPAN|DSBCAPS_PRIMARYBUFFER;
	dsbDesc.dwBufferBytes=0;
	dsbDesc.lpwfxFormat=NULL;
	if(DS_OK!=m_dsound->CreateSoundBuffer(&dsbDesc,&m_primaryBuffer,NULL))
		return false;
	
	//设备播放格式
	WAVEFORMATEX waveFormatEx;
	ZeroMemory(&waveFormatEx,sizeof(WAVEFORMATEX));
	waveFormatEx.wFormatTag=WAVE_FORMAT_PCM;
	waveFormatEx.nChannels=2;
	waveFormatEx.nSamplesPerSec=22050;
	waveFormatEx.nBlockAlign=4;
	waveFormatEx.nAvgBytesPerSec=
		waveFormatEx.nSamplesPerSec*waveFormatEx.nBlockAlign;
	waveFormatEx.wBitsPerSample=16;
	if(DS_OK!=m_primaryBuffer->SetFormat(&waveFormatEx))
		return false;

	return true;
}
bool Platform_Win32_Sound_DSound::Setup()
	{
	dsoundDLL_=LoadLibrary("dsound.dll");

	if (dsoundDLL_)
		{
		typedef HRESULT (WINAPI *DirectSoundCreateDefinition)(LPCGUID pcGuidDevice, LPDIRECTSOUND *ppDS, LPUNKNOWN pUnkOuter);
		DirectSoundCreateDefinition DirectSoundCreate=(DirectSoundCreateDefinition)GetProcAddress((HMODULE)dsoundDLL_, "DirectSoundCreate");


		HRESULT hr;
		hr = DirectSoundCreate(NULL, &directSound_, NULL);
		if (!SUCCEEDED(hr))
			{
			Platform::GetPlatform_OS()->OutputDebugText("Couldn't create DirectSound object\n");
			return false;
			}

		hr = directSound_->SetCooperativeLevel(windowHandle_, /* DSSCL_EXCLUSIVE*/ DSSCL_NORMAL);
		if (!SUCCEEDED(hr))
			{
			Platform::GetPlatform_OS()->OutputDebugText("Couldn't set cooperative level for DirectSound object\n");
			return false;
			}

		return true;
		}

	Platform::GetPlatform_OS()->OutputDebugText("Couldn't load dsound.dll\n");
	return false;
	}
예제 #7
0
/*------------------------
	イニシャライズ
  -------------------------*/
STDMETHODIMP CFACE::Sound( LONG DSMODE ){ if ( DSMODE == dwSndMode ) return S_OK;
	// ログに記述
		LogBegin( "Sounds Initializer" );
		LogPut( CONTINUE , IDS_LOG_MODEOUT , DSMODE ); 

	// ハンドルチェック
		CHECK_HWND;
	// グラフィック定数範囲チェック
		CHECK_RANGE( DSMODE , 0 , 1 );

	// 使用しないモード
	if ( DSMODE == SOUNDDISABLE ) SoundRelease( ); 
	else{
		SoundRelease( );	// 全解放
		// DirectSound を作成する。
		if ( FAILED( DirectSoundCreate( NULL , &ObjDS , NULL ) ) )
			DSoundInitFailed;
		// 協調レベルを設定する
		if ( FAILED( ObjDS->SetCooperativeLevel( hWnd , DSSCL_NORMAL ) ) )
			DSoundInitFailed;
		// イベントの作成
		// at Half, at EndPos , FinallyHandler at Half
		for ( int i = 0 ; i < 3 ; i++ ) 
			hEvent[ i ] = CreateEvent( NULL , FALSE , FALSE , NULL );
	}
	dwSndMode = (BYTE)DSMODE;
	LogQuit( );
	return S_OK;
}
예제 #8
0
	DirectSound_AudioManager::DirectSound_AudioManager(void* backendId, bool threaded, float updateTime, chstr deviceName) :
		AudioManager(backendId, threaded, updateTime, deviceName)
	{
		this->name = XAL_AS_DIRECTSOUND;
		hlog::write(xal::logTag, "Initializing DirectSound.");
		HRESULT result = DirectSoundCreate(NULL, &this->dsDevice, NULL);
		if (FAILED(result))
		{
			this->dsDevice = NULL;
			hlog::error(xal::logTag, "Could not create device!");
			return;
		}
		result = this->dsDevice->SetCooperativeLevel((HWND)backendId, DSSCL_NORMAL);
		if (FAILED(result))
		{
			this->dsDevice->Release();
			this->dsDevice = NULL;
			hlog::error(xal::logTag, "Could not set cooperative level!");
			return;
		}
		this->dsCaps = new _DSCAPS();
		memset(this->dsCaps, 0, sizeof(_DSCAPS));
		this->dsCaps->dwSize = sizeof(_DSCAPS);
		result = this->dsDevice->GetCaps(this->dsCaps);
		if (result != DS_OK)
		{
			this->dsCaps->dwMaxSecondarySampleRate = 100000; // just in case. 100k is guaranteed to be always supported on all DS hardware
			hlog::error(xal::logTag, "Failed fetching DirectSound device caps");
		}
		else
		{
			hlog::writef(xal::logTag, "DirectSound device caps: { maxSampleRate = %u }", this->dsCaps->dwMaxSecondarySampleRate);
		}
		this->enabled = true;
	}
예제 #9
0
LPDIRECTSOUND CDXSound::Create( HWND hwnd, DWORD dwLevel )
{
	HRESULT hr;

	m_hWnd = hwnd;
	m_lpDS = NULL;
	
	hr = DirectSoundCreate( NULL, &m_lpDS, NULL );
	if( hr != DS_OK )
		return m_lpDS;

	hr = m_lpDS->SetCooperativeLevel( hwnd, dwLevel );//DSSCL_NORMAL );
	if ( hr != DS_OK ) 
	{
		m_lpDS->Release();
		m_lpDS = NULL;
	}
	else if ( !CreateBuffer() )
	{
		DestroyBuffer();
		m_lpDS->Release();
		m_lpDS = NULL;
	}
	return m_lpDS;
}
예제 #10
0
HRESULT DSW_InitOutputDevice( DSoundWrapper *dsw, LPGUID lpGUID )
{
// Create the DS object
	HRESULT hr = DirectSoundCreate( lpGUID, &dsw->dsw_pDirectSound, NULL );
	if( hr != DS_OK ) return hr;
	return hr;
}
예제 #11
0
Boolean DirectSoundInit( MADDriverRec* WinMADDriver)
{
	OnOff					= false;
	
	WIN95BUFFERSIZE = WinMADDriver->BufSize;
	WIN95BUFFERSIZE *= 2L;								// double buffer system
	
	currentBuf 		= calloc( WIN95BUFFERSIZE, 1);
	
	hwnd = GetForegroundWindow();	//GetForegroundWindow();
	if( !hwnd) return false;
	
	if(DS_OK == DirectSoundCreate(NULL, &WinMADDriver->lpDirectSound, NULL))
	{
		if( !AppCreateWritePrimaryBuffer( WinMADDriver->lpDirectSound, &WinMADDriver->lpDirectSoundBuffer, hwnd, WinMADDriver))
		{
			WinMADDriver->lpDirectSound = 0L;
			return false;
		}
		if( !WinMADDriver->lpDirectSoundBuffer) return false;
		
		// Creation succeeded.
		WinMADDriver->lpDirectSound->lpVtbl->SetCooperativeLevel(WinMADDriver->lpDirectSound, hwnd, DSSCL_NORMAL);
		
		WinMADDriver->lpSwSamp = 0L;
		if( !LoadSamp(WinMADDriver->lpDirectSound, &WinMADDriver->lpSwSamp, 0L, WIN95BUFFERSIZE, DSBCAPS_LOCSOFTWARE, WinMADDriver))
		{
			//DEBUG debugger( "Error 2\n");		//DSBCAPS_LOCSOFTWARE
			WinMADDriver->lpDirectSound = 0L;
			return false;
		}
		
		if( !WinMADDriver->lpSwSamp) return false;
		
		WinMADDriver->lpSwSamp->lpVtbl->Play(WinMADDriver->lpSwSamp, 0, 0, DSBPLAY_LOOPING);
		
		///////////
		
		timeBeginPeriod(20);      /* set the minimum resolution */
		
		/*  Set up the callback event.  The callback function
		 *  MUST be in a FIXED CODE DLL!!! -> not in Win95
		 */
		 
		// debugger( "timeSetEvent\n");
		 
		gwID = timeSetEvent(	  40,   												/* how often                 */
													  40,   							/* timer resolution          */
													  TimeProc,  						/* callback function         */
													  (unsigned long) WinMADDriver,		/* info to pass to callback  */
													  TIME_PERIODIC); 					/* oneshot or periodic?      */
		
		if( gwID == 0) return false;
		else return true;
	}
	
	WinMADDriver->lpDirectSound = 0L;
	
	return false;
}
예제 #12
0
static BOOL SB_Init(void)
{
    HRESULT result;

    if (!lpdsound) {
        result = DirectSoundCreate(NULL,&lpdsound,NULL);
        if (result != DS_OK) {
            ERR("Unable to initialize Sound Subsystem err = %x !\n",result);
            return FALSE;
        }

        /* FIXME: To uncomment when :
           - SetCooperative level is correctly implemented
           - an always valid and non changing handle to a windows  (vga_hwnd) is available
             (this surely needs some work in vga.c)
        result = IDirectSound_SetCooperativeLevel(lpdsound,vga_hwnd,DSSCL_EXCLUSIVE|DSSCL_PRIORITY);
        if (result != DS_OK) {
            ERR("Can't set cooperative level !\n");
            return FALSE;
        }
        */

        /* Default format */
        wav_fmt.wFormatTag = WAVE_FORMAT_PCM;
        wav_fmt.nChannels = 1;
        wav_fmt.nSamplesPerSec = 22050;
        wav_fmt.nAvgBytesPerSec = 22050;
        wav_fmt.nBlockAlign = 1;
        wav_fmt.wBitsPerSample = 8;
        wav_fmt.cbSize = 0;

        memset(&buf_desc,0,sizeof(DSBUFFERDESC));
        buf_desc.dwSize = sizeof(DSBUFFERDESC);
        buf_desc.dwBufferBytes = DSBUFLEN;
        buf_desc.lpwfxFormat = &wav_fmt;
        result = IDirectSound_CreateSoundBuffer(lpdsound,&buf_desc,&lpdsbuf,NULL);
        if (result != DS_OK) {
            ERR("Can't create sound buffer !\n");
            return FALSE;
        }

        result = IDirectSoundBuffer_Play(lpdsbuf,0, 0, DSBPLAY_LOOPING);
        if (result != DS_OK) {
            ERR("Can't start playing !\n");
            return FALSE;
        }

        buf_off = 0;
        end_sound_loop = 0;
        SB_Thread = CreateThread(NULL, 0, SB_Poll, NULL, 0, NULL);
        TRACE("thread\n");
        if (!SB_Thread) {
            ERR("Can't create thread !\n");
            return FALSE;
        }
    }
    return TRUE;
}
예제 #13
0
int audioStreamer_ds::Open(int iswrite, int srate, int nch, int bps, int sleep, int nbufs, int bufsize, GUID *device)
{
  // todo: use device
  m_sleep = sleep >= 0 ? sleep : 0;

  GUID zero={0,};
  if (!memcmp(device,&zero,sizeof(zero))) device=NULL;

  m_nch = nch;
  m_srate=srate;
  m_bps=bps;

  int fmt_align=(bps>>3)*nch;
  int fmt_mul=fmt_align*srate;
  WAVEFORMATEX wfx={
		WAVE_FORMAT_PCM,
		nch,
		srate,
		fmt_mul,
		fmt_align,
		bps,
		0
	};
  m_totalbufsize=nbufs*bufsize;

  if (iswrite)
  {
      DirectSoundCreate(device,&m_lpds,NULL);

      if (m_lpds)
      {
        HWND hWnd = GetForegroundWindow();
        if (hWnd == NULL) hWnd = GetDesktopWindow();
        m_lpds->SetCooperativeLevel(hWnd,DSSCL_PRIORITY);

        // create a secondary buffer for now
        DSBUFFERDESC ds={sizeof(ds),DSBCAPS_GETCURRENTPOSITION2|DSBCAPS_GLOBALFOCUS,m_totalbufsize,0,&wfx, };
        m_lpds->CreateSoundBuffer(&ds,&m_outbuf,NULL);
        
      }

  }
  else
  {
    DirectSoundCaptureCreate(device,&m_lpcap,NULL);
    if (m_lpcap)
    {
      DSCBUFFERDESC ds={sizeof(ds),0,m_totalbufsize,0,&wfx, };
      m_lpcap->CreateCaptureBuffer(&ds,&m_inbuf,NULL);
    }
  }

  m_bufsize=bufsize;


  return 0;
}
예제 #14
0
static BOOL DS_IsPresent(void)
{
	if(DirectSoundCreate(NULL,&pSoundCard,NULL)!=DS_OK)
		return 0;
	if (pSoundCard) {
		IDirectSound_Release(pSoundCard);
		pSoundCard = NULL;
	}
	return 1;
}
예제 #15
0
      static BOOL CALLBACK func(LPGUID lpGuid, LPCSTR lpcstrDescription, LPCSTR lpcstrModule, LPVOID lpContext) {
        enum_callback *context = (enum_callback *)lpContext;

        if (_stricmp(context->name, lpcstrDescription) == 0) {
          context->hr = DirectSoundCreate(lpGuid, &dsound, NULL);
          return false;
        }

        return true;
      }
예제 #16
0
파일: sound.cpp 프로젝트: Budskii/ulib-win
DirectSoundManager::DirectSoundManager() 
{  
    DirectSound = NULL;
    PrimaryBuffer = NULL;

       // If Direct sound fails, just return - no sound effects will be heard

    DirectSoundCreate(NULL,&DirectSound,NULL);
    
}
예제 #17
0
nuiAudioDevice_DirectSound::nuiAudioDevice_DirectSound(GUID IGuid, GUID OGuid, const nglString& rInName, const nglString& rOutName, const nglString& rInModule, const nglString& rOutModule)
: nuiAudioDevice()
{
  mInName = rInName;
  mOutName = rOutName;
  if (rOutName.IsEmpty())
    mName = rInName;
  else
    mName = rOutName;

  mManufacturer = rOutModule;
  mIsPresent = false;
  mHasInput = false;
  mHasOutput = false;

  mIDeviceID = IGuid;
  mODeviceID = OGuid;

  mpDirectSound = NULL;
  mpDirectSoundCapture = NULL;

  mAPIName = API_NAME;

  mpRingBuffer = NULL;
  mpInputBuffer = NULL;
  mpOutputBuffer = NULL;

  mpProcessingTh = NULL;
  mpOutputTh = NULL;

  mNotifInputEvent[0] = NULL;
  mNotifInputEvent[1] = NULL;
  mNotifOutputEvent[0] = NULL;
  mNotifOutputEvent[1] = NULL;

  HRESULT hr;
  // Get Input device caps:
  hr = DirectSoundCaptureCreate(&mIDeviceID, &mpDirectSoundCapture, NULL);
  if (hr != S_OK || !mpDirectSoundCapture)
  {
    NGL_LOG(_T("nuiAudioDevice_DirectSound"), NGL_LOG_INFO, _T("constructor ERROR : could not create DirectSoundCapture object!\n"));
  }

  // Get Output device caps:
  hr = DirectSoundCreate(&mODeviceID, &mpDirectSound, NULL);
  if (hr != S_OK || !mpDirectSound)
  {
    NGL_LOG(_T("nuiAudioDevice_DirectSound"), NGL_LOG_ERROR, _T("constructor ERROR : could not create DirectSound object!\n")); // if there is no output, consider the device as not valid
    return;
  }


  Init();
}
예제 #18
0
// initialize
bool sspDSDeviceGroup::initializeImpl(LPVOID hWnd)
{
	if (m_pDS.size() > 0) return TRUE;	// Already initialized

    if (hWnd == NULL)
    {
        // Error, invalid hwnd
        DOUT (_T("ERROR: Invalid parameters, unable to initialize services\n\r"));
        return FALSE;
    }
	m_hApp = (HWND) hWnd;
    setBufferFormat(2);
	m_pDS.reserve(m_nDevices.size());
	m_pDSBuf.reserve(m_nDevices.size());
	for (unsigned int i=0; i<m_nDevices.size(); i++) {
		// Create DirectSound object
		LPDIRECTSOUND ds;
		HRESULT nResult = DirectSoundCreate(m_dsInfo[m_nDevices[i]]->lpGuid, &ds, NULL);
		if (nResult == DS_OK) {
			nResult = ds->SetCooperativeLevel(m_hApp, DSSCL_PRIORITY);
			if (nResult == DS_OK) {
				LPDIRECTSOUNDBUFFER dsbuf;
				nResult = ds->CreateSoundBuffer(&m_dsBufDesc, &dsbuf, NULL);
				if (nResult == DS_OK) {
					nResult = dsbuf->SetFormat(&m_pcmWf);
					if (nResult == DS_OK) {
						DOUT (_T("SUCCESS: DirectSound created and formatted\n\r"));
					}
					else {
						DOUT(_T("ERROR: Unable to set DirectSound format\n\r"));
						return FALSE;
					}
				m_pDSBuf.push_back(dsbuf);
				}
				else {
					DOUT(_T("ERROR: Unable to create DirectSound buffer\n\r"));
					return FALSE;
				}
			}
			else {
				DOUT(_T("ERROR: Unable to set DirectSound cooperative level\n\r"));
				return FALSE;
			}
			m_pDS.push_back(ds);
		}
		else {
			// Error
			DOUT(_T("ERROR: Unable to create DirectSound object\n\r"));
			return FALSE;
		}
	}
    return TRUE;
}
int DSound_Init(void)
{
    // this function initializes the sound system
    static int first_time = 1; // used to track the first time the function
    // is entered

    // test for very first time
    if (first_time)
    {		
        // clear everything out
        memset(sound_fx,0,sizeof(pcm_sound)*MAX_SOUNDS);

        // reset first time
        first_time = 0;

        // create a directsound object
        if (FAILED(DirectSoundCreate(NULL, &lpds, NULL)))
            return(0);

        // set cooperation level
        if (FAILED(lpds->SetCooperativeLevel((HWND)main_window_handle,DSSCL_NORMAL)))
            return(0);

    } // end if

    // initialize the sound fx array
    for (int index=0; index<MAX_SOUNDS; index++)
    {
        // test if this sound has been loaded
        if (sound_fx[index].dsbuffer)
        {
            // stop the sound
            sound_fx[index].dsbuffer->Stop();

            // release the buffer
            sound_fx[index].dsbuffer->Release();

        } // end if

        // clear the record out
        memset(&sound_fx[index],0,sizeof(pcm_sound));

        // now set up the fields
        sound_fx[index].state = SOUND_NULL;
        sound_fx[index].id    = index;

    } // end for index

    // return sucess
    return(1);

} // end DSound_Init
예제 #20
0
파일: dsound.c 프로젝트: howard5888/wineT
static HRESULT test_block_align(LPGUID lpGuid)
{
    HRESULT rc;
    LPDIRECTSOUND dso=NULL;
    LPDIRECTSOUNDBUFFER secondary=NULL;
    DSBUFFERDESC bufdesc;
    DSBCAPS dsbcaps;
    WAVEFORMATEX wfx;
    int ref;

    /* Create the DirectSound object */
    rc=DirectSoundCreate(lpGuid,&dso,NULL);
    ok(rc==DS_OK||rc==DSERR_NODRIVER||rc==DSERR_ALLOCATED,
       "DirectSoundCreate() failed: %s\n",DXGetErrorString8(rc));
    if (rc!=DS_OK)
        return rc;

    init_format(&wfx,WAVE_FORMAT_PCM,11025,16,2);
    ZeroMemory(&bufdesc, sizeof(bufdesc));
    bufdesc.dwSize=sizeof(bufdesc);
    bufdesc.dwFlags=DSBCAPS_GETCURRENTPOSITION2;
    bufdesc.dwBufferBytes=wfx.nAvgBytesPerSec + 1;
    bufdesc.lpwfxFormat=&wfx;
    rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&secondary,NULL);
    ok(rc==DS_OK,"IDirectSound_CreateSoundBuffer() "
       "should have returned DS_OK, returned: %s\n",
       DXGetErrorString8(rc));

    if (rc==DS_OK && secondary!=NULL) {
        ZeroMemory(&dsbcaps, sizeof(dsbcaps));
        dsbcaps.dwSize = sizeof(dsbcaps);
        rc=IDirectSoundBuffer_GetCaps(secondary,&dsbcaps);
        ok(rc==DS_OK,"IDirectSoundBuffer_GetCaps() should have returned DS_OK, "
           "returned: %s\n", DXGetErrorString8(rc));
        if (rc==DS_OK)
            ok(dsbcaps.dwBufferBytes==(wfx.nAvgBytesPerSec + wfx.nBlockAlign),
               "Buffer size not a multiple of nBlockAlign: requested %ld, "
               "got %ld, should be %ld\n", bufdesc.dwBufferBytes,
               dsbcaps.dwBufferBytes, wfx.nAvgBytesPerSec + wfx.nBlockAlign);
        ref=IDirectSoundBuffer_Release(secondary);
        ok(ref==0,"IDirectSoundBuffer_Release() secondary has %d references, "
           "should have 0\n",ref);
    }

    ref=IDirectSound_Release(dso);
    ok(ref==0,"IDirectSound_Release() has %d references, should have 0\n",ref);
    if (ref!=0)
        return DSERR_GENERIC;

    return rc;
}
예제 #21
0
APU_DX::APU_DX(void)
{
	buffer = NULL;
	active = false;
	buf.sample_rate(48000);
	buf.clock_rate(BASERATE);

	apu.output(&buf);
	time = 0;

	if (DS_OK != DirectSoundCreate(NULL, &lpDS, NULL))
		MessageBox(NULL, "DirectSoundCreate failed", "", MB_OK);
//	if (DS_OK != IDirectSound_SetCooperativeLevel(lpDS, NULL /*hWnd*/, DSSCL_PRIORITY))
//		MessageBox(NULL, "IDirectSound_SetCooperativeLevel failed", "", MB_OK);


	ZeroMemory(&wf, sizeof(WAVEFORMATEX));
	wf.wFormatTag = WAVE_FORMAT_PCM;
	wf.nChannels = 1;
	wf.nSamplesPerSec = 48000;
	wf.wBitsPerSample = 16;
	wf.nBlockAlign = wf.wBitsPerSample / 8 * wf.nChannels;
	wf.nAvgBytesPerSec = wf.nSamplesPerSec * wf.nBlockAlign;



	bufferdesc.dwSize = sizeof(DSBUFFERDESC); 
	bufferdesc.dwFlags = DSBCAPS_GLOBALFOCUS | DSBCAPS_GETCURRENTPOSITION2 | DSBCAPS_CTRLVOLUME; 
	bufferdesc.dwBufferBytes = (wf.nAvgBytesPerSec * BUFFER_MSEC)/1000;

	bufferdesc.dwReserved = 0; 
	bufferdesc.lpwfxFormat = &wf; 

	if (DS_OK != lpDS->CreateSoundBuffer(&bufferdesc, &buffer, NULL))
	{
		//MessageBox(NULL, "CreateSoundBuffer failed", "", MB_OK);
		return;
	}
	active = true;

	loThreshold = (int)((wf.nAvgBytesPerSec / 60) * 1.5);
	hiThreshold = (int)(wf.nAvgBytesPerSec / 60);

	writeBufferSize = loThreshold;
	bufferOffset = bufferdesc.dwBufferBytes - writeBufferSize;
	samplesPerFrame = wf.nSamplesPerSec / 60.0;
	buffer->SetCurrentPosition(0);
	buffer->Play(0, 0, DSBPLAY_LOOPING);

	apu.dmc_reader( DMCRead, this );
}
예제 #22
0
파일: ds.c 프로젝트: btb/d2x
BOOL SSInit(HWND hWnd, int channels, unsigned flags)
{
	LPDIRECTSOUNDBUFFER lpPrimaryBuffer;
	LPDIRECTSOUND lpDS;
	DSBUFFERDESC dsbd;

	if (SSMixer.lpds) return TRUE;

//	Perform Direct Sound Initialization
	if (DirectSoundCreate(NULL, &lpDS, NULL) != DS_OK) 
		return FALSE;

	SSMixer.lpds = lpDS;

	if (IDirectSound_SetCooperativeLevel(lpDS, hWnd, DSSCL_NORMAL) != DS_OK) {
		SSDestroy();
		return FALSE;
	}

//	Start Mixer
	memset(&dsbd, 0, sizeof(DSBUFFERDESC));
	dsbd.dwSize = sizeof(DSBUFFERDESC);
	dsbd.dwFlags = DSBCAPS_PRIMARYBUFFER;
	if (IDirectSound_CreateSoundBuffer(SSMixer.lpds, &dsbd, &lpPrimaryBuffer, NULL) == DS_OK) {
		if (IDirectSoundBuffer_Play(lpPrimaryBuffer, 0, 0, DSBPLAY_LOOPING) != DS_OK) {
			IDirectSoundBuffer_Release(lpPrimaryBuffer);
			SSDestroy();
			return FALSE;
		}
		IDirectSoundBuffer_Release(lpPrimaryBuffer);
	}
	else {
		SSDestroy();
		return FALSE;
	}


//	Finish initializing SSMixer.
	SSMixer.ch_cur = 0;
	SSMixer.ch_list = (SSoundBuffer *)malloc(sizeof(SSoundBuffer)*channels);
	if (!SSMixer.ch_list) return FALSE;
	
	memset(SSMixer.ch_list, 0, sizeof(SSoundBuffer)*channels);
	
	SSMixer.ch_num = channels;

//	Determine Sound technology and volume caps
	waveOutGetVolume((HWAVEOUT)WAVE_MAPPER, (LPDWORD)&SSMixer.old_master_vol);
//	waveOutSetVolume((HWAVEOUT)WAVE_MAPPER, 0x40004000);
	return TRUE;
}
예제 #23
0
int Game_Init(void *parms)
{
// this function is where you do all the initialization 
// for your game

// create a directsound object
if (DirectSoundCreate(NULL, &lpds, NULL)!=DS_OK )
	return(0);

// set cooperation level
if (lpds->SetCooperativeLevel(main_window_handle,DSSCL_NORMAL)!=DS_OK)
	return(0);

// clear array out
memset(sound_fx,0,sizeof(pcm_sound)*MAX_SOUNDS);
	
// initialize the sound fx array
for (int index=0; index<MAX_SOUNDS; index++)
	{
	// test if this sound has been loaded
	if (sound_fx[index].dsbuffer)
		{
		// stop the sound
		sound_fx[index].dsbuffer->Stop();

		// release the buffer
		sound_fx[index].dsbuffer->Release();
	
		} // end if

	// clear the record out
	memset(&sound_fx[index],0,sizeof(pcm_sound));

	// now set up the fields
	sound_fx[index].state = SOUND_NULL;
	sound_fx[index].id    = index;

	} // end for index

// load a wav file in
if ((sound_id = DSound_Load_WAV("FLIGHT.WAV"))!=-1)
   {
   // start the voc playing in looping mode
   sound_fx[sound_id].dsbuffer->Play(0,0,DSBPLAY_LOOPING);
   } // end if

// return success
return(1);

} // end Game_Init
예제 #24
0
static int _qdgdfa_startup(void)
{
    int n;

    for (n = 0; n < MAX_SOUNDS; n++)
        _sounds[n] = NULL;
    for (n = 0; n < MAX_SPAWNED_SOUNDS; n++)
        _spawned_sounds[n] = NULL;

    if (DirectSoundCreate(NULL, &dsound, NULL) != DS_OK)
        return 0;

    return 1;
}
예제 #25
0
파일: dsnd.cpp 프로젝트: dreiss/M1-Android
INT16 m1sdr_IsThere(void)
{
    if(DS_OK == DirectSoundCreate(NULL, &lpDS, NULL)) 
    {
		IDirectSound_Release(lpDS);
		hw_present = 1;
		return(1);
    } 
    else
    {
		hw_present = 0;
    	return(0);
    }
}
예제 #26
0
//************************************************************************
BOOL CDirSnd::Init(HWND hWnd)
//************************************************************************
{
	// Already created
	if (m_pDirectSound)
		return(FALSE);

	if (DS_OK != DirectSoundCreate(NULL, &m_pDirectSound, NULL))
		return(FALSE);

	// Create succeeded
	m_pDirectSound->SetCooperativeLevel(hWnd, DSSCL_NORMAL);
	return(TRUE);
}
예제 #27
0
//-----------------------------------------------------------------------------
// Name: DSUtil_InitDirectSound()
// Desc: 
//-----------------------------------------------------------------------------
HRESULT DSUtil_InitDirectSound( HWND hWnd )
{
    if( FAILED( DirectSoundCreate( NULL, &g_pDS, NULL ) ) )
        return E_FAIL;

    if( FAILED( g_pDS->SetCooperativeLevel( hWnd, DSSCL_NORMAL ) ) )
    {
        g_pDS->Release();
        g_pDS = NULL;
        return E_FAIL;
    }

    return S_OK;
}
예제 #28
0
sU32 __stdcall dsInit(DSIOCALLBACK *callback, void *parm, void *hwnd)
{
  static const WAVEFORMATEX wfxprimary = { WAVE_FORMAT_PCM, 2, 44100, 44100*2*2, 2*2, 16, 0 };
  //static const WAVEFORMATEX wfxprimary = { WAVE_FORMAT_PCM, 2, 48000, 48000*2*2, 2*2, 16, 0 };
  static const DSBUFFERDESC primdesc = { sizeof(DSBUFFERDESC), DSBCAPS_PRIMARYBUFFER, 0, 0, 0 };
  static const DSBUFFERDESC streamdesc = { sizeof(DSBUFFERDESC), DSBCAPS_GETCURRENTPOSITION2 | DSBCAPS_GLOBALFOCUS, BUFFERLEN, 0, (WAVEFORMATEX*)&wfxprimary };

  ZeroMemory(&g_dsound, sizeof(g_dsound));
  g_dsound.callback = callback;
  g_dsound.cbparm = parm;

  void *buf1, *buf2;
  DWORD len1, len2;

  if (DirectSoundCreate(0, &g_dsound.dssd, 0) != S_OK || // create DSound instance
    g_dsound.dssd->SetCooperativeLevel((HWND)hwnd, DSSCL_PRIORITY) != S_OK || // cooperative level
    g_dsound.dssd->CreateSoundBuffer(&primdesc, &g_dsound.pbuf, 0) != S_OK || // primary buffer
    g_dsound.dssd->CreateSoundBuffer(&streamdesc, &g_dsound.sbuf, 0) != S_OK || // secondary buffer
    g_dsound.pbuf->SetFormat(&wfxprimary) != S_OK || // set primary buf format
    g_dsound.sbuf->Lock(0, 0, &buf1, &len1, &buf2, &len2, DSBLOCK_ENTIREBUFFER) != S_OK) // lock secondary buf
    goto bad;

  // clear secondary buffer
  memset(buf1, 0, len1);
  memset(buf2, 0, len2);
  if (g_dsound.sbuf->Unlock(buf1, len1, buf2, len2) != S_OK)
    goto bad;

  g_dsound.bufcnt = -BUFFERLEN;
  g_dsound.ltg = -BUFFERLEN;

  g_dsound.tickev = CreateEvent(0, FALSE, FALSE, 0);
  g_dsound.exitev = CreateEvent(0, FALSE, FALSE, 0);
  InitializeCriticalSection(&g_dsound.crsec);

  if (g_dsound.sbuf->Play(0, 0, DSBPLAY_LOOPING) != S_OK)
    goto bad;

  dsSetVolume(1.0f);

  // start sound thread
  g_dsound.thndl = CreateThread(0, 0, threadfunc, 0, 0, &len1);
  SetThreadPriority(g_dsound.thndl, THREAD_PRIORITY_ABOVE_NORMAL);

  return 0;

bad:
  dsClose();
  return ~0u;
}
예제 #29
0
LC3Sound::LC3Sound()
{
	memset(table, 0, sizeof(table));
	timeLeft = 0;
	tableIndex = 0;
	hwnd = GetForegroundWindow();
	DirectSoundCreate(NULL, &lpDirectSound, NULL);
	AppCreateWritePrimaryBuffer( lpDirectSound, &lpDirectSoundBuffer, hwnd);
	LoadSamp(lpDirectSound, &lpSwSamp, NULL, BUFSIZE, DSBCAPS_LOCSOFTWARE);
	lpDirectSound->SetCooperativeLevel(hwnd, DSSCL_NORMAL);
	//lpDirectSound->Initialize(&soundGUID);
	lpSwSamp->Play(0, 0, DSBPLAY_LOOPING);
	soundData = (char*)malloc(BUFSIZE);
	gwid = timeSetEvent( 40, 40, TimeProcC, (unsigned long) this, TIME_PERIODIC);
}
예제 #30
0
//-----------------------------------------------------------------------------
// Name: Initialize()
// Desc: Performs whatever initialization the sample needs
//-----------------------------------------------------------------------------
HRESULT CXBoxSample::Initialize()
{


	main_back=this->m_pBackBuffer;
	main_depth=this->m_pDepthBuffer;

	for(int i=0;i<128;i++)
	{
		angles[i]=10+i*.1;
	}

	//return E_FAIL;

	// Create a font
	if( FAILED( m_Font.Create( "Font.xpr" ) ) )
		return XBAPPERR_MEDIANOTFOUND;
	// Create the DirectSound object
	if( FAILED( DirectSoundCreate( NULL, &m_pDSound, NULL ) ) )
		return E_FAIL;
	m_bDrawHelp = FALSE;
	m_bPaused = FALSE;

	m_dwPercentCompleted = 0;

	demo_init();

	g_pd3dDevice->Clear( 0L, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER|D3DCLEAR_STENCIL, 0xff000000, 1.0f, 0L );
	m_pd3dDevice->Present( NULL, NULL, NULL, NULL );
	g_pd3dDevice->Clear( 0L, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER|D3DCLEAR_STENCIL, 0xff000000, 1.0f, 0L );

	WRAP(CreateSecondaryRenderTarget());

	SetSecondaryRenderTarget();
	g_pd3dDevice->Clear( 0L, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER|D3DCLEAR_STENCIL, 0xff000000, 1.0f, 0L );
	m_pd3dDevice->Present( NULL, NULL, NULL, NULL );
	g_pd3dDevice->Clear( 0L, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER|D3DCLEAR_STENCIL, 0xff000000, 1.0f, 0L );
	RenderSecondary(main_back, main_depth);


	MEMORYSTATUS stat;
    // Get the memory status.
    GlobalMemoryStatus( &stat );

//	m_Stream.Seek(startTime, (LPDWORD)&startTime);

	return S_OK;
}