예제 #1
0
        public Stream(Guid DeviceId, Audio.Stream.SampleHandler Callback, Channel[] Input, Channel[] Output)
            : base(Input, Output)
        {
            Log.Global.WriteLine(MessageType.Info, "Instantiating ASIO stream with {0} input channels and {1} output channels.", Input.Length, Output.Length);
            asio = new AsioObject(DeviceId);
            asio.Init(IntPtr.Zero);
            callback = Callback;

            // Just use the driver's preferred buffer size.
            bufferSize = asio.BufferSize.Preferred;

            ASIOBufferInfo[] infos = new ASIOBufferInfo[Input.Length + Output.Length];
            for (int i = 0; i < Input.Length; ++i)
            {
                infos[i].isInput    = ASIOBool.True;
                infos[i].channelNum = Input[i].Index;
            }
            for (int i = 0; i < Output.Length; ++i)
            {
                infos[Input.Length + i].isInput    = ASIOBool.False;
                infos[Input.Length + i].channelNum = Output[i].Index;
            }

            ASIOCallbacks callbacks = new ASIOCallbacks()
            {
                bufferSwitch         = OnBufferSwitch,
                sampleRateDidChange  = OnSampleRateChange,
                asioMessage          = OnAsioMessage,
                bufferSwitchTimeInfo = OnBufferSwitchTimeInfo
            };

            asio.CreateBuffers(infos, bufferSize, callbacks);

            // Create input buffers.
            input        = new BufferInfo[Input.Length];
            inputBuffers = new Audio.SampleBuffer[Input.Length];
            for (int i = 0; i < Input.Length; ++i)
            {
                input[i]        = new BufferInfo(infos[i], Input[i].Type);
                inputBuffers[i] = new Audio.SampleBuffer(bufferSize);
            }

            // Create output buffers.
            output        = new BufferInfo[Output.Length];
            outputBuffers = new Audio.SampleBuffer[Output.Length];
            for (int i = 0; i < Output.Length; ++i)
            {
                output[i]        = new BufferInfo(infos[Input.Length + i], Output[i].Type);
                outputBuffers[i] = new Audio.SampleBuffer(bufferSize);
            }

            sampleRate = asio.SampleRate;

            asio.Start();
        }
예제 #2
0
        public Stream(Guid DeviceId, Audio.Stream.SampleHandler Callback, Channel[] Input, Channel[] Output)
            : base(Input, Output)
        {
            Log.Global.WriteLine(MessageType.Info, "Instantiating ASIO stream with {0} input channels and {1} output channels.", Input.Length, Output.Length);
            asio = new AsioObject(DeviceId);
            asio.Init(IntPtr.Zero);
            callback = Callback;

            buffer = asio.BufferSize.Preferred;
            ASIOBufferInfo[] infos = new ASIOBufferInfo[Input.Length + Output.Length];
            for (int i = 0; i < Input.Length; ++i)
            {
                infos[i].isInput = ASIOBool.True;
                infos[i].channelNum = Input[i].Index;
            }
            for (int i = 0; i < Output.Length; ++i)
            {
                infos[Input.Length + i].isInput = ASIOBool.False;
                infos[Input.Length + i].channelNum = Output[i].Index;
            }

            ASIOCallbacks callbacks = new ASIOCallbacks()
            {
                bufferSwitch = OnBufferSwitch,
                sampleRateDidChange = OnSampleRateChange,
                asioMessage = OnAsioMessage,
                bufferSwitchTimeInfo = OnBufferSwitchTimeInfo
            };
            asio.CreateBuffers(infos, buffer, callbacks);

            input = new Buffer[Input.Length];
            for (int i = 0; i < Input.Length; ++i)
                input[i] = new Buffer(infos[i], Input[i].Type, buffer);
            output = new Buffer[Output.Length];
            for (int i = 0; i < Output.Length; ++i)
                output[i] = new Buffer(infos[Input.Length + i], Output[i].Type, buffer);

            sampleRate = asio.SampleRate;
            asio.Start();
        }
예제 #3
0
 public Buffer(ASIOBufferInfo Info, ASIOSampleType Type, int Count)
 {
     info    = Info;
     type    = Type;
     samples = new Audio.SampleBuffer(Count);
 }
예제 #4
0
파일: Asio.cs 프로젝트: alexbv16/LiveSPICE
        public void CreateBuffers(ASIOBufferInfo[] Infos, int Size, ASIOCallbacks Callbacks)
        {
            pins = new GCHandle[]
            {
                GCHandle.Alloc(Callbacks.bufferSwitch),
                GCHandle.Alloc(Callbacks.sampleRateDidChange),
                GCHandle.Alloc(Callbacks.asioMessage),
                GCHandle.Alloc(Callbacks.bufferSwitchTimeInfo)
            };
            callbacks = Marshal.AllocHGlobal(Marshal.SizeOf(Callbacks));

            Marshal.StructureToPtr(Callbacks, callbacks, false);
            Log.Global.WriteLine(MessageType.Info, "AsioObject.CreateBuffers(Size={0})", Size);
            Try(vtbl.createBuffers(_this, Infos, Infos.Length, Size, callbacks));
        }
예제 #5
0
 public BufferInfo(ASIOBufferInfo Info, ASIOSampleType Type)
 {
     info = Info;
     type = Type;
 }
예제 #6
0
 public Buffer(ASIOBufferInfo Info, ASIOSampleType Type, int Count)
 {
     info = Info;
     type = Type;
     samples = new Audio.SampleBuffer(Count);
 }