public void Equals() { var one = new AudioFormat(WaveFormatEncoding.LPCM, 2, 16, 48000); var two = new AudioFormat(WaveFormatEncoding.LPCM, 2, 16, 48000); Assert.IsTrue(one.Equals(two)); }
public void Equals() { var one = new AudioFormat (WaveFormatEncoding.LPCM, 2, 16, 48000); var two = new AudioFormat (WaveFormatEncoding.LPCM, 2, 16, 48000); Assert.IsTrue (one.Equals (two)); }
public void DoesNotEqual() { var one = new AudioFormat (WaveFormatEncoding.Unknown, 2, 16, 48000); var two = new AudioFormat (WaveFormatEncoding.LPCM, 2, 16, 48000); Assert.IsFalse (one.Equals (two)); one = new AudioFormat (WaveFormatEncoding.LPCM, 1, 16, 48000); Assert.IsFalse (one.Equals (two)); one = new AudioFormat (WaveFormatEncoding.LPCM, 2, 8, 48000); Assert.IsFalse (one.Equals (two)); one = new AudioFormat (WaveFormatEncoding.LPCM, 2, 16, 44100); Assert.IsFalse (one.Equals (two)); }
public void DoesNotEqual() { var one = new AudioFormat(WaveFormatEncoding.Unknown, 2, 16, 48000); var two = new AudioFormat(WaveFormatEncoding.LPCM, 2, 16, 48000); Assert.IsFalse(one.Equals(two)); one = new AudioFormat(WaveFormatEncoding.LPCM, 1, 16, 48000); Assert.IsFalse(one.Equals(two)); one = new AudioFormat(WaveFormatEncoding.LPCM, 2, 8, 48000); Assert.IsFalse(one.Equals(two)); one = new AudioFormat(WaveFormatEncoding.LPCM, 2, 16, 44100); Assert.IsFalse(one.Equals(two)); }
void PlayCurrentSound(IAudioOutput[] outputs, float volume) { for (int i = 0; i < outputs.Length; i++) { IAudioOutput output = outputs[i]; if (output == null) { output = MakeOutput(1); outputs[i] = output; } else { if (!output.IsFinished()) { continue; } } AudioFormat fmt = output.Format; if (fmt.Channels == 0 || fmt.Equals(format)) { PlaySound(output, volume); return; } } // This time we try to play the sound on all possible devices, // even if it requires the expensive case of recreating a device for (int i = 0; i < outputs.Length; i++) { IAudioOutput output = outputs[i]; if (!output.IsFinished()) { continue; } PlaySound(output, volume); return; } }
/// <summary> /// Indicates whether the format converter supports conversion to the /// specified target format encoding. /// </summary> /// <remarks> /// Indicates whether the format converter supports conversion to the /// specified target format encoding. /// </remarks> /// <param name="targetEncoding">the target format encoding for which support is queried /// </param> /// <returns><code>true</code> if the encoding is supported, otherwise <code>false</code> /// </returns> public virtual bool isTargetEncodingSupported(AudioFormat.Encoding targetEncoding ) { AudioFormat.Encoding[] targetEncodings = getTargetEncodings(); for (int i = 0; i < targetEncodings.Length; i++) { if (targetEncoding.Equals(targetEncodings[i])) { return true; } } return false; }
/// <summary> /// Indicates whether the format converter supports conversion from the /// specified source format encoding. /// </summary> /// <remarks> /// Indicates whether the format converter supports conversion from the /// specified source format encoding. /// </remarks> /// <param name="sourceEncoding">the source format encoding for which support is queried /// </param> /// <returns><code>true</code> if the encoding is supported, otherwise <code>false</code> /// </returns> public virtual bool isSourceEncodingSupported(AudioFormat.Encoding sourceEncoding ) { AudioFormat.Encoding[] sourceEncodings = getSourceEncodings(); for (int i = 0; i < sourceEncodings.Length; i++) { if (sourceEncoding.Equals(sourceEncodings[i])) { return true; } } return false; }
/// <summary> /// Indicates whether the format converter supports conversion to a particular encoding /// from a particular format. /// </summary> /// <remarks> /// Indicates whether the format converter supports conversion to a particular encoding /// from a particular format. /// </remarks> /// <param name="targetEncoding">desired encoding of the outgoing data</param> /// <param name="sourceFormat">format of the incoming data</param> /// <returns><code>true</code> if the conversion is supported, otherwise <code>false</code> /// </returns> public virtual bool isConversionSupported(AudioFormat.Encoding targetEncoding , AudioFormat sourceFormat) { AudioFormat.Encoding[] targetEncodings = getTargetEncodings(sourceFormat ); for (int i = 0; i < targetEncodings.Length; i++) { if (targetEncoding.Equals(targetEncodings[i])) { return true; } } return false; }
protected int GetDataForCurrentTrack(AudioFormat format, int framesRequested, Span <byte> dest, int framesOffset = 0) { if (Status != PlaybackStatus.Playing) { return(0); } int playlistCount; lock (_playlist) { playlistCount = _playlist.Count; } if (_currentTrack < 0 || _currentTrack > playlistCount - 1) { return(0); } // Pause if window is not focused. if (Engine.Host != null && !Engine.Host.IsFocused) { Engine.Host.FocusWait.WaitOne(); } AudioTrack currentTrack; lock (_playlist) { currentTrack = _playlist[_currentTrack]; } if (currentTrack == null) { return(0); } // Set the conversion format to the requested one - if it doesn't match. if (!format.Equals(currentTrack.ConvFormat)) { currentTrack.SetConvertFormat(format); } // Get frames from the streamer. int framesOutput = currentTrack.GetNextFrames(framesRequested, dest.Slice(framesOffset * format.FrameSize)); // Check if the buffer was filled. Debug.Assert(framesOutput <= framesRequested); if (framesOutput == framesRequested) { return(framesOutput); } // If less frames were drawn than the buffer can take - the track is over. // Check if looping. if (LoopingCurrent) { currentTrack.Reset(); OnTrackLoop.Invoke(currentTrack.File); } // Otherwise, go to next track. else { lock (_playlist) { _playlist.RemoveAt(0); } playlistCount--; } // Check if there are more tracks. if (playlistCount > 0) { framesOutput += GetDataForCurrentTrack(format, framesRequested - framesOutput, dest, framesOutput); AudioTrack newTrack; lock (_playlist) { newTrack = _playlist[_currentTrack]; } OnTrackChanged.Invoke(currentTrack.File, newTrack.File); } else { lock (_playlist) { TransitionStatus(PlaybackStatus.NotPlaying); } OnTrackChanged.Invoke(currentTrack.File, null); } return(framesOutput); }