コード例 #1
0
        internal DssiDescriptor(LadspaLibraryContext library, uint index, IntPtr dataPtr)
        {
            DssiDescriptorStruct data = (DssiDescriptorStruct)Marshal.PtrToStructure(dataPtr, typeof(DssiDescriptorStruct));

            Library          = library;
            DataHandle       = dataPtr;
            LadspaDescriptor = new LadspaDescriptor(library, index, data.LadspaDescriptor);
            if (data.Configure != IntPtr.Zero)
            {
                Configure = (DssiDescriptorConfigureCallback)Marshal.GetDelegateForFunctionPointer(data.Configure, typeof(DssiDescriptorConfigureCallback));
            }
            if (data.GetProgram != IntPtr.Zero)
            {
                GetProgram = (DssiDescriptorGetProgramCallback)Marshal.GetDelegateForFunctionPointer(data.GetProgram, typeof(DssiDescriptorGetProgramCallback));
            }
            if (data.SelectProgram != IntPtr.Zero)
            {
                SelectProgram = (DssiDescriptorSelectProgramCallback)Marshal.GetDelegateForFunctionPointer(data.SelectProgram, typeof(DssiDescriptorSelectProgramCallback));
            }
            if (data.GetMidiControllerForPort != IntPtr.Zero)
            {
                GetMidiControllerForPort = (DssiDescriptorGetMidiControllerForPortCallback)Marshal.GetDelegateForFunctionPointer(data.GetMidiControllerForPort, typeof(DssiDescriptorGetMidiControllerForPortCallback));
            }
            if (data.RunSynth != IntPtr.Zero)
            {
                RunSynth = (DssiDescriptorRunSynthCallback)Marshal.GetDelegateForFunctionPointer(data.RunSynth, typeof(DssiDescriptorRunSynthCallback));
            }
            if (data.RunSynthAdding != IntPtr.Zero)
            {
                RunSynthAdding = (DssiDescriptorRunSynthCallback)Marshal.GetDelegateForFunctionPointer(data.RunSynthAdding, typeof(DssiDescriptorRunSynthCallback));
            }
            if (data.RunMultiSynth != IntPtr.Zero)
            {
                RunMultiSynth = (DssiDescriptorRunMultiSynthCallback)Marshal.GetDelegateForFunctionPointer(data.RunMultiSynth, typeof(DssiDescriptorRunMultiSynthCallback));
            }
            if (data.RunMultiSynthAdding != IntPtr.Zero)
            {
                RunMultiSynthAdding = (DssiDescriptorRunMultiSynthCallback)Marshal.GetDelegateForFunctionPointer(data.RunMultiSynthAdding, typeof(DssiDescriptorRunMultiSynthCallback));
            }
            IsSynth = data.RunSynth != null;
        }
コード例 #2
0
 public bool RunAdding(float[][] outputs)
 {
     if (handle != IntPtr.Zero)
     {
         if (DssiDescriptor.RunSynthAdding != null)
         {
             PrepareEvents();
             DssiDescriptor.RunSynthAdding(handle, (uint)bufferSize, eventBuffer, (uint)eventBufferCount);
             CopyOutputs(outputs);
             return(true);
         }
         else if (LadspaDescriptor.RunAdding != null)
         {
             LadspaDescriptor.RunAdding(handle, (uint)bufferSize);
             CopyOutputs(outputs);
             return(true);
         }
     }
     if (eventList.Count > 0)
     {
         eventList.Clear();
     }
     return(false);
 }
コード例 #3
0
        internal LadspaInstance(LadspaDescriptor descriptor, IntPtr handle, int sampleRate, int bufferSize)
        {
            if (bufferSize < 512)
            {
                bufferSize = 512;
            }
            LadspaDescriptor = descriptor;
            this.handle      = handle;
            this.bufferSize  = bufferSize;
            this.sampleRate  = sampleRate;
            int inputCount = 0, outputCount = 0;

            for (int i = 0; i < descriptor.Ports.Length; i++)
            {
                if (descriptor.Ports[i].PortType != LadspaPortType.Audio)
                {
                    continue;
                }
                LadspaPortDirection dir = descriptor.Ports[i].PortDirection;
                if (dir == LadspaPortDirection.Input)
                {
                    inputCount++;
                }
                else if (dir == LadspaPortDirection.Output)
                {
                    outputCount++;
                }
            }
            InputCount    = inputCount;
            OutputCount   = outputCount;
            dataOffsets   = new int[descriptor.Ports.Length];
            inputOffsets  = new int[inputCount];
            outputOffsets = new int[outputCount];
            paramBuffer   = new float[1];
            if (descriptor.ConnectPort != null)
            {
                int dataSize = 0, blockSize = (int)(bufferSize * 4);
                inputCount = 0; outputCount = 0;
                for (int i = 0; i < descriptor.Ports.Length; i++)
                {
                    dataOffsets[i] = dataSize;
                    if (descriptor.Ports[i].PortType != LadspaPortType.Audio)
                    {
                        dataSize += 4;
                    }
                    else
                    {
                        LadspaPortDirection dir = descriptor.Ports[i].PortDirection;
                        if (dir == LadspaPortDirection.Input)
                        {
                            inputOffsets[inputCount++] = dataSize;
                        }
                        else if (dir == LadspaPortDirection.Output)
                        {
                            outputOffsets[outputCount++] = dataSize;
                        }
                        dataSize += blockSize;
                    }
                }
                if (dataSize > 0)
                {
                    data = Marshal.AllocHGlobal(dataSize);
                    RtlZeroMemory(data, dataSize);
                    ResetParameters();
                    for (uint i = 0; i < descriptor.Ports.Length; i++)
                    {
                        descriptor.ConnectPort(handle, i, IntPtr.Add(data, dataOffsets[i]));
                    }
                }
            }
        }
コード例 #4
0
ファイル: LadspaPort.cs プロジェクト: xtremegaida/ladspa.net
        internal LadspaPort(LadspaDescriptor descriptor, int index,
                            LadspaPortDescriptorEnum type, LadspaPortRangeHintsEnum hints, string name,
                            float minBound, float maxBound)
        {
            Descriptor = descriptor;
            Index      = index;
            Type       = type;
            Name       = name;
            Hints      = hints;
            PortType   = type.HasFlag(LadspaPortDescriptorEnum.LADSPA_PORT_CONTROL) ? LadspaPortType.Control :
                         type.HasFlag(LadspaPortDescriptorEnum.LADSPA_PORT_AUDIO) ? LadspaPortType.Audio : LadspaPortType.Unknown;
            PortDirection = type.HasFlag(LadspaPortDescriptorEnum.LADSPA_PORT_INPUT) ? LadspaPortDirection.Input :
                            type.HasFlag(LadspaPortDescriptorEnum.LADSPA_PORT_OUTPUT) ? LadspaPortDirection.Output : LadspaPortDirection.Unknown;
            IsLogarithmic        = hints.HasFlag(LadspaPortRangeHintsEnum.LADSPA_HINT_LOGARITHMIC);
            IsInteger            = hints.HasFlag(LadspaPortRangeHintsEnum.LADSPA_HINT_INTEGER);
            IsSampleRateMultiple = hints.HasFlag(LadspaPortRangeHintsEnum.LADSPA_HINT_SAMPLE_RATE);
            IsToggled            = hints.HasFlag(LadspaPortRangeHintsEnum.LADSPA_HINT_TOGGLED);
            if (hints.HasFlag(LadspaPortRangeHintsEnum.LADSPA_HINT_BOUNDED_BELOW))
            {
                MinimumValue = minBound;
            }
            else
            {
                MinimumValue = 0;
            }
            if (hints.HasFlag(LadspaPortRangeHintsEnum.LADSPA_HINT_BOUNDED_ABOVE))
            {
                MaximumValue = maxBound;
            }
            else
            {
                MaximumValue = 1;
            }
            switch (hints & LadspaPortRangeHintsEnum.LADSPA_HINT_DEFAULT_MASK)
            {
            case LadspaPortRangeHintsEnum.LADSPA_HINT_DEFAULT_MINIMUM: DefaultValue = MinimumValue; break;

            case LadspaPortRangeHintsEnum.LADSPA_HINT_DEFAULT_LOW:
                DefaultValue = IsLogarithmic ? (float)Math.Exp((Math.Log(MinimumValue) * 3 + Math.Log(MaximumValue)) * 0.25) :
                               (MinimumValue * 3 + MaximumValue) * 0.25f;
                break;

            case LadspaPortRangeHintsEnum.LADSPA_HINT_DEFAULT_MIDDLE:
                DefaultValue = IsLogarithmic ? (float)Math.Exp((Math.Log(MinimumValue) + Math.Log(MaximumValue)) * 0.5) :
                               (MinimumValue + MaximumValue) * 0.5f;
                break;

            case LadspaPortRangeHintsEnum.LADSPA_HINT_DEFAULT_HIGH:
                DefaultValue = IsLogarithmic ? (float)Math.Exp((Math.Log(MinimumValue) + Math.Log(MaximumValue) * 3) * 0.25) :
                               (MinimumValue + MaximumValue * 3) * 0.25f;
                break;

            case LadspaPortRangeHintsEnum.LADSPA_HINT_DEFAULT_MAXIMUM: DefaultValue = MaximumValue; break;

            case LadspaPortRangeHintsEnum.LADSPA_HINT_DEFAULT_0: DefaultValue = 0; break;

            case LadspaPortRangeHintsEnum.LADSPA_HINT_DEFAULT_1: DefaultValue = 1; break;

            case LadspaPortRangeHintsEnum.LADSPA_HINT_DEFAULT_100: DefaultValue = 100; break;

            case LadspaPortRangeHintsEnum.LADSPA_HINT_DEFAULT_440: DefaultValue = 440; break;

            default: break;
            }
        }