Ejemplo n.º 1
0
        public static int LoadSample(string SamplePath)
        {
            try
            {
                if (UsedLibrary == AudioLibrary.NAudio)
                {
                    // NAUDIO
                    var        reader = new WaveFileReader(SamplePath);
                    WaveStream Stream = null;

                    if (reader.WaveFormat.BitsPerSample == 16)
                    {
                        Stream = new WaveChannel16To32(reader);                                                           //Volume e Pan da aggiungere
                    }
                    else if (reader.WaveFormat.BitsPerSample == 24)
                    {
                        Stream = new WaveChannel24To32(reader);
                    }
                    else if (reader.WaveFormat.BitsPerSample == 32 && reader.WaveFormat.Encoding == WaveFormatEncoding.Pcm)
                    {
                        Stream = new WaveChannel32To32(reader);
                    }
                    else if (reader.WaveFormat.BitsPerSample == 32 && reader.WaveFormat.Encoding == WaveFormatEncoding.IeeeFloat)
                    {
                        MessageBox.Show("Attenzione"); Stream = new WaveChannel32(new Wave32To16Stream(reader));
                    }

                    if (Stream != null)
                    {
                        if (Stream is WaveChannel16To32)
                        {
                            ((WaveChannel16To32)Stream).Volume = 0.0f;
                        }
                        else if (Stream is WaveChannel24To32)
                        {
                            ((WaveChannel24To32)Stream).Volume = 0.0f;
                        }
                        else if (Stream is WaveChannel32To32)
                        {
                            ((WaveChannel32To32)Stream).Volume = 0.0f;
                        }
                        else if (Stream is WaveChannel32)
                        {
                            ((WaveChannel32)Stream).Volume = 0.0f;
                        }

                        Samples.Add(Stream);
                        Mixer32.AddInputStream(Stream);

                        return(Samples.Count - 1);
                    }
                    //=============================================
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            return(0);
        }
Ejemplo n.º 2
0
        public static VST LoadVst(string vstPath, IntPtr hWnd)
        {
            DisposeVst();

            _generalVst = new VST();

            var hcs = new HostCommandStub {
                Directory = System.IO.Path.GetDirectoryName(vstPath)
            };

            try
            {
                _generalVst.pluginContext = VstPluginContext.Create(vstPath, hcs);
                _generalVst.pluginContext.PluginCommandStub.Open();
                _generalVst.pluginContext.PluginCommandStub.SetProgram(13000);
                _generalVst.pluginContext.PluginCommandStub.EditorOpen(hWnd);
                _generalVst.pluginContext.PluginCommandStub.MainsChanged(true);

                _vstStream = new VSTStream();
                _vstStream.ProcessCalled += _generalVst.Stream_ProcessCalled;
                _vstStream.pluginContext  = _generalVst.pluginContext;
                _vstStream.SetWaveFormat(44100, 2);

                _mixer32.AddInputStream(_vstStream);

                return(_generalVst);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
            return(null);
        }