/// <summary> /// Opens the audio track with the specified parameters /// </summary> /// <param name="sampleRate">The requested sample rate of the track</param> /// <param name="channelCount">The requested channel count of the track</param> /// <param name="callback">A <see cref="ReleaseCallback" /> that represents the delegate to invoke when a buffer has been released by the audio track</param> /// <param name="format">The requested sample format of the track</param> public void Open( int sampleRate, int channelCount, ReleaseCallback callback, SoundIOFormat format = SoundIOFormat.S16LE) { // Close any existing audio streams if (AudioStream != null) { Close(); } if (!AudioDevice.SupportsSampleRate(sampleRate)) { throw new InvalidOperationException($"This sound device does not support a sample rate of {sampleRate}Hz"); } if (!AudioDevice.SupportsFormat(format)) { throw new InvalidOperationException($"This sound device does not support SoundIOFormat.{Enum.GetName(typeof(SoundIOFormat), format)}"); } AudioStream = AudioDevice.CreateOutStream(); AudioStream.Name = $"SwitchAudioTrack_{TrackID}"; AudioStream.Layout = SoundIOChannelLayout.GetDefault(channelCount); AudioStream.Format = format; AudioStream.SampleRate = sampleRate; AudioStream.WriteCallback = WriteCallback; BufferReleased += callback; AudioStream.Open(); }
public static AudioFormat ToManagedFormat(SoundIOFormat format, int sampleRate, int channels) { if (format == SoundIODevice.S16NE) { return(new AudioFormat(sampleRate, channels, 16, true)); } else if (format == SoundIODevice.U16NE) { return(new AudioFormat(sampleRate, channels, 16, false)); } else if (format == SoundIODevice.S24NE) { return(new AudioFormat(sampleRate, channels, 24, true)); } else if (format == SoundIODevice.U24NE) { return(new AudioFormat(sampleRate, channels, 24, false)); } else if (format == SoundIODevice.Float32NE) { return(new AudioFormat(sampleRate, channels, 32, true)); } else { return(null); } }
public bool SupportsFormat(SoundIOFormat format) { return(Natives.soundio_device_supports_format(handle, (SoundIoFormat)format)); }
public static string GetSoundFormatName(SoundIOFormat format) { return(Marshal.PtrToStringAnsi(Natives.soundio_format_name((SoundIoFormat)format))); }
public static int GetBytesPerSecond(SoundIOFormat format, int channelCount, int sampleRate) { return(Natives.soundio_get_bytes_per_second((SoundIoFormat)format, channelCount, sampleRate)); }
public static int GetBytesPerFrame(SoundIOFormat format, int channelCount) { return(Natives.soundio_get_bytes_per_frame((SoundIoFormat)format, channelCount)); }
public static int GetBytesPerSample(SoundIOFormat format) { return(Natives.soundio_get_bytes_per_sample((SoundIoFormat)format)); }