]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - snd_main.c
eliminated qbyte type, now uses unsigned char throughout the engine for this purpose
[xonotic/darkplaces.git] / snd_main.c
index fe590b1234d7e63ea81a5ef93f25854b653efc21..778e68d73285a5e2625cddc1754debc5aba52743 100644 (file)
@@ -124,7 +124,7 @@ void S_Startup(void)
                shm->format.channels = 2;
                shm->samples = 32768;
                shm->samplepos = 0;
-               shm->buffer = Mem_Alloc(snd_mempool, shm->format.channels * shm->samples * shm->format.width);
+               shm->buffer = (unsigned char *)Mem_Alloc(snd_mempool, shm->format.channels * shm->samples * shm->format.width);
        }
        else
        {
@@ -140,7 +140,8 @@ void S_Startup(void)
 
        sound_started = true;
 
-       Con_DPrintf("Sound sampling rate: %i\n", shm->format.speed);
+       Con_Printf("Sound format: %dHz, %d bit, %d channels\n", shm->format.speed,
+                          shm->format.width * 8, shm->format.channels);
 }
 
 void S_Shutdown(void)
@@ -268,9 +269,10 @@ sfx_t *S_FindName (const char *name)
                        return sfx;
 
        // Add a sfx_t struct for this sound
-       sfx = Mem_Alloc (snd_mempool, sizeof (*sfx));
+       sfx = (sfx_t *)Mem_Alloc (snd_mempool, sizeof (*sfx));
        memset (sfx, 0, sizeof(*sfx));
        strlcpy (sfx->name, name, sizeof (sfx->name));
+       sfx->memsize = sizeof(*sfx);
        sfx->next = known_sfx;
        known_sfx = sfx;
 
@@ -286,6 +288,8 @@ S_FreeSfx
 */
 void S_FreeSfx (sfx_t *sfx, qboolean force)
 {
+       unsigned int i;
+
        // Never free a locked sfx unless forced
        if (!force && (sfx->locks > 0 || (sfx->flags & SFXFLAG_PERMANENTLOCK)))
                return;
@@ -312,8 +316,14 @@ void S_FreeSfx (sfx_t *sfx, qboolean force)
                }
        }
 
+       // Stop all channels using this sfx
+       for (i = 0; i < total_channels; i++)
+               if (channels[i].sfx == sfx)
+                       S_StopChannel (i);
+
        // Free it
-       Mem_FreePool (&sfx->mempool);
+       if (sfx->fetcher != NULL && sfx->fetcher->free != NULL)
+               sfx->fetcher->free (sfx);
        Mem_Free (sfx);
 }
 
@@ -630,9 +640,9 @@ void S_StopChannel (unsigned int channel_ind)
 
                if (sfx->fetcher != NULL)
                {
-                       snd_fetcher_end_t fetcher_end = sfx->fetcher->end;
-                       if (fetcher_end != NULL)
-                               fetcher_end (ch);
+                       snd_fetcher_endsb_t fetcher_endsb = sfx->fetcher->endsb;
+                       if (fetcher_endsb != NULL)
+                               fetcher_endsb (ch);
                }
 
                // Remove the lock it holds
@@ -689,7 +699,7 @@ void S_StopAllSounds (void)
        memset(channels, 0, MAX_CHANNELS * sizeof(channel_t));
 
        // Clear sound buffer
-       pbuf = S_LockBuffer();
+       pbuf = (unsigned char *)S_LockBuffer();
        if (pbuf != NULL)
        {
                int setsize = shm->samples * shm->format.width;
@@ -770,7 +780,7 @@ void S_UpdateAmbientSounds (void)
        float           vol;
        int                     ambient_channel;
        channel_t       *chan;
-       qbyte           ambientlevels[NUM_AMBIENTS];
+       unsigned char           ambientlevels[NUM_AMBIENTS];
 
        if (ambient_level.value <= 0 || !cl.worldmodel || !cl.worldmodel->brush.AmbientSoundLevelsForPoint)
                return;
@@ -1023,7 +1033,7 @@ void S_SoundList(void)
        {
                if (sfx->fetcher != NULL)
                {
-                       size = (int)sfx->mempool->totalsize;
+                       size = (int)sfx->memsize;
                        total += size;
                        Con_Printf ("%c%c%c%c(%2db, %6s) %8i : %s\n",
                                                (sfx->loopstart >= 0) ? 'L' : ' ',