Ejemplo n.º 1
0
        private int GetFreeSample(Sample sample)
        {
            if (sample == null)
                return -1;

            for (int i = 0; i < CountInstancePerSample; i++)
            {
                WaveChannel32 channel = channelSteam[dicSample[sample.Name][i]];

                if (!PlayingNote[dicSample[sample.Name][i]] && channel.CurrentTime == TimeSpan.Zero || channel.CurrentTime >= channel.TotalTime)
                {
                    return i;
                }
            }

            return -1;
        }
Ejemplo n.º 2
0
        private EffectChain CreateEffectChain(Sample sample)
        {
            EffectChain effectChain = new EffectChain();
            List<Effect> listEffect = new List<Effect>();

            List<List<Effect>> listListEffect;

            if (dicEffect.ContainsKey(sample.Name))
            {
                listListEffect = dicEffect[sample.Name];
            }
            else
            {
                listListEffect = new List<List<Effect>>();
                dicEffect.Add(sample.Name, listListEffect);
            }

            listListEffect.Add(listEffect);

            //AddEffect(effectChain, listEffect, typeof(Volume));
            //AddEffect(effectChain, listEffect, typeof(Chorus));
            //AddEffect(effectChain, listEffect, typeof(JSNet.Delay));
            //AddEffect(effectChain, listEffect, typeof(Flanger));
            //AddEffect(effectChain, listEffect, typeof(Tremolo));
            AddEffect(effectChain, listEffect, typeof(SuperPitch));

            return effectChain;
        }
Ejemplo n.º 3
0
        public void PlayNote(Sample sample, float noteKey)
        {
            int indexChannel = GetFreeSample(sample);

            if (indexChannel != -1)
            {
                PlayingNote[dicSample[sample.Name][indexChannel]] = true;

                Effect effect = dicEffect[sample.Name][indexChannel].Find(e => e.Name == "SuperPitch");

                float octave = (int)((noteKey - sample.NoteKey) / 12f);
                float semitonesF = noteKey - (sample.NoteKey + 12f * octave);
                float semitones = (int)semitonesF;
                float cents = (int)((semitonesF - semitones) * 100f);

                //AddSlider(0, -100, 100, 1, "Pitch adjust (cents)");
                //AddSlider(0, -12, 12, 1, "Pitch adjust (semitones)");
                //AddSlider(0, -12, 12, 1, "Pitch adjust (octaves)");
                //AddSlider(50, 0, 200, 1, "Window size (ms)");
                //AddSlider(20, 0.05f, 50, 0.5f, "Overlap size (ms)");

                effect.Enabled = true;
                effect.Sliders[0].Value = cents;
                effect.Sliders[1].Value = semitones;
                effect.Sliders[2].Value = octave;
                //effect.Sliders[3].Value = 200;
                //effect.Sliders[4].Value = 50f;
                effect.Slider();

                channelSteam[dicSample[sample.Name][indexChannel]].Position = 0;
            }
        }
Ejemplo n.º 4
0
        public void PlaySample(Sample sample)
        {
            int indexChannel = GetFreeSample(sample);

            if (indexChannel != -1)
            {
                channelSteam[dicSample[sample.Name][indexChannel]].Position = 0;
            }
        }
Ejemplo n.º 5
0
        public void LoadLibrary(string libraryName, Map map)
        {
            map.LibraryName = libraryName;
            string libraryDirectory = Path.Combine(Directory.GetParent(Application.ExecutablePath).FullName, @"Files\Sound\Library", libraryName);

            InitializeChannel(map);

            foreach (string channelDirectory in Directory.GetDirectories(libraryDirectory))
            {
                Channel channel = map.Channels.Find(c => c.Name.ToUpper() == Path.GetFileName(channelDirectory).ToUpper());

                if (channel != null)
                {
                    channel.ListSample = new List<Sample>();
                    foreach (string sampleFileName in Directory.GetFiles(channelDirectory))
                    {
                        Sample sample = new Sample(channel, sampleFileName);
                        channel.ListSample.Add(sample);
                    }
                }
            }

            //---
            bool writeNewConfig = false;
            Map mapConfig = FileSystem.LoadLevelConfig(this, map.LibraryName);

            if (mapConfig != null)
            {
                foreach (Channel channel in map.Channels)
                {
                    Channel channelConfig = mapConfig.Channels.Find(c => c.Name == channel.Name);

                    if (channelConfig != null)
                    {
                        foreach (Sample sample in channel.ListSample)
                        {
                            Sample sampleConfig = channelConfig.ListSample.Find(s => s.Name == sample.Name);

                            if (sampleConfig != null)
                            {
                                sample.NoteKey = sampleConfig.NoteKey;
                                sample.Frequency = sampleConfig.Frequency;
                            }

                            if (sample.Frequency == -1f)
                                writeNewConfig = true;
                        }
                    }
                }
            }

            GameEngine.Sound.Init(map);

            if (writeNewConfig || mapConfig == null)
                FileSystem.SaveLibraryConfig(map);
            //---

            map.Channels.RemoveAll(c => c.ListSample.Count == 0 && c.Name != "Empty");
        }