private unsafe PaBuffer PaBufferBySampleFormat(PaSampleFormat sampleFormat, void *pointer, int length, int channels)
        {
            switch (sampleFormat & ~PaSampleFormat.paCustomFormat)
            {
            case 0:
                return(null);

            case PaSampleFormat.paFloat32:
                return(new PaBuffer <float>(pointer, length, channels));

            case PaSampleFormat.paInt32:
                return(new PaBuffer <Int32>(pointer, length, channels));

            case PaSampleFormat.paInt16:
                return(new PaBuffer <Int16>(pointer, length, channels));

            case PaSampleFormat.paInt8:
                return(new PaBuffer <SByte>(pointer, length, channels));

            case PaSampleFormat.paUInt8:
                return(new PaBuffer <Byte>(pointer, length, channels));

            default:
                return(new PaBuffer(pointer));
            }
        }
 internal PaBlockingStream(
     IntPtr stream,
     PaSampleFormat inputSampleFormat, PaSampleFormat outputSampleFormat,
     int numInputChannels, int numOutputChannels) :
     base(stream, null, inputSampleFormat, outputSampleFormat, numInputChannels, numOutputChannels)
 {
 }
        public Error OpenDefaultOutputStream(int numOutputChannels, double sampleRate, uint sampleSize, out IBuffer buffer)
        {
            bps = (int)sampleSize;
            PaSampleFormat sampleFormat = bps switch
            {
                8 => PaSampleFormat.paInt8,
                16 => PaSampleFormat.paInt16,
                24 => PaSampleFormat.paInt24,
                32 => PaSampleFormat.paInt32,
                _ => PaSampleFormat.paCustomFormat
            };

            if (sampleFormat == PaSampleFormat.paCustomFormat)
            {
                buffer = null;
                return(Error.paSampleFormatNotSupported);
            }
            buffer = outBuffer = new Buffer.Buffer(256 * numOutputChannels * bps / 8);
            outBuffer.SetEndOfBuffer(new BufferState {
                AbsolutePosition = 256 * numOutputChannels * 20
            });
            streamCallback = StreamCallback;
            channel        = numOutputChannels;
            outBufferState.AbsolutePosition = 0;
            return(Pa_OpenDefaultStream(ref stream, 0, numOutputChannels, sampleFormat, sampleRate, 256, streamCallback, IntPtr.Zero));
        }
Пример #4
0
        public static int GetSampleSize(PaSampleFormat format)
        {
            var ret = PortAudioInterop.Pa_GetSampleSize(format);

            HandleError((PaErrorCode)ret);
            return(ret);
        }
Пример #5
0
 private static extern int Pa_OpenDefaultStream(ref IntPtr stream,
                                                int numInputChannels,
                                                int numOutputChannels,
                                                PaSampleFormat sampleFormat,
                                                double sampleRate,
                                                ulong framesPerBuffer,
                                                PaStreamCallback streamCallback,
                                                IntPtr userData);
Пример #6
0
 internal PaStream(
     IntPtr stream, StreamCallbackContainer streamCallbackContainer,
     PaSampleFormat inputSampleFormat, PaSampleFormat outputSampleFormat,
     int numInputChannels, int numOutputChannels)
 {
     this.stream = stream;
     this.streamCallbackContainer = streamCallbackContainer;
 }
        private unsafe PaBuffer PaBufferBySampleFormat(
            IntPtr pointer, PaSampleFormat sampleFormat,
            int channels, int frames)
        {
            if (channels == 0)
            {
                return(null);
            }
            if ((sampleFormat & PaSampleFormat.paNonInterleaved) == 0)
            {
                switch (sampleFormat)
                {
                case PaSampleFormat.paFloat32:
                    return(new PaBuffer <Single>(pointer, channels, frames));

                case PaSampleFormat.paInt32:
                    return(new PaBuffer <Int32>(pointer, channels, frames));

                case PaSampleFormat.paInt16:
                    return(new PaBuffer <Int16>(pointer, channels, frames));

                case PaSampleFormat.paInt8:
                    return(new PaBuffer <SByte>(pointer, channels, frames));

                case PaSampleFormat.paUInt8:
                    return(new PaBuffer <Byte>(pointer, channels, frames));

                default:
                    return(new PaBuffer(pointer, channels, frames));
                }
            }
            else
            {
                switch (sampleFormat & ~PaSampleFormat.paNonInterleaved)
                {
                case PaSampleFormat.paFloat32:
                    return(new PaNonInterleavedBuffer <Single>(pointer, channels, frames));

                case PaSampleFormat.paInt32:
                    return(new PaNonInterleavedBuffer <Int32>(pointer, channels, frames));

                case PaSampleFormat.paInt16:
                    return(new PaNonInterleavedBuffer <Int16>(pointer, channels, frames));

                case PaSampleFormat.paInt8:
                    return(new PaNonInterleavedBuffer <SByte>(pointer, channels, frames));

                case PaSampleFormat.paUInt8:
                    return(new PaNonInterleavedBuffer <Byte>(pointer, channels, frames));

                default:
                    return(new PaBuffer(pointer, channels, frames));
                }
            }
        }
 public StreamCallbackContainer(
     PaStreamCallback callbackProvider,
     PaSampleFormat inputSampleFormat, PaSampleFormat outputSampleFormat,
     int numInputChannels, int numOutputChannels, object userData)
 {
     this.callbackProvider   = callbackProvider;
     this.inputSampleFormat  = inputSampleFormat;
     this.outputSampleFormat = outputSampleFormat;
     this.numInputChannels   = numInputChannels;
     this.numOutputChannels  = numOutputChannels;
     this.userData           = userData;
 }
Пример #9
0
 public PortAudioStreamPlayer(IMediaBufferGenerator generator, AudioParameters parameters, PaSampleFormat sampleFormat, uint frames, object userData)
     : base(generator)
 {
     stream = new PortAudioOutputStream (
         parameters.Channels,
         sampleFormat,
         parameters.SamplesPerSecond,
         frames,
         StreamCallback,
         userData
     );
 }
Пример #10
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
     ));
 }
Пример #11
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
                     ));
 }
        private Type SampleFormatToType(PaSampleFormat sampleFormat)
        {
            if ((sampleFormat & PaSampleFormat.paNonInterleaved) == 0)
            {
                switch (sampleFormat)
                {
                case PaSampleFormat.paFloat32:
                    return(typeof(PaBuffer <Single>));

                case PaSampleFormat.paInt32:
                    return(typeof(PaBuffer <Int32>));

                case PaSampleFormat.paInt16:
                    return(typeof(PaBuffer <Int16>));

                case PaSampleFormat.paInt8:
                    return(typeof(PaBuffer <SByte>));

                case PaSampleFormat.paUInt8:
                    return(typeof(PaBuffer <Byte>));

                default:
                    return(typeof(PaBuffer));
                }
            }
            else
            {
                switch (sampleFormat & ~PaSampleFormat.paNonInterleaved)
                {
                case PaSampleFormat.paFloat32:
                    return(typeof(PaNonInterleavedBuffer <Single>));

                case PaSampleFormat.paInt32:
                    return(typeof(PaNonInterleavedBuffer <Int32>));

                case PaSampleFormat.paInt16:
                    return(typeof(PaNonInterleavedBuffer <Int16>));

                case PaSampleFormat.paInt8:
                    return(typeof(PaNonInterleavedBuffer <SByte>));

                case PaSampleFormat.paUInt8:
                    return(typeof(PaNonInterleavedBuffer <Byte>));

                default:
                    return(typeof(PaBuffer));
                }
            }
        }
Пример #13
0
        public PaBlockingStream OpenDefaultStream(
            int numInputChannels, int numOutputChannels, PaSampleFormat sampleFormat,
            double sampleRate, int framesPerBuffer, PaStreamFlags streamFlags)
        {
            IntPtr stream;

            unsafe
            {
                PaErrorException.ThrowIfError(Pa_OpenDefaultStream(
                                                  new IntPtr(&stream),
                                                  numInputChannels, numOutputChannels, sampleFormat,
                                                  sampleRate, (unsigned_long_t)framesPerBuffer, streamFlags,
                                                  null, IntPtr.Zero));
            }
            return(new PaBlockingStream(stream, sampleFormat, sampleFormat, numInputChannels, numOutputChannels));
        }
Пример #14
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 ();
     }
 }
Пример #15
0
        public PaStream OpenDefaultStream(
            int numInputChannels, int numOutputChannels, PaSampleFormat sampleFormat,
            double sampleRate, int framesPerBuffer, PaStreamFlags streamFlags,
            PaStreamCallback streamCallback, object userData)
        {
            var streamCallbackContainer = new StreamCallbackContainer(
                streamCallback,
                sampleFormat, sampleFormat,
                numInputChannels, numOutputChannels, userData);
            IntPtr stream;

            unsafe
            {
                PaErrorException.ThrowIfError(Pa_OpenDefaultStream(
                                                  new IntPtr(&stream),
                                                  numInputChannels, numOutputChannels, sampleFormat,
                                                  sampleRate, (unsigned_long_t)framesPerBuffer, streamFlags,
                                                  streamCallbackContainer.Callback, IntPtr.Zero));
            }
            return(new PaStream(stream, streamCallbackContainer));
        }
Пример #16
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();
                }
            }
        }
Пример #17
0
 public static extern pa_error_t Pa_GetSampleSize(PaSampleFormat format);
Пример #18
0
 public static extern pa_error_t Pa_OpenDefaultStream(
     IntPtr stream,
     int_t numInputChannels, int numOutputChannels, PaSampleFormat sampleFormat,
     double sampleRate, unsigned_long_t framesPerBuffer, PaStreamFlags streamFlags,
     _PaStreamCallback streamCallback, IntPtr userData);
Пример #19
0
 public pa_error_t GetSampleSize(PaSampleFormat format) => Pa_GetSampleSize(format);
 private static extern Error Pa_GetSampleSize(PaSampleFormat format);
Пример #21
0
 int     Pa_GetSampleSize([MarshalAs(UnmanagedType.SysUInt)] PaSampleFormat format)
 ;
Пример #22
0
 protected PortAudioStream(PaSampleFormat sampleFormat, int channels)
 {
     this.sample_format = sampleFormat;
     this.channels = channels;
 }
Пример #23
0
 protected PortAudioStream(PaSampleFormat sampleFormat, int channels)
 {
     this.sample_format = sampleFormat;
     this.channels      = channels;
 }
Пример #24
0
 public static extern PaError Pa_OpenDefaultStream(out IntPtr stream, int numInputChannels, int numOutputChannels, PaSampleFormat sampleFormat, double sampleRate, uint framesPerBuffer, PaStreamCallback streamCallback, IntPtr userData);
Пример #25
0
 public static extern PaError Pa_GetSampleSize(PaSampleFormat format);
Пример #26
0
 private static extern int Pa_GetSampleSize(PaSampleFormat format);
Пример #27
0
 public static extern PaError Pa_GetSampleSize(PaSampleFormat format);
Пример #28
0
 public static int GetSampleSize(PaSampleFormat format)
 {
     var ret = PortAudioInterop.Pa_GetSampleSize (format);
     HandleError ((PaErrorCode) ret);
     return ret;
 }