コード例 #1
0
ファイル: SoundIoAudioTrack.cs プロジェクト: zpoo32/Ryujinx
        /// <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();
        }
コード例 #2
0
ファイル: Soundio.cs プロジェクト: SKKbySSK/Ws281x.Visualizer
 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);
     }
 }
コード例 #3
0
 public bool SupportsFormat(SoundIOFormat format)
 {
     return(Natives.soundio_device_supports_format(handle, (SoundIoFormat)format));
 }
コード例 #4
0
 public static string GetSoundFormatName(SoundIOFormat format)
 {
     return(Marshal.PtrToStringAnsi(Natives.soundio_format_name((SoundIoFormat)format)));
 }
コード例 #5
0
 public static int GetBytesPerSecond(SoundIOFormat format, int channelCount, int sampleRate)
 {
     return(Natives.soundio_get_bytes_per_second((SoundIoFormat)format, channelCount, sampleRate));
 }
コード例 #6
0
 public static int GetBytesPerFrame(SoundIOFormat format, int channelCount)
 {
     return(Natives.soundio_get_bytes_per_frame((SoundIoFormat)format, channelCount));
 }
コード例 #7
0
 public static int GetBytesPerSample(SoundIOFormat format)
 {
     return(Natives.soundio_get_bytes_per_sample((SoundIoFormat)format));
 }