示例#1
0
        public ISoundObj Subset(int start, int count)
        {
            bool          started = false;
            ISampleBuffer sb      = GetInputEnum();

            return(new CallbackSource(NumChannels, SampleRate, delegate(long n)
            {
                int nn;
                bool more;
                if (!started)
                {
                    sb.Skip(start, out nn, out more);
                    started = true;
                }
                if (n > count)
                {
                    return null;
                }
                ISample[] sa = sb.Read(1, out nn, out more);
                if (sa.Length > 0)
                {
                    return sa[0];
                }
                else
                {
                    return null;
                }
            }));
        }
示例#2
0
        /// <summary>
        ///		Initializes a new sound instance, and loads its sample from the given
        ///		file path (and or memory url).
        /// </summary>
        /// <param name="path">File path or memory url to sound to load.</param>
        /// <param name="flags">Describes how this sound should be loaded and played.</param>
        public Sound(object path, SoundFlags flags)
        {
            // Save details.
            _flags = flags;
            _url   = path as string;

            // Load the audio sample then.
            _sample = SampleFactory.LoadSample(path, (flags & SoundFlags.Streamed) != 0);

            // Load one buffer for quick response.
            ISampleBuffer buffer = AudioManager.Driver.CreateSampleBuffer(_sample, flags);

            _frequency = buffer.Frequency;
            _buffers.Add(buffer);

            // If its not dynamic then destroy the samples data as its just cluttering up space.
            if ((_flags & SoundFlags.Dynamic) == 0)
            {
                if (_sample != null)
                {
                    _sampleLength = _sample.Data.Length;
                    _sample.Data  = null;
                }
                //GC.Collect();
                _globalBuffer = buffer; // Save the global buffer as its what we will get our data from.
            }
        }
        /// <summary>
        ///     Reloads the currently selected sound.
        /// </summary>
        private void ReloadSound()
        {
            if (_soundChannel != null)
            {
                _soundChannel.Stop();
                _soundChannel = null;
            }
            if (_sound != null)
            {
                _sound.Stop();
                _sound = null;
            }
            GC.Collect();

            SoundFlags flags = 0;

            if (_streamed == true)
            {
                flags |= SoundFlags.Streamed;
            }
            if (_positional == true)
            {
                flags |= SoundFlags.Positional;
            }
            if (fileTreeView.SelectedNode != null && File.Exists(Engine.GlobalInstance.AudioPath + "/" + fileTreeView.SelectedNode.FullPath))
            {
                _sound        = AudioManager.LoadSound(Engine.GlobalInstance.AudioPath + "/" + fileTreeView.SelectedNode.FullPath, flags);
                _soundChannel = _sound.Play();
            }
            SyncronizeWindow();
        }
示例#4
0
 private ISampleBuffer GetInputEnum()
 {
     if (_inputEnum == null)
     {
         _inputEnum = _input.GetBufferedEnumerator() as ISampleBuffer;
     }
     return(_inputEnum);
 }
 /// <summary>
 ///     Initializes a new instance of this class.
 /// </summary>
 public ChannelFadeProcess(ISampleBuffer channel, float start, float end, int duration)
 {
     _channel = channel;
     _startVolume = start;
     _endVolume = end;
     _duration = duration;
     channel.Volume = start;
 }
 /// <summary>
 ///     Initializes a new instance of this class.
 /// </summary>
 public ChannelFadeProcess(ISampleBuffer channel, float start, float end, int duration)
 {
     _channel       = channel;
     _startVolume   = start;
     _endVolume     = end;
     _duration      = duration;
     channel.Volume = start;
 }
示例#7
0
 /// <summary>
 ///     Disposes of this class when it is closed.
 /// </summary>
 /// <param name="sender">Object that invoked this event.</param>
 /// <param name="e">Reason why this event was invoked.</param>
 private void MusicPlayerWindow_FormClosed(object sender, FormClosedEventArgs e)
 {
     _soundChannel.Stop();
     _soundChannel = null;
     _sound.Stop();
     _sound = null;
     GC.Collect();
 }
 /// <summary>
 ///
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void SoundSelectorWindow_FormClosed(object sender, FormClosedEventArgs e)
 {
     if (_soundChannel != null)
     {
         _soundChannel.Stop();
         _soundChannel = null;
     }
     GC.Collect();
 }
示例#9
0
 void done()
 {
     // Done
     _running     = false;
     src          = null;
     output       = null;
     accum        = null;
     inputSamples = null;
 }
示例#10
0
        public void ResumeChannel(ScriptThread thread)
        {
            ISampleBuffer sound = ((NativeObject)thread.GetObjectParameter(0)).Object as ISampleBuffer;

            if (sound == null)
            {
                DebugLogger.WriteLog((thread.Process.Url != null && thread.Process.Url != "" ? thread.Process.Url : "A script") + " called ResumeChannel with an invalid object.", LogAlertLevel.Error);
                return;
            }
            sound.Paused = false;
        }
示例#11
0
        public void ChannelOuterRadius(ScriptThread thread)
        {
            ISampleBuffer sound = ((NativeObject)thread.GetObjectParameter(0)).Object as ISampleBuffer;

            if (sound == null)
            {
                DebugLogger.WriteLog((thread.Process.Url != null && thread.Process.Url != "" ? thread.Process.Url : "A script") + " called ChannelOuterRadius with an invalid object.", LogAlertLevel.Error);
                return;
            }
            thread.SetReturnValue(sound.OuterRadius);
        }
示例#12
0
        public void SetChannel3DVolume(ScriptThread thread)
        {
            ISampleBuffer sound = ((NativeObject)thread.GetObjectParameter(0)).Object as ISampleBuffer;

            if (sound == null)
            {
                DebugLogger.WriteLog((thread.Process.Url != null && thread.Process.Url != "" ? thread.Process.Url : "A script") + " called SetChannel3DPosition with an invalid object.", LogAlertLevel.Error);
                return;
            }
            sound.Position3D = new Vector(thread.GetFloatParameter(1), thread.GetFloatParameter(2), thread.GetFloatParameter(3));
        }
示例#13
0
        public void SetChannelFrequency(ScriptThread thread)
        {
            ISampleBuffer sound = ((NativeObject)thread.GetObjectParameter(0)).Object as ISampleBuffer;

            if (sound == null)
            {
                DebugLogger.WriteLog((thread.Process.Url != null && thread.Process.Url != "" ? thread.Process.Url : "A script") + " called SetChannelFrequency with an invalid object.", LogAlertLevel.Error);
                return;
            }
            sound.Frequency = thread.GetIntegerParameter(1);
        }
        /// <summary>
        ///     Initializes a new instance of this class. 
        /// </summary>
        /// <param name="file">Music file to play.</param>
        public MusicPlayerWindow(string file)
        {
            InitializeComponent();

            _sound = AudioManager.LoadSound(file, 0);
            _soundChannel = _sound.Play();
            frequencyTrackBar.Value = _soundChannel.Frequency;
            panTrackBar.Value = (int)(_soundChannel.Pan * 50);
            volumeTrackBar.Value = (int)(_soundChannel.Volume);
            updateTimer.Start();
            fileLabel.Text = Path.GetFileName(file);
            Text = "Music Player - " + Path.GetFileName(file);
        }
示例#15
0
        /// <summary>
        ///     Initializes a new instance of this class.
        /// </summary>
        /// <param name="file">Music file to play.</param>
        public MusicPlayerWindow(string file)
        {
            InitializeComponent();

            _sound                  = AudioManager.LoadSound(file, 0);
            _soundChannel           = _sound.Play();
            frequencyTrackBar.Value = _soundChannel.Frequency;
            panTrackBar.Value       = (int)(_soundChannel.Pan * 50);
            volumeTrackBar.Value    = (int)(_soundChannel.Volume);
            updateTimer.Start();
            fileLabel.Text = Path.GetFileName(file);
            Text           = "Music Player - " + Path.GetFileName(file);
        }
示例#16
0
        public bool ReadTo(int n)
        {
            if (n < _samples.Count)
            {
                return(true);
            }
            if (_input == null)
            {
                _moreSamples = false;
                return(_moreSamples);
            }
            if (_inputEnum == null)
            {
                _inputEnum = _input.GetBufferedEnumerator() as ISampleBuffer;
            }
            int nn = n - _samples.Count;

            if (nn > 0 && _moreSamples)
            {
                if (n < int.MaxValue && _samples.Capacity < n)
                {
                    _samples.Capacity = n;
                }
                int tot = 0;
                int nnn;
                while (_moreSamples && tot < nn)
                {
                    ISample[] tmp = _inputEnum.Read(DSPUtil.BUFSIZE, out nnn, out _moreSamples);
                    for (int j = 0; j < nnn; j++)
                    {
                        _samples.Add(tmp[j]);
                    }
                    tot += nnn;
                }
            }
            return(nn < 0 || _moreSamples);
        }
示例#17
0
        /// <summary>
        ///     Invoked when the pause button is clicked.
        /// </summary>
        /// <param name="sender">Object that invoked this event.</param>
        /// <param name="e">Reason why this event was invoked.</param>
        private void pauseButton_Click(object sender, EventArgs e)
        {
            if (_soundChannel.Finished == true && _soundChannel.Paused == false)
            {
                _soundChannel          = null;
                _soundChannel          = _sound.Play();
                pauseButton.ImageIndex = 0;
                pauseButton.Text       = "Pause";
                return;
            }

            if (_soundChannel.Paused == false)
            {
                _soundChannel.Paused   = true;
                pauseButton.ImageIndex = 1;
                pauseButton.Text       = "Resume";
            }
            else
            {
                _soundChannel.Paused   = false;
                pauseButton.ImageIndex = 0;
                pauseButton.Text       = "Pause";
            }
        }
 /// <summary>
 /// 
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void SoundSelectorWindow_FormClosed(object sender, FormClosedEventArgs e)
 {
     if (_soundChannel != null)
     {
         _soundChannel.Stop();
         _soundChannel = null;
     }
     GC.Collect();
 }
示例#19
0
 public ChannelScriptObject(ISampleBuffer buffer)
 {
     _nativeObject = buffer;
 }
示例#20
0
 public override void Reset()
 {
     _inputEnum = null;
 }
示例#21
0
 public bool ReadTo(int n)
 {
     if (n < _samples.Count)
     {
         return true;
     }
     if (_input == null)
     {
         _moreSamples = false;
         return _moreSamples;
     }
     if (_inputEnum == null)
     {
         _inputEnum = _input.GetBufferedEnumerator() as ISampleBuffer;
     }
     int nn = n - _samples.Count;
     if (nn > 0 && _moreSamples)
     {
         if (n<int.MaxValue && _samples.Capacity < n) _samples.Capacity = n;
         int tot = 0;
         int nnn;
         while (_moreSamples && tot < nn)
         {
             ISample[] tmp = _inputEnum.Read(DSPUtil.BUFSIZE, out nnn, out _moreSamples);
             for (int j = 0; j < nnn; j++)
             {
                 _samples.Add(tmp[j]);
             }
             tot += nnn;
         }
     }
     return nn < 0 || _moreSamples;
 }
示例#22
0
        /// <summary>
        ///		Initializes a new sound instance, and loads its sample from the given
        ///		file path (and or memory url).
        /// </summary>
        /// <param name="path">File path or memory url to sound to load.</param>
        /// <param name="flags">Describes how this sound should be loaded and played.</param>
        public Sound(object path, SoundFlags flags)
        {
            // Save details.
            _flags = flags;
            _url = path as string;

            // Load the audio sample then.
            _sample = SampleFactory.LoadSample(path, (flags & SoundFlags.Streamed) != 0);

            // Load one buffer for quick response.
            ISampleBuffer buffer = AudioManager.Driver.CreateSampleBuffer(_sample, flags);
            _frequency = buffer.Frequency;
            _buffers.Add(buffer);

            // If its not dynamic then destroy the samples data as its just cluttering up space.
            if ((_flags & SoundFlags.Dynamic) == 0)
            {
                if (_sample != null)
                {
                    _sampleLength = _sample.Data.Length;
                    _sample.Data = null;
                }
                //GC.Collect();
                _globalBuffer = buffer; // Save the global buffer as its what we will get our data from.
            }
        }
示例#23
0
 private ISampleBuffer GetInputEnum()
 {
     if (_inputEnum == null)
     {
         _inputEnum = _input.GetBufferedEnumerator() as ISampleBuffer;
     }
     return _inputEnum;
 }
示例#24
0
 public override void Reset()
 {
     _inputEnum = null;
 }
 /// <summary>
 ///     Disposes of this class when it is closed.
 /// </summary>
 /// <param name="sender">Object that invoked this event.</param>
 /// <param name="e">Reason why this event was invoked.</param>
 private void MusicPlayerWindow_FormClosed(object sender, FormClosedEventArgs e)
 {
     _soundChannel.Stop();
     _soundChannel = null;
     _sound.Stop();
     _sound = null;
     GC.Collect();
 }
示例#26
0
 public ChannelScriptObject(ISampleBuffer buffer)
 {
     _nativeObject = buffer;
 }
示例#27
0
        /// <summary>
        ///		Starts playing this sound.
        /// </summary>
        public ISampleBuffer Play()
        {
            ISampleBuffer playbackBuffer = null;

            // Global buffer not playing?
            if (_globalBuffer != null && _globalBuffer.Finished == true)
            {
                playbackBuffer = _globalBuffer;
            }

            // See if we can just replay one that has finished.
            if (playbackBuffer == null)
            {
                foreach (ISampleBuffer buffer in _buffers)
                {
                    if (buffer.Finished == true)
                    {
                        playbackBuffer = buffer;
                    }
                }
            }

            // No available buffers? Create a new one.
            if (playbackBuffer == null)
            {
                // Refill the samples data from the global buffer if we are not dynamic.
                if ((_flags & SoundFlags.Dynamic) == 0 && _globalBuffer != null)
                {
                    _sample.Data = _globalBuffer.GetCurrentData();
                }

                playbackBuffer = _globalBuffer.Clone();

                if ((_flags & SoundFlags.Dynamic) == 0 && _globalBuffer != null)
                {
                    _sample.Data = new byte[0];
                }

                _buffers.Add(playbackBuffer);
            }

            // Play buffer
            playbackBuffer.Play();

            // Set values.
            if (_pan != 0.0f)
            {
                playbackBuffer.Pan = _pan;
            }
            if (_volume != 0.0f)
            {
                playbackBuffer.Volume = _volume;
            }
            if (_innerRadius != 0.0f)
            {
                playbackBuffer.InnerRadius = _innerRadius;
            }
            if (_outerRadius != 0.0f)
            {
                playbackBuffer.OuterRadius = _outerRadius;
            }
            playbackBuffer.Looping = _looping;
            if (_frequency != 0.0f)
            {
                playbackBuffer.Frequency = _frequency;
            }

            // To many buffers? Delete some.
            while (_buffers.Count > 4)
            {
                ((ISampleBuffer)_buffers[0]).Stop();
                _buffers.RemoveAt(0);
            }

            // Return it.
            return(playbackBuffer);
        }
        /// <summary>
        ///     Reloads the currently selected sound.
        /// </summary>
        private void ReloadSound()
        {
            if (_soundChannel != null)
            {
                _soundChannel.Stop();
                _soundChannel = null;
            }
            if (_sound != null)
            {
                _sound.Stop();
                _sound = null;
            }
            GC.Collect();

            SoundFlags flags = 0;
            if (_streamed == true) flags |= SoundFlags.Streamed;
            if (_positional == true) flags |= SoundFlags.Positional;
            if (fileTreeView.SelectedNode != null && File.Exists(Engine.GlobalInstance.AudioPath + "/" + fileTreeView.SelectedNode.FullPath))
            {
                _sound = AudioManager.LoadSound(Engine.GlobalInstance.AudioPath + "/" + fileTreeView.SelectedNode.FullPath, flags);
                _soundChannel = _sound.Play();
            }
            SyncronizeWindow();
        }
        /// <summary>
        ///     Invoked when the pause button is clicked.
        /// </summary>
        /// <param name="sender">Object that invoked this event.</param>
        /// <param name="e">Reason why this event was invoked.</param>
        private void pauseButton_Click(object sender, EventArgs e)
        {
            if (_soundChannel.Finished == true && _soundChannel.Paused == false)
            {
                _soundChannel = null;
                _soundChannel = _sound.Play();
                pauseButton.ImageIndex = 0;
                pauseButton.Text = "Pause";
                return;
            }

            if (_soundChannel.Paused == false)
            {
                _soundChannel.Paused = true;
                pauseButton.ImageIndex = 1;
                pauseButton.Text = "Resume";
            }
            else
            {
                _soundChannel.Paused = false;
                pauseButton.ImageIndex = 0;
                pauseButton.Text = "Pause";
            }
        }