예제 #1
0
void SoundSource::Update(float timeStep)
{
    if (!audio_)
        return;
    
    // If there is no actual audio output, perform fake mixing into a nonexistent buffer to check stopping/looping
    if (!audio_->IsInitialized())
        MixNull(timeStep);
    
    // Free the sound if playback has stopped
    if (sound_ && !position_)
    {
        FreeDecoder();
        sound_.Reset();
    }
    
    // Check for autoremove
    if (autoRemove_)
    {
        if (!IsPlaying())
        {
            autoRemoveTimer_ += timeStep;
            if (autoRemoveTimer_ > AUTOREMOVE_DELAY)
            {
                Remove();
                // Note: this object is now deleted, so only returning immediately is safe
                return;
            }
        }
        else
            autoRemoveTimer_ = 0.0f;
    }
}
예제 #2
0
void SoundSource::PlayLockless(Sound* sound)
{
    // Reset the time position in any case
    timePosition_ = 0.0f;
    
    if (sound)
    {
        if (!sound->IsCompressed())
        {
            // Uncompressed sound start
            signed char* start = sound->GetStart();
            if (start)
            {
                // Free Decoder in case previous sound was compressed
                FreeDecoder();
                sound_ = sound;
                position_ = start;
                fractPosition_ = 0;
                return;
            }
        }
        else
        {
            // Compressed sound start
            if (sound == sound_)
            {
                // If same compressed sound is already playing, rewind the Decoder
                sound_->RewindDecoder(decoder_);
                return;
            }
            else
            {
                // Else just set the new sound with a dummy start position. The mixing routine will allocate the new Decoder
                FreeDecoder();
                sound_ = sound;
                position_ = sound->GetStart();
                return;
            }
        }
    }
    
    // If sound pointer is null or if sound has no data, stop playback
    FreeDecoder();
    sound_.Reset();
    position_ = 0;
}
예제 #3
0
void FreeParkingLot(ParkingLot * parkinglot)
{
  FreeDecoder( GetDecoder( parkinglot ), GetVertices( parkinglot ) );
  FreeGraph( GetGraph( parkinglot ) ) ;
  freeLinkedList( GetAccesses( parkinglot) );
  freeLinkedList( GetQueueHead(parkinglot) );
  FreeParkedCars( GetParkedListHead(parkinglot) );
  free(parkinglot);
}
예제 #4
0
void SoundSource::SetSoundAttr(ResourceRef value)
{
    ResourceCache* cache = GetSubsystem<ResourceCache>();
    Sound* newSound = cache->GetResource<Sound>(value.name_);
    if (IsPlaying())
        Play(newSound);
    else
    {
        // When changing the sound and not playing, make sure the old decoder (if any) is freed
        FreeDecoder();
        sound_ = newSound;
    }
}
예제 #5
0
void SoundSource::Stop()
{
    if (!audio_)
        return;

    // If sound source is currently playing, have to lock the audio mutex
    if (position_)
    {
        MutexLock lock(audio_->GetMutex());
        StopLockless();
    }

    // Free the compressed sound decoder now if any
    FreeDecoder();

    MarkNetworkUpdate();
}