Ejemplo n.º 1
0
 public void SetStreamFinishedCallback(StreamFinishedCallback streamFinishedCallback)
 {
     HandleError(PortAudioInterop.Pa_SetStreamFinishedCallback(
                     handle,
                     userData => streamFinishedCallback(userData)
                     ));
 }
Ejemplo n.º 2
0
        public static int GetSampleSize(PaSampleFormat format)
        {
            var ret = PortAudioInterop.Pa_GetSampleSize(format);

            HandleError((PaErrorCode)ret);
            return(ret);
        }
Ejemplo n.º 3
0
        internal static void ThrowLastError()
        {
            var ret = PortAudioInterop.Pa_GetLastHostErrorInfo();
            var ei  = Factory.Create <PaHostErrorInfo> (new CppInstancePtr(ret));

            if (ei.errorCode < 0)
            {
                throw new PortAudioException(ei);
            }
        }
Ejemplo n.º 4
0
 // "The function doesn't return until the entire buffer has been filled - this may involve waiting for the operating system to supply the data." (!)
 public void Write(byte[] buffer, int offset, uint frames)
 {
     unsafe {
         fixed(byte *buf = buffer)
         HandleError(PortAudioInterop.Pa_WriteStream(
                         handle,
                         (IntPtr)(buf + offset),
                         frames
                         ));
     }
 }
Ejemplo n.º 5
0
 public void Close()
 {
     if (handle != IntPtr.Zero)
     {
         if (should_dispose_handle)
         {
             HandleError(PortAudioInterop.Pa_CloseStream(handle));
         }
         handle = IntPtr.Zero;
     }
 }
Ejemplo n.º 6
0
        public static PaDeviceInfo GetDeviceInfo(int deviceIndex)
        {
            var ptr = PortAudioInterop.Pa_GetDeviceInfo(deviceIndex);

            if (ptr == IntPtr.Zero)
            {
                ThrowLastError();
            }
            using (var cppptr = new CppInstancePtr(ptr))
                return(Factory.Create <PaDeviceInfo> (cppptr));
        }
Ejemplo n.º 7
0
        public static PaHostApiInfo GetHostApiInfo(int hostApi)
        {
            var ptr = PortAudioInterop.Pa_GetHostApiInfo(hostApi);

            if (ptr == IntPtr.Zero)
            {
                ThrowLastError();
            }
            using (var cppptr = new CppInstancePtr(ptr))
                return(Factory.Create <PaHostApiInfo> (cppptr));
        }
Ejemplo n.º 8
0
 public PortAudioInputStream(int numInputChannels, PaSampleFormat sampleFormat, double sampleRate, uint framesPerBuffer, StreamCallback streamCallback, IntPtr userData)
     : base(sampleFormat, numInputChannels)
 {
     HandleError(PortAudioInterop.Pa_OpenDefaultStream(
                     out handle,
                     numInputChannels,
                     0,
                     (IntPtr)sampleFormat,
                     sampleRate,
                     (IntPtr)framesPerBuffer,
                     ToPaStreamCallback(streamCallback, false),
                     userData
                     ));
 }
Ejemplo n.º 9
0
 public PortAudioInputStream(PaStreamParameters inputParameters, double sampleRate, uint framesPerBuffer, PaStreamFlags streamFlags, StreamCallback streamCallback, IntPtr userData)
     : base(inputParameters.sampleFormat, inputParameters.channelCount)
 {
     using (var input = Factory.ToNative <PaStreamParameters> (inputParameters))
         HandleError(PortAudioInterop.Pa_OpenStream(
                         out handle,
                         input.Native,
                         IntPtr.Zero,
                         sampleRate,
                         framesPerBuffer,
                         streamFlags,
                         ToPaStreamCallback(streamCallback, false),
                         userData
                         ));
 }
Ejemplo n.º 10
0
        public PortAudioOutputStream(int numOutputChannels, PaSampleFormat sampleFormat, double sampleRate, uint framesPerBuffer, StreamCallback streamCallback, object userData)
            : base(sampleFormat, numOutputChannels)
        {
            var gch = userData == null ? default(GCHandle) : GCHandle.Alloc(userData, GCHandleType.Pinned);

            try {
                HandleError(PortAudioInterop.Pa_OpenDefaultStream(
                                out handle,
                                0,
                                numOutputChannels,
                                (IntPtr)sampleFormat,
                                sampleRate,
                                (IntPtr)framesPerBuffer,
                                ToPaStreamCallback(streamCallback, true),
                                userData != null ? gch.AddrOfPinnedObject() : IntPtr.Zero));
            } finally {
                if (userData != null)
                {
                    gch.Free();
                }
            }
        }
Ejemplo n.º 11
0
        public PortAudioOutputStream(PaStreamParameters outputParameters, double sampleRate, uint framesPerBuffer, PaStreamFlags streamFlags, StreamCallback streamCallback, object userData)
            : base(outputParameters.sampleFormat, outputParameters.channelCount)
        {
            var gch = userData == null ? default(GCHandle) : GCHandle.Alloc(userData, GCHandleType.Pinned);

            try {
                using (var output = Factory.ToNative <PaStreamParameters> (outputParameters))
                    HandleError(PortAudioInterop.Pa_OpenStream(
                                    out handle,
                                    IntPtr.Zero,
                                    output.Native,
                                    sampleRate,
                                    framesPerBuffer,
                                    streamFlags,
                                    ToPaStreamCallback(streamCallback, true),
                                    userData != null ? gch.AddrOfPinnedObject() : IntPtr.Zero));
            } finally {
                if (userData != null)
                {
                    gch.Free();
                }
            }
        }
Ejemplo n.º 12
0
 public static PaErrorCode CheckIfFormatSupported(PaStreamParameters inputParameters, PaStreamParameters outputParameters, double sampleRate)
 {
     using (var input = Factory.ToNative <PaStreamParameters> (inputParameters))
         using (var output = Factory.ToNative <PaStreamParameters> (outputParameters))
             return(PortAudioInterop.Pa_IsFormatSupported(input.Native, output.Native, sampleRate));
 }
Ejemplo n.º 13
0
 public static PaHostErrorInfo GetLastHostErrorInfo()
 {
     using (var cppptr = new CppInstancePtr(PortAudioInterop.Pa_GetLastHostErrorInfo()))
         return(Factory.Create <PaHostErrorInfo> (cppptr));
 }
Ejemplo n.º 14
0
 public static int HostApiDeviceIndexToDeviceIndex(int hostApi, int hostApiDeviceIndex)
 {
     return(PortAudioInterop.Pa_HostApiDeviceIndexToDeviceIndex(hostApi, hostApiDeviceIndex));
 }
Ejemplo n.º 15
0
 public static int HostApiTypeIdToHostApiIndex(PaHostApiTypeId type)
 {
     return(PortAudioInterop.Pa_HostApiTypeIdToHostApiIndex(type));
 }
Ejemplo n.º 16
0
 public static string GetErrorText(PaErrorCode errorCode)
 {
     return(Marshal.PtrToStringAuto(PortAudioInterop.Pa_GetErrorText(errorCode)));
 }
Ejemplo n.º 17
0
 public void StopStream()
 {
     HandleError(PortAudioInterop.Pa_StopStream(handle));
 }
Ejemplo n.º 18
0
 public void AbortStream()
 {
     HandleError(PortAudioInterop.Pa_AbortStream(handle));
 }