Example #1
0
//***************************************************************************
//
// SD_UpdatePlaybackSound - Update playback of a sound in chunks
//
//***************************************************************************
void SD_UpdatePlaybackSound ( char ** ptr, unsigned long * length )
   {
   if ( Playing==false )
      {
      *ptr = NULL;
      *length = 0;
      return;
      }
   if (PlayingPointer==PlaybackPointer)
      {
      *ptr = NULL;
      *length = 0;
      if (Playback==false)
         {
         FX_StopSound( Playingvoice );
         SafeFree ( PlaybackBuffer );
         Playing=false;
         }
      return;
      }

   *length=PLAYBACKDELTASIZE;

   if (PlayingPointer==-1)
      {
      *ptr = NULL;
      *length = 0;
      return;
      }

   *ptr=&PlaybackBuffer[PlayingPointer];

   PlayingPointer = (PlayingPointer + *length) &
                      (PLAYBACKBUFFERSIZE - 1);
   }
Example #2
0
void
StopSong(void)
{
    if (DemoMode)
        return;

    if (SongType == SongTypeWave && SongVoice >= 0)
    {
        FX_StopSound(SongVoice);
    }
    else if (SongType == SongTypeMIDI)
    {
        MUSIC_StopSong();
    }
    SongType = SongTypeNone;

    DO_FREE_AND_NULL(SongName);
    SongTrack = 0;

    if (SongPtr)
    {
        FreeMem(SongPtr);
        SongPtr = 0;
        SongLength = 0;
    }
}
Example #3
0
/////////////////////////////////////////////////////
// Deletes vocs in the 3D sound queue with no owners
/////////////////////////////////////////////////////
void
DeleteNoSoundOwner(short spritenum)
{
    VOC3D_INFOp vp, dp;

    vp = voc3dstart;

    while (vp)
    {
        dp = NULL;
        if (vp->owner == spritenum && vp->owner >= 0 && (vp->vp->voc_flags & vf_loop))
        {
            //DSPRINTF(ds,"Deleting owner %d\n",vp->owner);
            //MONO_PRINT(ds);

            // Make sure to stop active
            // sounds
            if (FX_SoundActive(vp->handle))
            {
                FX_StopSound(vp->handle);
            }

#if 0
            // Clean up the sound active counter for cacheing locks
            if (vp->FX_Ok) // Only decrement if sound ever played
                vp->vp->playing--; // Decrement instance of sound playing
            if (vp->vp->playing == 0 && vp->vp->lock > CACHE_UNLOCK_MAX)
                vp->vp->lock = CACHE_UNLOCK_MAX;
#endif


            dp = vp;                    // Point to sound to be deleted

            if (vp->prev)
            {
                vp->prev->next = vp->next;
            }
            else
            {
                voc3dstart = vp->next;  // New first item
                if (voc3dstart)
                    voc3dstart->prev = NULL;
            }

            if (vp->next)
            {
                vp->next->prev = vp->prev;      // Middle element
            }
            else
            {
                voc3dend = vp->prev;    // Delete last element
            }
        }

        vp = vp->next;

        if (dp != NULL)
            FreeMem(dp);                // Return memory to heap
    }
}
Example #4
0
static int32_t S_TakeSlot(int32_t num)
{
    S_Cleanup();

    uint32_t dist = 0, clock = UINT32_MAX;
    int32_t i = 0, j = 0;

    while (j < MAXSOUNDINSTANCES && g_sounds[num].SoundOwner[j].voice > 0)
    {
        if (g_sounds[num].SoundOwner[j].sndist > dist ||
            (g_sounds[num].SoundOwner[j].sndist == dist && g_sounds[num].SoundOwner[j].clock < clock))
        {
            clock = g_sounds[num].SoundOwner[j].clock;
            dist = g_sounds[num].SoundOwner[j].sndist;
            i = j;
        }

        j++;
    }

    if (j != MAXSOUNDINSTANCES)
        return j;

    if (FX_SoundActive(g_sounds[num].SoundOwner[i].voice))
        FX_StopSound(g_sounds[num].SoundOwner[i].voice);

    mutex_lock(&s_mutex);
    dq[dnum++] = (num * MAXSOUNDINSTANCES) + i;
    mutex_unlock(&s_mutex);
    S_Cleanup();

    return i;
}
Example #5
0
// This is called from KillSprite to kill a follow sound with no valid sprite owner
// Stops and active sound with the follow bit set, even play once sounds.
void DeleteNoFollowSoundOwner(short spritenum)
{
    VOC3D_INFOp vp, dp;
    SPRITEp sp = &sprite[spritenum];

    vp = voc3dstart;

    while (vp)
    {
        dp = NULL;
        // If the follow flag is set, compare the x and y addresses.
        if ((vp->flags & v3df_follow) && vp->x == &sp->x && vp->y == &sp->y)
        {
            if (FX_SoundActive(vp->handle))
            {
                FX_StopSound(vp->handle);
            }

#if 0
            if (vp->FX_Ok) // Only decrement if sound ever played
                vp->vp->playing--; // Decrement instance of sound playing
            if (vp->vp->playing == 0 && vp->vp->lock > CACHE_UNLOCK_MAX)
                vp->vp->lock = CACHE_UNLOCK_MAX;
#endif

            dp = vp;                    // Point to sound to be deleted

            if (vp->prev)
            {
                vp->prev->next = vp->next;
            }
            else
            {
                voc3dstart = vp->next;  // New first item
                if (voc3dstart)
                    voc3dstart->prev = NULL;
            }

            if (vp->next)
            {
                vp->next->prev = vp->prev;      // Middle element
            }
            else
            {
                voc3dend = vp->prev;    // Delete last element
            }
        }

        vp = vp->next;

        if (dp != NULL)
            FreeMem(dp);                // Return memory to heap
    }
}
Example #6
0
int SD_PlayIt ( int sndnum, int angle, int distance, int pitch )
{
   int voice;
   uint8_t * snd;

   if (!(sounds[sndnum].flags & SD_WRITE))
      {
      if (sounds[sndnum].count)
         {
         if (distance<=sounds[sndnum].prevdistance)
            FX_StopSound(sounds[sndnum].prevhandle);
         else
            return 0;
         }
      }

   if ( !FX_VoiceAvailable( sounds[sndnum].priority ) )
      {
      return( 0 );
      }

   sounds[sndnum].count++;

   snd=W_CacheLumpNum(SoundNumber(sndnum),PU_STATIC, CvtNull, 1);

   if ( *snd == 'C' )
      {
      voice = FX_PlayVOC3D( snd, pitch, angle, distance,
         sounds[sndnum].priority, (unsigned long) sndnum );
      }
   else
      {
      voice = FX_PlayWAV3D( snd, pitch, angle, distance,
         sounds[sndnum].priority, (unsigned long) sndnum );
      }

   if ( voice < FX_Ok )
      {
      SD_MakeCacheable( sndnum );

      return 0;
      }

   NumBadSounds=0;

   if (!(sounds[sndnum].flags & SD_WRITE))
      {
      sounds[sndnum].prevhandle=voice;
      sounds[sndnum].prevdistance=distance;
      }
   return voice;
}
Example #7
0
void S_StopMusic(void)
{
    MusicPaused = 0;

    if (MusicIsWaveform && MusicVoice >= 0)
    {
        FX_StopSound(MusicVoice);
        MusicVoice = -1;
        MusicIsWaveform = 0;
    }

    MUSIC_StopSong();

    ALIGNED_FREE_AND_NULL(MusicPtr);
    g_musicSize = 0;
}
Example #8
0
void stopmusic(void)
{
    if (MusicIsWaveform && MusicVoice >= 0) {
       FX_StopSound(MusicVoice);
       MusicVoice = -1;
    } else if (!MusicIsWaveform) {
       MUSIC_StopSong();
    }

    MusicPaused = 0;

    if (MusicPtr) {
       free(MusicPtr);
       MusicPtr = 0;
       MusicLen = 0;
    }
}