Esempio n. 1
0
        public static void load_batch_samples(string folder)
        {
            //Debug.Log("Loading audio clips from folder " + folder);
            Debug.StartLogGroup();

            DirectoryInfo dir = new DirectoryInfo(folder);
            if (dir.Exists)
            {
                var ogg_files = dir.GetFiles("*.ogg", SearchOption.AllDirectories);
                var wav_files = dir.GetFiles("*.wav", SearchOption.AllDirectories);
                //var mp3_files = dir.GetFiles("*.mp3", SearchOption.AllDirectories);

                var lst = new List<FileInfo>();
                lst.AddRange(ogg_files);
                lst.AddRange(wav_files);
                //lst.AddRange(mp3_files);

                foreach (var file in lst)
                {
                    var s = new Sample(file.FullName);
                    if (s.buffer == null)
                        Debug.Log("Failed loading sample " + file.FullName);
                    samples.Add(s);
                    _lookup.Add(s.name, s);
                }
            }
            Debug.EndLogGroup();
        }
Esempio n. 2
0
        public static AmbientSound ambient_sound(int unique_id, Sample sample, float volume = 0.5f, float pan = 0f, float pitch = 1f)
        {
            AmbientSound s;

            var key = unique_id ^ (sample.index << 16);

            if (ambient_sounds.ContainsKey(key))    s = ambient_sounds[key];
            else                                    {s = new AmbientSound(sample); ambient_sounds.Add(key, s);};

            s.nudge(volume, pan, pitch);

            return s;
        }
Esempio n. 3
0
        public static void play(Sample sample, float volume = 0.65f, float pan = 0f, float pitch = 1f)
        {
            if (sample == null) return;
            if (Application.audio_disabled) return;

            var sound = new SA.Sound();

            sounds.Add(sound);
            sound.SoundBuffer = sample.buffer;
            sound.Loop = false;
            sound.Pitch = pitch;

            sound.Volume = volume * volume * sample.volume_modifier * 100f;
            sound.Play();
        }
Esempio n. 4
0
            public AmbientSound(Sample sample)
            {
                this.volume = 0.5f;
                this.pan = 0f;
                this.pitch = 1f;
                this.assigned_sample = sample;

                // create sound object
                sound = new SA.Sound();
                sound.SoundBuffer = sample.buffer;
                sound.Loop = true;
                sound.Pitch = pitch;
                sound.Volume = volume * volume * sample.volume_modifier * 100f;
            }