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; } })); }
/// <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(); }
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> /// 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(); }
void done() { // Done _running = false; src = null; output = null; accum = null; inputSamples = null; }
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; }
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); }
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)); }
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); }
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); }
/// <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"; } }
public ChannelScriptObject(ISampleBuffer buffer) { _nativeObject = buffer; }
public override void Reset() { _inputEnum = null; }
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; }
private ISampleBuffer GetInputEnum() { if (_inputEnum == null) { _inputEnum = _input.GetBufferedEnumerator() as ISampleBuffer; } return _inputEnum; }
/// <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(); }