Ejemplo n.º 1
0
 void m_CheckErrorCode(PAErrorCode errorCode)
 {
     if (errorCode != PAErrorCode.NoError)
     {
         throw new Exception("PortAudio: error " + errorCode.ToString());
     }
 }
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 void Dispose(bool disposing)
 {
     if (disposing)
     {
         PAErrorCode l_Error = PA.SafeNativeMethods.Pa_Terminate();
         m_CheckErrorCode(l_Error);
         m_Initialized = false;
     }
 }
Ejemplo n.º 3
0
 /// <summary>Initializes a new instance of the <see cref="PortAudio"/> class.</summary>
 public PortAudio()
 {
     try
     {
         PAErrorCode l_Error = PA.SafeNativeMethods.Pa_Initialize();
         m_Initialized = l_Error == PAErrorCode.NoError;
         m_CheckErrorCode(l_Error);
     }
     catch { }
 }
Ejemplo n.º 4
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.º 5
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.º 6
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.º 7
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));
            }
        }
Ejemplo n.º 8
0
 public static string GetErrorText(PAErrorCode errorCode)
 {
     return(Marshal.PtrToStringAnsi(SafeNativeMethods.Pa_GetErrorText(errorCode)));
 }
Ejemplo n.º 9
0
 public static extern IntPtr Pa_GetErrorText(PAErrorCode errorCode);