Beispiel #1
0
        public float SecondsRemaining(SoundTag snd)
        {
            if (SoundTagEmitters.TryGetValue(snd.Id, out var emitter))
            {
                return((float)emitter.RemainingTime().TotalSeconds);
            }

            return(0);
        }
Beispiel #2
0
    private AudioClip GetClip(SoundTag soundTag)
    {
        foreach (SoundItem s in clips)
        {
            if (s.tag == soundTag)
            {
                return(s.clip);
            }
        }

        return(null);
    }
Beispiel #3
0
    private void PlaySound(SoundTag soundTag)
    {
        AudioSource player = audioSourcePool.GetAvailableAudioSource();

        if (player == null)
        {
            Debug.LogWarning("there is no available audio source left available");
            return;
        }

        player.clip = GetClip(soundTag);
        player.Play();
    }
Beispiel #4
0
        private ClipData GetClip(SoundTag snd)
        {
            var soundEntry = soundMapping.SoundEntries[snd.SoundEntryIndex];

            var clipIndex = rng.Next(0, soundEntry.NamedSoundClipCount);
            var clipInfo  = soundMapping.NamedSoundClips[soundEntry.NamedSoundClipIndex + clipIndex];

            var result = new ClipData();

            result.Encoding = snd.Encoding switch
            {
                EncodingType.ImaAdpcmMono => AudioEncoding.MonoImaAdpcm,
                EncodingType.ImaAdpcmStereo => AudioEncoding.StereoImaAdpcm,
                _ => AudioEncoding.Mono16,
            };

            result.SampleRate = snd.SampleRate switch
            {
                Core.Tags.SampleRate.hz22k05 => SampleRate._22k05,
                Core.Tags.SampleRate.hz44k1 => SampleRate._44k1,
                _ => SampleRate._44k1
            };

            var clipSize = 0;

            for (var c = 0; c < clipInfo.SoundDataChunkCount; c++)
            {
                var chunk = soundMapping.SoundDataChunks[clipInfo.SoundDataChunkIndex + c];
                clipSize += (int)(chunk.Length & 0x3FFFFFFF);
            }

            Span <byte> clipData        = new byte[clipSize];
            var         clipDataCurrent = 0;

            for (var c = 0; c < clipInfo.SoundDataChunkCount; c++)
            {
                var chunk = soundMapping.SoundDataChunks[clipInfo.SoundDataChunkIndex + c];

                var len       = (int)(chunk.Length & 0x3FFFFFFF);
                var chunkData = this.scene.Map.ReadData(chunk.Offset.Location, chunk.Offset, len);

                chunkData.Span.CopyTo(clipData.Slice(clipDataCurrent));
                clipDataCurrent += len;
            }

            result.Data = clipData;

            return(result);
        }
Beispiel #5
0
    void Update()
    {
        while (callQueue.Count > 0)
        {
            Action   action = callQueue.Dequeue();
            SoundTag param  = paramQueue.Dequeue();

            switch (action)
            {
            case Action.PlaySound: PlaySound(param); break;

            case Action.PlayBGM: PlayBGM(); break;

            case Action.StopAll: StopAll(); break;
            }
        }
    }
Beispiel #6
0
        public void Start(SoundTag sound, IGameObject target)
        {
            var clip = GetClip(sound);

            ISoundEmitter emitter;

            if (target is GameObjectEntity e)
            {
                if (e.SoundEmitter.Emitter == null)
                {
                    // TODO: destroy emitter
                    e.SoundEmitter.Emitter = this.audioAdapter.CreateEmitter();
                }

                emitter = e.SoundEmitter.Emitter;
            }
            else
            {
                emitter = globalEmitter;
            }

            emitter.PlayImmediate(clip.Encoding, clip.SampleRate, clip.Data);
            SoundTagEmitters[sound.Id] = emitter;
        }
Beispiel #7
0
 public AudioClip GetClip(SoundTag sound)
 {
     return(_generalSFX[(int)sound]);
 }
Beispiel #8
0
 /// <summary>plays an impulse sound from the specified source object (or "none"), with the specified scale.</summary>
 public void sound_impulse_trigger(SoundTag sound, IGameObject source, float floatValue, int intValue)
 {
     this.audioSystem.Start(sound, source);
 }
Beispiel #9
0
 /// <summary>stops the specified impulse sound.</summary>
 public void sound_impulse_stop(SoundTag sound)
 {
 }
Beispiel #10
0
 /// <summary>plays an impulse sound from the specified source object (or "none"), with the specified scale and effect.</summary>
 public void sound_impulse_start_effect(SoundTag sound, IGameObject entity, float floatValue, string /*id*/ effect)
 {
     this.audioSystem.Start(sound, entity);
 }
Beispiel #11
0
 /// <summary>plays an impulse sound from the specified source object (or "none"), with the specified scale.</summary>
 public void sound_impulse_start(SoundTag sound, IGameObject entity, float floatValue)
 {
     this.audioSystem.Start(sound, entity);
 }
Beispiel #12
0
 /// <summary>returns the time remaining for the specified impulse sound. DO NOT CALL IN CUTSCENES.</summary>
 public int sound_impulse_language_time(SoundTag soundRef)
 {
     return((int)(this.audioSystem.SecondsRemaining(soundRef) * TicksPerSecond));
 }
Beispiel #13
0
 static public void CallFunction(Action action, SoundTag tag)
 {
     callQueue.Enqueue(action);
     paramQueue.Enqueue(tag);
 }
Beispiel #14
0
 /// <summary>your mom part 2.</summary>
 public void sound_impulse_predict(SoundTag soundRef)
 {
 }