コード例 #1
0
        /// <summary>Initializes a new instance of the <see cref="PAOut"/> class.</summary>
        /// <param name="dev">The device to use.</param>
        /// <param name="configuration">The configuration to use.</param>
        /// <exception cref="NotSupportedException">
        /// </exception>
        /// <exception cref="Exception"></exception>
        internal PAOut(IAudioDevice dev, IAudioConfiguration configuration)
            : base(dev, configuration)
        {
            var l_OutputParameters = new PAStreamParameters();

            switch (configuration.ChannelSetup)
            {
            case AudioChannelSetup.Mono:
            case AudioChannelSetup.Stereo:
                l_OutputParameters.ChannelCount = configuration.Channels; break;

            default: throw new NotSupportedException(string.Format("Audio channel setup {0} not supported!", configuration.ChannelSetup));
            }
            switch (configuration.Format)
            {
            case AudioSampleFormat.Float: l_OutputParameters.SampleFormat = PASampleFormat.Float32; break;

            case AudioSampleFormat.Int8: l_OutputParameters.SampleFormat = PASampleFormat.Int8; break;

            case AudioSampleFormat.Int16: l_OutputParameters.SampleFormat = PASampleFormat.Int16; break;

            case AudioSampleFormat.Int24: l_OutputParameters.SampleFormat = PASampleFormat.Int24; break;

            case AudioSampleFormat.Int32: l_OutputParameters.SampleFormat = PASampleFormat.Int32; break;

            default: throw new NotSupportedException(string.Format("Audio format {0} not supported!", configuration.Format));
            }
            l_OutputParameters.Device = ((PADevice)dev).DeviceIndex;

            SamplesPerBuffer   = Math.Max(1, configuration.SamplingRate / PA.BuffersPerSecond);
            BufferSize         = configuration.BytesPerTick * SamplesPerBuffer;
            m_CallbackDelegate = new PA.StreamCallbackDelegate(Callback);
            PAErrorCode l_ErrorCode = PA.SafeNativeMethods.Pa_OpenStream(out m_StreamHandle, IntPtr.Zero, ref l_OutputParameters, configuration.SamplingRate, (uint)SamplesPerBuffer, PAStreamFlags.ClipOff, m_CallbackDelegate, IntPtr.Zero);

            if (l_ErrorCode != PAErrorCode.NoError)
            {
                throw new Exception(PA.GetErrorText(l_ErrorCode));
            }
        }
コード例 #2
0
ファイル: PA.cs プロジェクト: elfen20/cave-media
 public static extern PAErrorCode Pa_OpenStream(out IntPtr stream, ref PAStreamParameters inputParameters, IntPtr outputParameters, double sampleRate, uint framesPerBuffer, PAStreamFlags streamFlags, StreamCallbackDelegate streamCallback, IntPtr userData);
コード例 #3
0
ファイル: PA.cs プロジェクト: elfen20/cave-media
 public static extern PAErrorCode Pa_IsFormatSupported(ref PAStreamParameters inputParameters, ref PAStreamParameters outputParameters, double sampleRate);