Ejemplo n.º 1
0
        static string GetName(int devIndex)
        {
            PADeviceInfo  l_DeviceInfo  = PA.GetDeviceInfo(devIndex);
            PAHostApiInfo l_HostApiInfo = PA.GetHostApiInfo(l_DeviceInfo.HostApi);

            // by default use utf-8, but mme uses ansi
            switch (l_HostApiInfo.Type)
            {
            case PAHostApiTypeId.MME: return("PortAudio " + l_HostApiInfo.NameUtf8 + ": " + l_DeviceInfo.NameAnsi);
            }
            return("PortAudio " + l_HostApiInfo.NameUtf8 + ": " + l_DeviceInfo.NameUtf8);
        }
Ejemplo n.º 2
0
 /// <summary>Releases unmanaged and - optionally - managed resources.</summary>
 /// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
 protected override void Dispose(bool disposing)
 {
     m_Exit = true;
     if (m_StreamHandle != IntPtr.Zero)
     {
         PAErrorCode l_ErrorCode = PA.SafeNativeMethods.Pa_CloseStream(m_StreamHandle);
         if (l_ErrorCode != PAErrorCode.NoError)
         {
             Trace.WriteLine("Error Pa_CloseStream " + PA.GetErrorText(l_ErrorCode));
         }
         m_StreamHandle = IntPtr.Zero;
     }
     m_CallbackDelegate = null;
     m_StreamData       = null;
 }
Ejemplo n.º 3
0
        /// <summary>Stops playing.</summary>
        /// <exception cref="Exception">
        /// Already stopped!
        /// or.
        /// </exception>
        protected override void StopPlayback()
        {
            if (m_Exit)
            {
                throw new Exception("Already stopped!");
            }

            m_Exit = true;
            PAErrorCode l_ErrorCode = PA.SafeNativeMethods.Pa_StopStream(m_StreamHandle);

            if (l_ErrorCode != PAErrorCode.NoError)
            {
                throw new Exception(PA.GetErrorText(l_ErrorCode));
            }
        }
Ejemplo n.º 4
0
        /// <summary>Begins playing.</summary>
        /// <exception cref="Exception">
        /// Already started!
        /// or.
        /// </exception>
        protected override void StartPlayback()
        {
            if (!m_Exit)
            {
                throw new Exception("Already started!");
            }

            m_Exit = false;
            PAErrorCode errorCode = PA.SafeNativeMethods.Pa_StartStream(m_StreamHandle);

            if (errorCode != PAErrorCode.NoError)
            {
                throw new Exception(PA.GetErrorText(errorCode));
            }
        }
Ejemplo n.º 5
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));
            }
        }