void S_SoundList_f( void ) { int i; sfx_t *sfx; int size, total; char type[4][16]; char mem[2][16]; #ifndef NO_DMAHD if ( dmaHD_Enabled() ) { dmaHD_SoundList(); return; } #endif strcpy(type[0], "16bit"); strcpy(type[1], "adpcm"); strcpy(type[2], "daub4"); strcpy(type[3], "mulaw"); strcpy(mem[0], "paged out"); strcpy(mem[1], "resident "); total = 0; for (sfx=s_knownSfx, i=0 ; i<s_numSfx ; i++, sfx++) { size = sfx->soundLength; total += size; Com_Printf("%6i[%s] : %s[%s]\n", size, type[sfx->soundCompressionMethod], sfx->soundName, mem[sfx->inMemory] ); } Com_Printf ("Total resident: %i\n", total); S_DisplayFreeMemory(); }
void S_SoundInfo_f(void) { Com_Printf("----- Sound Info -----\n" ); #ifndef NO_DMAHD if ( dmaHD_Enabled() ) { dmaHD_SoundInfo(); return; } #endif if (!s_soundStarted) { Com_Printf ("sound system not started\n"); } else { if ( s_soundMuted ) { Com_Printf ("sound system is muted\n"); } Com_Printf("%5d stereo\n", dma.channels - 1); Com_Printf("%5d samples\n", dma.samples); Com_Printf("%5d samplebits\n", dma.samplebits); Com_Printf("%5d submission_chunk\n", dma.submission_chunk); Com_Printf("%5d speed\n", dma.speed); Com_Printf("0x%x dma buffer\n", dma.buffer); if ( s_backgroundFile ) { Com_Printf("Background file: %s\n", s_backgroundLoop ); } else { Com_Printf("No background file.\n" ); } } Com_Printf("----------------------\n" ); }
void SND_setup(void) { sndBuffer *p, *q; cvar_t *cv; int scs; cv = Cvar_Get( "com_soundMegs", DEF_COMSOUNDMEGS, CVAR_LATCH | CVAR_ARCHIVE ); if (cv->integer < 16) Cvar_Set("com_soundMegs", "16"); //dmaHD optimization scs = (dmaHD_Enabled()) ? (2*1536) : (cv->integer*1536); // not needed by dmaHD buffer = malloc(scs*sizeof(sndBuffer) ); // allocate the stack based hunk allocator sfxScratchBuffer = malloc(SND_CHUNK_SIZE * sizeof(short) * 4); //Hunk_Alloc(SND_CHUNK_SIZE * sizeof(short) * 4); sfxScratchPointer = NULL; inUse = scs*sizeof(sndBuffer); p = buffer;; q = p + scs; while (--q > p) *(sndBuffer **)q = q-1; *(sndBuffer **)q = NULL; freelist = p + scs - 1; if (!com_quiet->integer) Com_Printf("Sound memory manager started\n"); }
void SND_setup(void) { sndBuffer *p, *q; cvar_t *cv; int scs; cv = Cvar_Get( "com_soundMegs", DEF_COMSOUNDMEGS, CVAR_LATCH | CVAR_ARCHIVE ); scs = ( #ifndef NO_DMAHD dmaHD_Enabled() ? (2*1536) : #endif (cv->integer*1536)); buffer = malloc(scs*sizeof(sndBuffer) ); // allocate the stack based hunk allocator sfxScratchBuffer = malloc(SND_CHUNK_SIZE * sizeof(short) * 4); //Hunk_Alloc(SND_CHUNK_SIZE * sizeof(short) * 4); sfxScratchPointer = NULL; inUse = scs*sizeof(sndBuffer); p = buffer;; q = p + scs; while (--q > p) *(sndBuffer **)q = q-1; *(sndBuffer **)q = NULL; freelist = p + scs - 1; Com_Printf("Sound memory manager started\n"); }
/* ================ S_Init ================ */ void S_Init( void ) { cvar_t *cv; qboolean r; Com_Printf("\n------- sound initialization -------\n"); s_volume = Cvar_Get ("s_volume", "0.8", CVAR_ARCHIVE); s_musicVolume = Cvar_Get ("s_musicvolume", "0.25", CVAR_ARCHIVE); s_separation = Cvar_Get ("s_separation", "0.5", CVAR_ARCHIVE); s_doppler = Cvar_Get ("s_doppler", "1", CVAR_ARCHIVE); s_khz = Cvar_Get ("s_khz", "22", CVAR_ARCHIVE); s_mixahead = Cvar_Get ("s_mixahead", "0.2", CVAR_ARCHIVE); s_mixPreStep = Cvar_Get ("s_mixPreStep", "0.05", CVAR_ARCHIVE); s_show = Cvar_Get ("s_show", "0", CVAR_CHEAT); s_testsound = Cvar_Get ("s_testsound", "0", CVAR_CHEAT); cv = Cvar_Get ("s_initsound", "1", 0); if ( !cv->integer ) { Com_Printf ("not initializing.\n"); Com_Printf("------------------------------------\n"); return; } Cmd_AddCommand("play", S_Play_f); Cmd_AddCommand("music", S_Music_f); Cmd_AddCommand("s_list", S_SoundList_f); Cmd_AddCommand("s_info", S_SoundInfo_f); Cmd_AddCommand("s_stop", S_StopAllSounds); r = SNDDMA_Init(); Com_Printf("------------------------------------\n"); #ifndef NO_DMAHD if (dmaHD_Enabled()) dmaHD_Init(); #endif if ( r ) { s_soundStarted = 1; s_soundMuted = 1; // s_numSfx = 0; Com_Memset(sfxHash, 0, sizeof(sfx_t *)*LOOP_HASH); s_soundtime = 0; s_paintedtime = 0; S_StopAllSounds (); S_SoundInfo_f(); } }
/* ============ S_Respatialize Change the volumes of all the playing sounds for changes in their positions ============ */ void S_Respatialize( int entityNum, const vec3_t head, vec3_t axis[3], int inwater ) { int i; channel_t *ch; vec3_t origin; #ifndef NO_DMAHD if ( dmaHD_Enabled() ) { dmaHD_Respatialize( entityNum, head, axis, inwater ); return; } #endif if ( !s_soundStarted || s_soundMuted ) { return; } listener_number = entityNum; VectorCopy(head, listener_origin); VectorCopy(axis[0], listener_axis[0]); VectorCopy(axis[1], listener_axis[1]); VectorCopy(axis[2], listener_axis[2]); // update spatialization for dynamic sounds ch = s_channels; for ( i = 0 ; i < MAX_CHANNELS ; i++, ch++ ) { if ( !ch->thesfx ) { continue; } // anything coming from the view entity will always be full volume if (ch->entnum == listener_number) { ch->leftvol = ch->master_vol; ch->rightvol = ch->master_vol; } else { if (ch->fixed_origin) { VectorCopy( ch->origin, origin ); } else { VectorCopy( loopSounds[ ch->entnum ].origin, origin ); } S_SpatializeOrigin (origin, ch->master_vol, &ch->leftvol, &ch->rightvol); } } // add loopsounds S_AddLoopSounds (); }
/* ============ S_Update Called once each time through the main loop ============ */ void S_Update( void ) { int i; int total; channel_t *ch; #ifndef NO_DMAHD if ( dmaHD_Enabled() ) { dmaHD_Update(); return; } #endif if ( !s_soundStarted || s_soundMuted ) { Com_DPrintf ("not started or muted\n"); return; } // // debugging output // if ( s_show->integer == 2 ) { total = 0; ch = s_channels; for (i=0 ; i<MAX_CHANNELS; i++, ch++) { if (ch->thesfx && (ch->leftvol || ch->rightvol) ) { Com_Printf ("%f %f %s\n", ch->leftvol, ch->rightvol, ch->thesfx->soundName); total++; } } Com_Printf ("----(%i)---- painted: %i\n", total, s_paintedtime); } // add raw data from streamed samples S_UpdateBackgroundTrack(); // mix some sound S_Update_(); }
/* ================ S_Init ================ */ qboolean S_Base_Init( soundInterface_t *si ) { qboolean r; if( !si ) { return qfalse; } #ifndef NO_DMAHD s_khz = Cvar_Get ("s_khz", "44", CVAR_ARCHIVE); #else s_khz = Cvar_Get ("s_khz", "22", CVAR_ARCHIVE); #endif s_mixahead = Cvar_Get ("s_mixahead", "0.2", CVAR_ARCHIVE); s_mixPreStep = Cvar_Get ("s_mixPreStep", "0.05", CVAR_ARCHIVE); s_show = Cvar_Get ("s_show", "0", CVAR_CHEAT); s_testsound = Cvar_Get ("s_testsound", "0", CVAR_CHEAT); s_dev = Cvar_Get ("s_dev", "", CVAR_ARCHIVE); Cmd_AddCommand( "s_devlist", S_dmaHD_devlist ); r = SNDDMA_Init(); if ( r ) { s_soundStarted = 1; s_soundMuted = 1; // s_numSfx = 0; Com_Memset(sfxHash, 0, sizeof(sfx_t *)*LOOP_HASH); s_soundtime = 0; s_paintedtime = 0; S_Base_StopAllSounds( ); } else { return qfalse; } si->Shutdown = S_Base_Shutdown; si->StartSound = S_Base_StartSound; si->StartLocalSound = S_Base_StartLocalSound; si->StartBackgroundTrack = S_Base_StartBackgroundTrack; si->StopBackgroundTrack = S_Base_StopBackgroundTrack; si->RawSamples = S_Base_RawSamples; si->StopAllSounds = S_Base_StopAllSounds; si->ClearLoopingSounds = S_Base_ClearLoopingSounds; si->AddLoopingSound = S_Base_AddLoopingSound; si->AddRealLoopingSound = S_Base_AddRealLoopingSound; si->StopLoopingSound = S_Base_StopLoopingSound; si->Respatialize = S_Base_Respatialize; si->UpdateEntityPosition = S_Base_UpdateEntityPosition; si->Update = S_Base_Update; si->DisableSounds = S_Base_DisableSounds; si->BeginRegistration = S_Base_BeginRegistration; si->RegisterSound = S_Base_RegisterSound; si->ClearSoundBuffer = S_Base_ClearSoundBuffer; si->SoundInfo = S_Base_SoundInfo; si->SoundList = S_Base_SoundList; #ifndef NO_DMAHD if (dmaHD_Enabled()) return dmaHD_Init(si); #endif return qtrue; }
/* ============== S_LoadSound The filename may be different than sfx->name in the case of a forced fallback of a player specific sound ============== */ qboolean S_LoadSound( sfx_t *sfx ) { byte *data; short *samples; snd_info_t info; // int size; #ifndef NO_DMAHD if(dmaHD_Enabled()) return dmaHD_LoadSound(sfx); #endif // player specific sounds are never directly loaded if ( sfx->soundName[0] == '*') { return qfalse; } // load it in data = S_CodecLoad(sfx->soundName, &info); if(!data) return qfalse; if ( info.width == 1 ) { Com_DPrintf(S_COLOR_YELLOW "WARNING: %s is a 8 bit audio file\n", sfx->soundName); } if ( info.rate != 22050 ) { Com_DPrintf(S_COLOR_YELLOW "WARNING: %s is not a 22kHz audio file\n", sfx->soundName); } samples = Hunk_AllocateTempMemory(info.samples * sizeof(short) * 2); sfx->lastTimeUsed = Com_Milliseconds()+1; // each of these compression schemes works just fine // but the 16bit quality is much nicer and with a local // install assured we can rely upon the sound memory // manager to do the right thing for us and page // sound in as needed if( sfx->soundCompressed == qtrue) { sfx->soundCompressionMethod = 1; sfx->soundData = NULL; sfx->soundLength = ResampleSfxRaw( samples, info.rate, info.width, info.samples, data + info.dataofs ); S_AdpcmEncodeSound(sfx, samples); #if 0 } else if (info.samples>(SND_CHUNK_SIZE*16) && info.width >1) { sfx->soundCompressionMethod = 3; sfx->soundData = NULL; sfx->soundLength = ResampleSfxRaw( samples, info.rate, info.width, info.samples, (data + info.dataofs) ); encodeMuLaw( sfx, samples); } else if (info.samples>(SND_CHUNK_SIZE*6400) && info.width >1) { sfx->soundCompressionMethod = 2; sfx->soundData = NULL; sfx->soundLength = ResampleSfxRaw( samples, info.rate, info.width, info.samples, (data + info.dataofs) ); encodeWavelet( sfx, samples); #endif } else { sfx->soundCompressionMethod = 0; sfx->soundLength = info.samples; sfx->soundData = NULL; ResampleSfx( sfx, info.rate, info.width, data + info.dataofs, qfalse ); } Hunk_FreeTempMemory(samples); Hunk_FreeTempMemory(data); return qtrue; }
int SNDDMA_InitDS () { HRESULT hresult; DSBUFFERDESC dsbuf; DSBCAPS dsbcaps; WAVEFORMATEX format; int use8; // Match/Choose output directsound device SNDDMAHD_DSEnumSoundDevices(qfalse); Com_Printf( "Initializing DirectSound\n"); use8 = 1; // Create IDirectSound using the primary sound device if( FAILED( hresult = CoCreateInstance(&CLSID_DirectSound8, NULL, CLSCTX_INPROC_SERVER, &IID_IDirectSound8, (void **)&pDS))) { use8 = 0; if( FAILED( hresult = CoCreateInstance(&CLSID_DirectSound, NULL, CLSCTX_INPROC_SERVER, &IID_IDirectSound, (void **)&pDS))) { Com_Printf ("failed\n"); SNDDMA_Shutdown (); return qfalse; } } hresult = pDS->lpVtbl->Initialize( pDS, g_dsguid); Com_DPrintf( "ok\n" ); Com_DPrintf("...setting DSSCL_PRIORITY coop level: " ); if ( DS_OK != pDS->lpVtbl->SetCooperativeLevel( pDS, g_wv.hWnd, DSSCL_PRIORITY ) ) { 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 >= 32) dma.speed = 32000; else if (s_khz->integer >= 24) dma.speed = 24000; else if (s_khz->integer >= 22) dma.speed = 22050; else dma.speed = 11025; #ifndef NO_DMAHD if (dmaHD_Enabled()) { // p5yc0runn3r - Fix dmaHD sound to 44KHz, Stereo and 16 bits per sample. dma.speed = 44100; dma.channels = 2; dma.samplebits = 16; } #endif 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; if (s_alttabmute->integer == 0) { // Keep playing when out of focus. dsbuf.dwFlags |= DSBCAPS_STICKYFOCUS; } if (use8) { 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->lpVtbl->CreateSoundBuffer(pDS, &dsbuf, &pDSBuf, NULL)) { Com_Printf( "locked hardware. ok\n" ); } else { // Couldn't get hardware, fallback to software. dsbuf.dwFlags = DSBCAPS_LOCSOFTWARE; if (use8) { dsbuf.dwFlags |= DSBCAPS_GETCURRENTPOSITION2; } 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; SNDDMA_BeginPainting (); if (dma.buffer) memset(dma.buffer, 0, dma.samples * dma.samplebits/8); SNDDMA_Submit (); return 1; }