qboolean SNDDMA_Init (void) { sndinitstat stat; if (COM_CheckParm ("-wavonly")) wavonly = true; dsound_init = wav_init = 0; stat = SIS_FAILURE; // assume DirectSound won't // initialize /* Init DirectSound */ if (!wavonly) { if (snd_firsttime || snd_isdirect) { stat = SNDDMA_InitDirect ();; if (stat == SIS_SUCCESS) { snd_isdirect = true; if (snd_firsttime) Con_Printf ("DirectSound initialized\n"); } else { snd_isdirect = false; Con_Printf ("DirectSound failed to init\n"); } } } // if DirectSound didn't succeed in initializing, try to initialize // waveOut sound, unless DirectSound failed because the hardware is // already allocated (in which case the user has already chosen not // to have sound) if (!dsound_init && (stat != SIS_NOTAVAIL)) { if (snd_firsttime || snd_iswave) { snd_iswave = SNDDMA_InitWav (); if (snd_iswave) { if (snd_firsttime) Con_Printf ("Wave sound initialized\n"); } else { Con_Printf ("Wave sound failed to init\n"); } } } snd_firsttime = false; if (!dsound_init && !wav_init) { if (snd_firsttime) Con_Printf ("No sound device initialized\n"); return 0; } return 1; }
//Try to find a sound device to mix for. //Returns false if nothing is found. qbool SNDDMA_Init(void) { sndinitstat stat; Cvar_SetCurrentGroup(CVAR_GROUP_SOUND); Cvar_Register (&sys_inactivesound); Cvar_ResetCurrentGroup (); if (COM_CheckParm ("-wavonly")) wavonly = true; dsound_init = wav_init = 0; stat = SIS_FAILURE; // assume DirectSound won't initialize /* Init DirectSound */ if (!wavonly) { if (snd_firsttime || snd_isdirect) { stat = SNDDMA_InitDirect (); if (stat == SIS_SUCCESS) { snd_isdirect = true; if (snd_firsttime) Com_Printf_State (PRINT_OK, "DirectSound initialized\n"); } else { snd_isdirect = false; Com_Printf_State (PRINT_FAIL, "DirectSound failed to init\n"); } } } // if DirectSound didn't succeed in initializing, try to initialize waveOut sound if (!dsound_init) { if (snd_firsttime || snd_iswave) { snd_iswave = SNDDMA_InitWav (); if (snd_iswave) { if (snd_firsttime) Com_Printf_State (PRINT_OK, "Wave sound initialized\n"); } else { Com_Printf_State (PRINT_FAIL, "Wave sound failed to init\n"); } } } snd_firsttime = false; if (!dsound_init && !wav_init) { if (snd_firsttime) Com_Printf_State (PRINT_INFO, "No sound device initialized\n"); return false; } return true; }
/* ================== SNDDMA_Init Try to find a sound device to mix for. Returns 0 if nothing is found. ================== */ int SNDDMA_Init(void) { sndinitstat stat; memset ((void *)&dma, 0, sizeof (dma)); s_soundsystem = Cvar_Get ("s_soundsystem", "1", CVAR_ARCHIVE ); s_soundquality = Cvar_Get ("s_soundquality", "2", CVAR_ARCHIVE ); s_buffersize = Cvar_Get ("s_buffersize", "1", CVAR_ARCHIVE); dsound_init = wav_init = 0; stat = SIS_FAILURE; // assume DirectSound won't initialize switch ((long int)s_khz->value) { case 96: dma.speed = 96000; break; case 48: dma.speed = 48000; break; case 44: dma.speed = 44100; break; case 22: dma.speed = 22050; break; case 11: dma.speed = 11025; break; case 8: dma.speed = 8000; break; default: dma.speed = 22050; // Default to ok quality break; } /* Init DirectSound */ if (s_soundsystem->value == 2) { //if (snd_firsttime || snd_isdirect) //{ stat = SNDDMA_InitDirect (); if (stat == SIS_SUCCESS) { snd_isdirect = 1; //if (snd_firsttime) Com_Printf ("DirectSound 8 initialization succeeded\n" ); } else { snd_isdirect = 0; Com_Printf ("*** DirectSound 8 initialization failed ***\n"); } //} } /* Init WaveOut */ else if (s_soundsystem->value == 1) { //if (snd_firsttime || snd_iswave) //{ snd_iswave = SNDDMA_InitWav (); if (snd_iswave) { if (snd_firsttime) Com_Printf ("Wave sound init succeeded\n"); } else { Com_Printf ("Wave sound init failed\n"); } //} } /* No Audio */ else if (s_soundsystem->value == 0) S_Shutdown(); snd_firsttime = 0; snd_buffer_count = 1; if (!dsound_init && !wav_init) { Com_Printf ("*** No sound device initialized ***\n"); } // NeVo - initialize Winamp Integration S_WinAmp_Init(); if (s_soundsystem->value == 0) return 0; return 1; }
/* ================== SNDDMA_Init Try to find a sound device to mix for. Returns false if nothing is found. ================== */ int SNDDMA_Init(void) { sndinitstat stat; memset ((void *)&dma, 0, sizeof (dma)); s_wavonly = Cvar_Get ("s_wavonly", "0", 0); dsound_init = wav_init = 0; stat = SIS_FAILURE; // assume DirectSound won't initialize /* Init DirectSound */ if (!s_wavonly->value) { if (snd_firsttime || snd_isdirect) { stat = SNDDMA_InitDirect (); if (stat == SIS_SUCCESS) { snd_isdirect = true; if (snd_firsttime) Com_Printf ("dsound init succeeded\n" ); } else { snd_isdirect = false; Com_Printf ("*** dsound init failed ***\n"); } } } // if DirectSound didn't succeed in initializing, try to initialize // waveOut sound, unless DirectSound failed because the hardware is // already allocated (in which case the user has already chosen not // to have sound) if (!dsound_init && (stat != SIS_NOTAVAIL)) { if (snd_firsttime || snd_iswave) { snd_iswave = SNDDMA_InitWav (); if (snd_iswave) { if (snd_firsttime) Com_Printf ("Wave sound init succeeded\n"); } else { Com_Printf ("Wave sound init failed\n"); } } } snd_firsttime = false; snd_buffer_count = 1; if (!dsound_init && !wav_init) { if (snd_firsttime) Com_Printf ("*** No sound device initialized ***\n"); return 0; } return 1; }
int SNDDMA_InitDS() { HRESULT hresult; qboolean pauseTried; DSBUFFERDESC dsbuf; DSBCAPS dsbcaps; WAVEFORMATEX format; if ( s_wavonly->integer ) { snd_iswave = SNDDMA_InitWav(); if ( snd_iswave ) { Com_Printf( "Wave sound init succeeded\n" ); } return 1; } Com_Printf( "Initializing DirectSound\n" ); if ( !hInstDS ) { Com_DPrintf( "...loading dsound.dll: " ); hInstDS = LoadLibrary( "dsound.dll" ); if ( hInstDS == NULL ) { Com_Printf( "failed\n" ); return 0; } Com_DPrintf( "ok\n" ); pDirectSoundCreate = ( long ( __stdcall * )( struct _GUID *,struct IDirectSound **,struct IUnknown * ) ) GetProcAddress( hInstDS,"DirectSoundCreate" ); if ( !pDirectSoundCreate ) { Com_Printf( "*** couldn't get DS proc addr ***\n" ); return 0; } } Com_DPrintf( "...creating DS object: " ); pauseTried = qfalse; while ( ( hresult = iDirectSoundCreate( NULL, &pDS, NULL ) ) != DS_OK ) { if ( hresult != DSERR_ALLOCATED ) { Com_Printf( "failed\n" ); return 0; } if ( pauseTried ) { Com_Printf( "failed, hardware already in use\n" ); return 0; } // first try just waiting five seconds and trying again // this will handle the case of a sysyem beep playing when the // game starts Com_DPrintf( "retrying...\n" ); Sleep( 3000 ); pauseTried = qtrue; } Com_DPrintf( "ok\n" ); Com_DPrintf( "...setting DSSCL_NORMAL coop level: " ); if ( DS_OK != pDS->lpVtbl->SetCooperativeLevel( pDS, g_wv.hWnd, DSSCL_NORMAL ) ) { Com_Printf( "failed\n" ); SNDDMA_Shutdown(); return qfalse; } 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; } 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. #define idDSBCAPS_GETCURRENTPOSITION2 0x00010000 dsbuf.dwFlags = DSBCAPS_LOCHARDWARE ; //DSBCAPS_CTRLFREQUENCY | DSBCAPS_LOCHARDWARE; 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->lpVtbl->CreateSoundBuffer( pDS, &dsbuf, &pDSBuf, NULL ) ) { Com_Printf( "locked hardware. ok\n" ); } else { // Couldn't get hardware, fallback to software. dsbuf.dwFlags = DSBCAPS_LOCSOFTWARE; //DSBCAPS_CTRLFREQUENCY | DSBCAPS_LOCSOFTWARE; if ( DS_OK != pDS->lpVtbl->CreateSoundBuffer( pDS, &dsbuf, &pDSBuf, NULL ) ) { Com_Printf( "failed\n" ); SNDDMA_Shutdown(); return qfalse; } Com_DPrintf( "forced to software. ok\n" ); } // Make sure mixer is active if ( DS_OK != pDSBuf->lpVtbl->Play( pDSBuf, 0, 0, DSBPLAY_LOOPING ) ) { Com_Printf( "*** Looped sound play failed ***\n" ); SNDDMA_Shutdown(); return qfalse; } // get the returned buffer size if ( DS_OK != pDSBuf->lpVtbl->GetCaps( pDSBuf, &dsbcaps ) ) { Com_Printf( "*** GetCaps failed ***\n" ); SNDDMA_Shutdown(); return qfalse; } 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; return 1; }
/* * SNDDMA_Init * * Try to find a sound device to mix for. * Returns false if nothing is found. */ bool SNDDMA_Init( void *hwnd, bool verbose ) { sndinitstat stat; cl_hwnd = ( HWND )hwnd; memset( (void *)&dma, 0, sizeof( dma ) ); s_wavonly = trap_Cvar_Get( "s_wavonly", "0", CVAR_LATCH_SOUND|CVAR_ARCHIVE ); s_globalfocus->modified = false; dsound_init = wav_init = false; stat = SIS_FAILURE; // assume DirectSound won't initialize /* Init DirectSound */ if( !s_wavonly->integer ) { if( /*snd_isdirect*/1 ) { stat = SNDDMA_InitDirect( verbose ); if( stat == SIS_SUCCESS ) { snd_isdirect = true; if( verbose ) Com_Printf( "dsound init succeeded\n" ); } else { snd_isdirect = false; Com_Printf( "*** dsound init failed ***\n" ); } } } // if DirectSound didn't succeed in initializing, try to initialize // waveOut sound, unless DirectSound failed because the hardware is // already allocated (in which case the user has already chosen not // to have sound) if( !dsound_init && ( stat != SIS_NOTAVAIL ) ) { if( /*snd_iswave*/1 ) { snd_iswave = SNDDMA_InitWav( verbose ); if( snd_iswave ) { if( verbose ) Com_Printf( "Wave sound init succeeded\n" ); } else { Com_Printf( "Wave sound init failed\n" ); } } } if( !dsound_init && !wav_init ) { Com_Printf( "*** No sound device initialized ***\n" ); return false; } return true; }
qbool SNDDMA_Init(void) { sndinitstat stat; if (COM_CheckParm ("-wavonly")) wavonly = true; dsound_init = wav_init = 0; stat = SIS_FAILURE; // assume DirectSound won't initialize /* Init DirectSound */ if (!wavonly) { if (snd_firsttime || snd_isdirect) { stat = SNDDMA_InitDirect ();; if (stat == SIS_SUCCESS) { snd_isdirect = true; // if (snd_firsttime) Com_Printf ("DirectSound initialized\n"); } else { snd_isdirect = false; Com_Printf ("DirectSound failed to init\n"); } } } // if DirectSound didn't succeed in initializing, try to initialize // waveOut sound if (!dsound_init) { if (snd_firsttime || snd_iswave) { snd_iswave = SNDDMA_InitWav (); if (snd_iswave) { if (snd_firsttime) Com_Printf ("Wave sound initialized\n"); } else { Com_Printf ("Wave sound failed to init\n"); } } } snd_firsttime = false; if (!dsound_init && !wav_init) { if (snd_firsttime) Com_Printf ("No sound device initialized\n"); return false; } return true; }