예제 #1
0
        /* get information for a sample object.  returns False if not found. */
        public static bool WaveSampDictGetSampleInfo(
            WaveSampDictRec Dict,
            string Name,
            out float[] DataOut,
            out int NumFramesOut,
            out NumChannelsType NumChannelsOut,
            out int Loop1StartOut,
            out int Loop1EndOut,
            out int Loop2StartOut,
            out int Loop2EndOut,
            out int Loop3StartOut,
            out int Loop3EndOut,
            out int OriginOut,
            out double NaturalFreqOut,
            out int SamplingRateOut,
            out bool Loop1Bidirectional,
            out bool Loop2Bidirectional,
            out bool Loop3Bidirectional)
        {
            DataOut            = null;
            NumFramesOut       = 0;
            NumChannelsOut     = 0;
            Loop1StartOut      = 0;
            Loop1EndOut        = 0;
            Loop2StartOut      = 0;
            Loop2EndOut        = 0;
            Loop3StartOut      = 0;
            Loop3EndOut        = 0;
            OriginOut          = 0;
            NaturalFreqOut     = 0;
            SamplingRateOut    = 0;
            Loop1Bidirectional = false;
            Loop2Bidirectional = false;
            Loop3Bidirectional = false;

            SampleRec Sample;

            if (!Dict.Samples.TryGetValue(Name, out Sample))
            {
                return(false);
            }

            DataOut            = Sample.SampleDataReference;
            NumFramesOut       = Sample.NumFrames;
            NumChannelsOut     = Sample.NumChannels;
            Loop1StartOut      = Sample.Loop1Start;
            Loop1EndOut        = Sample.Loop1End;
            Loop2StartOut      = Sample.Loop2Start;
            Loop2EndOut        = Sample.Loop2End;
            Loop3StartOut      = Sample.Loop3Start;
            Loop3EndOut        = Sample.Loop3End;
            OriginOut          = Sample.Origin;
            NaturalFreqOut     = Sample.NaturalFreq;
            SamplingRateOut    = Sample.SamplingRate;
            Loop1Bidirectional = Sample.Loop1Bidirectional;
            Loop2Bidirectional = Sample.Loop2Bidirectional;
            Loop3Bidirectional = Sample.Loop3Bidirectional;

            return(true);
        }
예제 #2
0
        /* create a new multisampling object based on a list of samples */
        public static MultiSampleRec NewMultiSample(
            SampleSelectorRec Selector,
            WaveSampDictRec Dictionary)
        {
            MultiSampleRec MultiSample = new MultiSampleRec();

            int Count = GetSampleSelectorListLength(Selector);

            MultiSample.SampleInfoArray = new OneSampleRec[Count];

            /* fill in the entries */
            int Index = 0;

            for (int i = 0; i < Count; i += 1)
            {
                OneSampleRec Entry = MultiSample.SampleInfoArray[Index] = new OneSampleRec();

                /* fill in interval for which this sample is valid */
                Entry.MinFrequency = GetSampleListEntryLowFreqBound(Selector, i);
                Entry.MaxFrequency = GetSampleListEntryHighFreqBound(Selector, i);

                /* get name of sample for this interval */
                string SampleName = GetSampleListEntryName(Selector, i);
                /* see if we can get info about this one */
                if (!WaveSampDictGetSampleInfo(
                        Dictionary,
                        SampleName,
                        out Entry.SampleDataReference,
                        out Entry.NumFrames,
                        out Entry.NumChannels,
                        out Entry.Loop1Start,
                        out Entry.Loop1End,
                        out Entry.Loop2Start,
                        out Entry.Loop2End,
                        out Entry.Loop3Start,
                        out Entry.Loop3End,
                        out Entry.Origin,
                        out Entry.NaturalFreq,
                        out Entry.SamplingRate,
                        out Entry.Loop1Bidirectional,
                        out Entry.Loop2Bidirectional,
                        out Entry.Loop3Bidirectional))
                {
                    /* couldn't find that wave table, so just skip it */
                    continue;
                }

                /* this entry is valid */
                Index += 1;
            }

            if (Index < Count)
            {
                Array.Resize(ref MultiSample.SampleInfoArray, Index);
            }

            return(MultiSample);
        }
예제 #3
0
        /* create a new multisampling object based on a list of wave tables */
        public static MultiWaveTableRec NewMultiWaveTable(
            SampleSelectorRec Selector,
            WaveSampDictRec Dictionary)
        {
            MultiWaveTableRec MultiWaveTable = new MultiWaveTableRec();

            int Count = GetSampleSelectorListLength(Selector);

            MultiWaveTable.WaveTableInfoArray = new OneWaveTableRec[Count];

            int Index = 0;

            for (int i = 0; i < Count; i += 1)
            {
                OneWaveTableRec Entry = MultiWaveTable.WaveTableInfoArray[Index] = new OneWaveTableRec();

                /* get interval for which this one is valid */
                Entry.MinFrequency = GetSampleListEntryLowFreqBound(Selector, i);
                Entry.MaxFrequency = GetSampleListEntryHighFreqBound(Selector, i);

                /* get name of wave table for this interval */
                string WaveTableName = GetSampleListEntryName(Selector, i);
                /* see if we can get info about this one */
                if (!WaveSampDictGetWaveTableInfo(
                        Dictionary,
                        WaveTableName,
                        out Entry.WaveTableMatrix,
                        out Entry.FramesPerTable,
                        out Entry.NumberOfTables))
                {
                    /* couldn't find that wave table, so just skip it */
                    continue;
                }

                /* this entry is valid */
                Index += 1;
            }
            if (Index < Count)
            {
                Array.Resize(ref MultiWaveTable.WaveTableInfoArray, Index);
            }

            return(MultiWaveTable);
        }
예제 #4
0
        /* get information for a wave table object.  returns False if not found */
        public static bool WaveSampDictGetWaveTableInfo(
            WaveSampDictRec Dict,
            string Name,
            out float[][] TwoDimensionalVecOut,
            out int NumFramesOut,
            out int NumTablesOut)
        {
            TwoDimensionalVecOut = null;
            NumFramesOut         = 0;
            NumTablesOut         = 0;

            WaveTableRec WaveTable;

            if (!Dict.WaveTables.TryGetValue(Name, out WaveTable))
            {
                return(false);
            }

            TwoDimensionalVecOut = WaveTable.WaveVectorReference;
            NumFramesOut         = WaveTable.FramesPerTable;
            NumTablesOut         = WaveTable.NumTables;

            return(true);
        }
예제 #5
0
        /* create new wave table and sample dictionary */
        public static WaveSampDictRec NewWaveSampDictionary(
            IEnumerable <SampleObjectRec> SampleList,
            IEnumerable <AlgoSampObjectRec> AlgoSampList,
            IEnumerable <WaveTableObjectRec> WaveTableList,
            IEnumerable <AlgoWaveTableObjectRec> AlgoWaveTableList)
        {
            WaveSampDictRec Dict = new WaveSampDictRec();

            foreach (SampleObjectRec Sample in SampleList)
            {
                SampleRec NewNode = new SampleRec();

                NewNode.Name = Sample.Name;
                Dict.Samples.Add(NewNode.Name, NewNode);

                NewNode.SampleDataReference = Sample.SampleData.Buffer;
                NewNode.NumChannels         = Sample.SampleData.NumChannels;
                Debug.Assert(Sample.NumChannels == Sample.SampleData.NumChannels);
                NewNode.NumFrames = Sample.SampleData.NumFrames;
                Debug.Assert(Sample.NumFrames == Sample.SampleData.NumFrames);
                NewNode.Loop1Start         = Sample.LoopStart1;
                NewNode.Loop1End           = Sample.LoopEnd1;
                NewNode.Loop2Start         = Sample.LoopStart2;
                NewNode.Loop2End           = Sample.LoopEnd2;
                NewNode.Loop3Start         = Sample.LoopStart3;
                NewNode.Loop3End           = Sample.LoopEnd3;
                NewNode.Loop1Bidirectional = Sample.Loop1Bidirectional == LoopBidirectionalType.Yes;
                NewNode.Loop2Bidirectional = Sample.Loop2Bidirectional == LoopBidirectionalType.Yes;
                NewNode.Loop3Bidirectional = Sample.Loop3Bidirectional == LoopBidirectionalType.Yes;
                NewNode.Origin             = Sample.Origin;
                NewNode.NaturalFreq        = Sample.NaturalFrequency;
                NewNode.SamplingRate       = Sample.SamplingRate;
            }

            foreach (AlgoSampObjectRec AlgoSamp in AlgoSampList)
            {
                SampleRec NewNode = new SampleRec();

                NewNode.Name = AlgoSamp.Name;
                Dict.Samples.Add(NewNode.Name, NewNode);

                NewNode.SampleDataReference = AlgoSamp.SampleData.Buffer;
                NewNode.NumChannels         = AlgoSamp.NumChannels;
                Debug.Assert(AlgoSamp.NumChannels == AlgoSamp.SampleData.NumChannels);
                NewNode.NumFrames          = AlgoSamp.SampleData.NumFrames;
                NewNode.Loop1Start         = AlgoSamp.LoopStart1;
                NewNode.Loop1End           = AlgoSamp.LoopEnd1;
                NewNode.Loop2Start         = AlgoSamp.LoopStart2;
                NewNode.Loop2End           = AlgoSamp.LoopEnd2;
                NewNode.Loop3Start         = AlgoSamp.LoopStart3;
                NewNode.Loop3End           = AlgoSamp.LoopEnd3;
                NewNode.Loop1Bidirectional = AlgoSamp.Loop1Bidirectional == LoopBidirectionalType.Yes;
                NewNode.Loop2Bidirectional = AlgoSamp.Loop2Bidirectional == LoopBidirectionalType.Yes;
                NewNode.Loop3Bidirectional = AlgoSamp.Loop3Bidirectional == LoopBidirectionalType.Yes;
                NewNode.Origin             = AlgoSamp.Origin;
                NewNode.NaturalFreq        = AlgoSamp.NaturalFrequency;
                NewNode.SamplingRate       = AlgoSamp.SamplingRate;
            }

            foreach (WaveTableObjectRec WaveTable in WaveTableList)
            {
                WaveTableRec NewNode = new WaveTableRec();

                NewNode.Name = WaveTable.Name;
                Dict.WaveTables.Add(NewNode.Name, NewNode);

                NewNode.NumTables      = WaveTable.NumTables;
                NewNode.FramesPerTable = WaveTable.NumFrames;

                NewNode.WaveVectorReference = new float[NewNode.FramesPerTable][];
                for (int i = 0; i < NewNode.NumTables; i++)
                {
                    NewNode.WaveVectorReference[i] = WaveTable.WaveTableData.ListOfTables[i].frames;
                    Debug.Assert(NewNode.WaveVectorReference[i].Length == NewNode.FramesPerTable + 1);
                }
            }

            foreach (AlgoWaveTableObjectRec AlgoWaveTable in AlgoWaveTableList)
            {
                WaveTableRec NewNode = new WaveTableRec();

                NewNode.Name = AlgoWaveTable.Name;
                Dict.WaveTables.Add(NewNode.Name, NewNode);

                NewNode.NumTables      = AlgoWaveTable.NumTables;
                NewNode.FramesPerTable = AlgoWaveTable.NumFrames;

                NewNode.WaveVectorReference = new float[NewNode.FramesPerTable][];
                for (int i = 0; i < NewNode.NumTables; i++)
                {
                    NewNode.WaveVectorReference[i] = AlgoWaveTable.WaveTableData.ListOfTables[i].frames;
                    Debug.Assert(NewNode.WaveVectorReference[i].Length == NewNode.FramesPerTable + 1);
                }
            }
            return(Dict);
        }
예제 #6
0
 /* find out if named sample exists.  returns True if it does */
 public static bool WaveSampDictDoesSampleExist(
     WaveSampDictRec Dict,
     string Name)
 {
     return(Dict.Samples.ContainsKey(Name));
 }