Beispiel #1
0
        public List <Granule> GenerateGranules(CoverageData coverageData)
        {
            var granules = new List <Granule>();

            for (var i = 0; i < coverageData.Count; i++)
            {
                var insideList = new List <int>();
                var indexes    = new List <int>();

                for (var j = 0; j < coverageData[i].Count; j++)
                {
                    if (coverageData[i][j] == 1)
                    {
                        indexes.Add(j);
                    }
                }

                foreach (var checkRow in coverageData)
                {
                    var result = indexes.All(x => checkRow[x] == 1) ? 1 : 0;
                    insideList.Add(result);
                }

                var granule = new Granule(insideList, i + 1);
                granules.Add(granule);
            }

            return(granules);
        }
Beispiel #2
0
        private List <List <Granule> > _getBranches(Granule granule)
        {
            var branch = new List <Granule>(new[] { granule });
            var result = new List <List <Granule> >();

            if (granule.Children.Count == 0)
            {
                result.Add(branch);
                return(result);
            }

            foreach (var child in granule.Children)
            {
                var partBranches = _getBranches(child);

                foreach (var partBranch in partBranches)
                {
                    var fullBranch = new List <Granule>(branch);
                    fullBranch.AddRange(partBranch);
                    result.Add(fullBranch);
                }
            }

            return(result);
        }
Beispiel #3
0
    public static Granule[][] ReturnRectangularGranuleArray(int size1, int size2)
    {
        Granule[][] newArray = new Granule[size1][];
        for (int array1 = 0; array1 < size1; array1++)
        {
            newArray[array1] = new Granule[size2];
        }

        return(newArray);
    }
Beispiel #4
0
        public void Compare_WhenCompareWithSomeOtherGranule_ThenShouldReturnResult(Granule gran1, Granule gran2,
                                                                                   GranuleComparerResult expectedResult)
        {
            // Arrange

            // Act
            var result = (GranuleComparerResult)_comparer.Compare(gran1, gran2);

            // Assert
            Assert.Equal(expectedResult, result);
        }
Beispiel #5
0
        private int CalculateItemOrder(Granule granule)
        {
            var value = 0;

            for (var i = granule.Count() - 1; i >= 0; i--)
            {
                value += granule.Inside[i] * (int)Math.Pow(10, i);
            }

            return(value);
        }
Beispiel #6
0
        /// <summary>
        /// 获取单声道第一个粒度
        /// </summary>
        /// <returns></returns>
        private Granule GetGranuleSingle0()
        {
            Granule granule = new Granule();

            granule.part2_3_length[0] = (uint)(data[2] & 0x3F);
            granule.part2_3_length[0] = (uint)((granule.part2_3_length[0] << 6) + (data[3] >> 2));

            granule.big_values[0] = (ushort)(data[3] & 0x3);
            granule.big_values[0] = (ushort)((granule.big_values[0] << 7) + (data[4] >> 1));

            granule.global_gain[0] = (ushort)(data[4] & 0x01);
            granule.global_gain[0] = (ushort)((granule.global_gain[0] << 7) + (data[5] >> 1));

            granule.scale_fac_compress[0] = (byte)(data[5] & 0x01);
            granule.scale_fac_compress[0] = (byte)((granule.scale_fac_compress[0] << 3) + data[6] >> 5);

            granule.window_switching_flag[0] = (byte)((data[6] >> 4) & 0x01);
            //当上面这个为1时
            if (granule.window_switching_flag[0] == 1)
            {
                granule.block_type[0]       = (byte)((data[6] >> 2) & 0x03);
                granule.mixed_block_flag[0] = (byte)((data[6] >> 1) & 0x01);

                granule.table_select[0][0] = (uint)(data[6] & 0x01);
                granule.table_select[0][0] = (uint)((granule.table_select[0][0] << 4) + data[7] >> 4);

                granule.table_select[0][1] = (uint)(((data[7] & 0x0f) << 1) + (data[8] >> 7));

                granule.subblock_gain[0][0] = (uint)((data[8] >> 4) & 0x07);
                granule.subblock_gain[0][1] = (uint)((data[8] >> 1) & 0x07);
                granule.subblock_gain[0][2] = (uint)(((data[8] & 0x01) << 2) + (data[9] >> 6));
            }
            //当上面这个为1时
            else
            {
                granule.table_select[0][0] = (uint)(((data[6] & 0x0F) << 1) + (data[7] >> 7));
                granule.table_select[0][1] = (uint)((data[7] >> 2) & 0x1f);
                granule.table_select[0][2] = (uint)(((data[7] & 0x03) << 3) + (data[8] >> 5));

                granule.region0_count[0] = (byte)((data[8] >> 1) & 0x0f);

                granule.region1_count[0] = (byte)(data[8] & 0x01);
                granule.region1_count[0] = (byte)((granule.region1_count[0] << 2) + (data[9] >> 6));
            }

            granule.preflag[0]            = (byte)((data[9] >> 5) & 0x01);
            granule.scalefac_scale[0]     = (byte)((data[9] >> 4) & 0x01);
            granule.count1table_select[0] = (byte)((data[9] >> 3) & 0x01);

            return(granule);
        }
Beispiel #7
0
        /// <summary>
        /// 获取单声道第二个粒度
        /// </summary>
        /// <returns></returns>
        private Granule GetGranuleSingle1()
        {
            Granule granule = new Granule();

            granule.part2_3_length[0] = (uint)(data[9] & 0x07);
            granule.part2_3_length[0] = (uint)((granule.part2_3_length[0] << 8) + data[10]);
            granule.part2_3_length[0] = (uint)((granule.part2_3_length[0] << 1) + (data[11] >> 7));

            granule.big_values[0] = (ushort)(data[11] & 0x7f);
            granule.big_values[0] = (ushort)((granule.big_values[0] << 2) + (data[12] >> 6));

            granule.global_gain[0] = (ushort)(data[12] & 0x3f);
            granule.global_gain[0] = (ushort)((granule.global_gain[0] << 2) + (data[13] >> 6));

            granule.scale_fac_compress[0] = (byte)((data[13] >> 2) & 0x0f);

            granule.window_switching_flag[0] = (byte)((data[13] >> 1) & 0x01);
            //当上面这个为0时
            if (granule.window_switching_flag[0] == 1)
            {
                granule.block_type[0] = (byte)(((data[13] & 0x01) << 1) + (data[14] >> 7));

                granule.mixed_block_flag[0] = (byte)((data[14] >> 6) & 0x01);

                granule.table_select[0][0] = (uint)((data[14] >> 1) & 0x1f);

                granule.table_select[0][1] = (uint)(((data[14] & 0x01) << 4) + (data[15] >> 4));

                granule.subblock_gain[0][0] = (uint)((data[15] >> 1) & 0x07);
                granule.subblock_gain[0][1] = (uint)(((data[15] & 0x01) << 2) + (data[16] >> 6));
                granule.subblock_gain[0][2] = (uint)((data[16] >> 3) & 0x07);
            }
            //当上面这个为1时
            else
            {
                granule.table_select[0][0] = (uint)(((data[13] & 0x01) << 4) + (data[14] >> 4));
                granule.table_select[0][1] = (uint)(((data[14] & 0x0f) << 1) + (data[15] >> 7));
                granule.table_select[0][2] = (uint)((data[15] >> 2) & 0x1f);

                granule.region0_count[0] = (byte)(((data[15] & 0x03) << 2) + (data[16] >> 6));

                granule.region1_count[0] = (byte)((data[16] >> 3) & 0x07);
            }

            granule.preflag[0]            = (byte)((data[16] >> 2) & 0x01);
            granule.scalefac_scale[0]     = (byte)((data[16] >> 1) & 0x01);
            granule.count1table_select[0] = (byte)(data[16] & 0x01);

            return(granule);
        }
Beispiel #8
0
 public static GranuleViewModel ToGranule(Granule elem)
 {
     return(new GranuleViewModel
     {
         Id = elem.Id,
         DiagnosticTestId = elem.DiagnosticTestId,
         GranulePosition = elem.GranulePosition,
         LingvistUX = elem.LingvistUX,
         LingvistFT = elem.LingvistFT,
         FuzzyLabelName = elem.FuzzyLabel.FuzzyLabelName,
         FuzzyTrendName = elem.FuzzyTrend.TrendName.ToString(),
         Count = elem.Count
     });
 }
Beispiel #9
0
        private bool ChildrenAndParentCompare(Granule x, Granule y)
        {
            if (x.Children.Count != y.Children.Count || x.Parent.Count != y.Parent.Count)
            {
                return(false);
            }

            var xChildren = x.Children.OrderBy(CalculateItemOrder).ToList();
            var xParents  = x.Parent.OrderBy(CalculateItemOrder).ToList();
            var yChildren = y.Children.OrderBy(CalculateItemOrder).ToList();
            var yParents  = y.Parent.OrderBy(CalculateItemOrder).ToList();

            return(!xChildren.Where((t, j) => !t.SequenceEqual(yChildren[j])).Any() &&
                   !xParents.Where((t, j) => !t.SequenceEqual(yParents[j])).Any());
        }
Beispiel #10
0
        private bool CheckContainInParent(Granule granule, Granule searchGranule)
        {
            if (granule == searchGranule)
            {
                return(true);
            }

            foreach (var parent in granule.Parent)
            {
                if (CheckContainInParent(parent, searchGranule))
                {
                    return(true);
                }
            }

            return(false);
        }
Beispiel #11
0
        /// <summary>
        /// 获取双声道第二个声道的两个粒度信息
        /// </summary>
        /// <returns></returns>
        private Granule GetGranuleDouble1()
        {
            Granule granule = new Granule();

            //第一个粒度
            granule.part2_3_length[0] = (uint)(data[17] & 0x3f);
            granule.part2_3_length[0] = (uint)((granule.part2_3_length[0] << 6) + (data[18] >> 2));

            granule.big_values[0] = (ushort)(data[18] & 0x03);
            granule.big_values[0] = (ushort)((granule.big_values[0] << 7) + (data[19] >> 1));

            granule.global_gain[0] = (ushort)(data[19] & 0x01);
            granule.global_gain[0] = (ushort)((granule.global_gain[0] << 7) + (data[20] >> 1));

            granule.scale_fac_compress[0] = (byte)(data[20] & 0x01);
            granule.scale_fac_compress[0] = (byte)((granule.scale_fac_compress[0] << 3) + (data[21] >> 5));

            granule.window_switching_flag[0] = (byte)((data[21] >> 4) & 0x01);
            //当上面这个为0时
            if (granule.window_switching_flag[0] == 1)
            {
                granule.block_type[0] = (byte)((data[21] >> 2) & 0x03);

                granule.mixed_block_flag[0] = (byte)((data[21] >> 1) & 0x01);

                granule.table_select[0][0] = (uint)(data[21] & 0x01);
                granule.table_select[0][0] = (uint)((granule.table_select[0][0] << 4) + (data[22] >> 4));

                granule.table_select[0][1] = (uint)(((data[22] & 0x0f) << 1) + (data[23] >> 7));

                granule.subblock_gain[0][0] = (uint)((data[23] >> 4) & 0x07);
                granule.subblock_gain[0][1] = (uint)((data[23] >> 1) & 0x07);
                granule.subblock_gain[0][2] = (uint)(data[23] & 0x01);
                granule.subblock_gain[0][2] = (uint)((granule.subblock_gain[0][2] << 2) + (data[24] >> 6));
            }
            //当上面这个为1时
            else
            {
                granule.table_select[0][0] = (uint)(((data[21] & 0x0f) << 1) + (data[22] >> 7));
                granule.table_select[0][1] = (uint)((data[22] >> 2) & 0x1f);
                granule.table_select[0][2] = (uint)(data[22] & 0x03);
                granule.table_select[0][2] = (uint)((granule.table_select[0][2] << 3) + (data[23] >> 5));

                granule.region0_count[0] = (byte)((data[23] >> 1) & 0x0f);

                granule.region1_count[0] = (byte)(data[23] & 0x01);
                granule.region1_count[0] = (byte)((granule.region1_count[0] << 2) + (data[24] >> 6));
            }

            granule.preflag[0]            = (byte)((data[24] >> 5) & 0x01);
            granule.scalefac_scale[0]     = (byte)((data[24] >> 4) & 0x01);
            granule.count1table_select[0] = (byte)((data[24] >> 3) & 0x01);

            granule.slen1[0] = (byte)granule.slen[granule.scale_fac_compress[0]][0];
            granule.slen2[0] = (byte)granule.slen[granule.scale_fac_compress[0]][1];

            //第二个粒度
            granule.part2_3_length[1] = (uint)(data[24] & 0x07);
            granule.part2_3_length[1] = (uint)((granule.part2_3_length[1] << 8) + data[25]);
            granule.part2_3_length[1] = (uint)((granule.part2_3_length[1] << 1) + (data[26] >> 7));

            granule.big_values[1] = (ushort)(data[26] & 0x7f);
            granule.big_values[1] = (ushort)((granule.big_values[1] << 2) + (data[27] >> 6));

            granule.global_gain[1] = (ushort)(data[27] & 0x3f);
            granule.global_gain[1] = (ushort)((granule.global_gain[1] << 2) + (data[28] >> 6));

            granule.scale_fac_compress[1] = (byte)((data[28] >> 2) & 0x0f);

            granule.window_switching_flag[1] = (byte)((data[28] >> 1) & 0x01);
            //当上面这个为1时
            if (granule.window_switching_flag[1] == 1)
            {
                granule.block_type[1] = (byte)(((data[28] & 0x01) << 1) + (data[29] >> 7));

                granule.mixed_block_flag[1] = (byte)((data[29] >> 6) & 0x01);

                granule.table_select[1][0] = (uint)((data[29] >> 1) & 0x1f);

                granule.table_select[1][1] = (uint)(((data[29] & 0x01) << 4) + (data[30] >> 4));

                granule.subblock_gain[1][0] = (uint)((data[30] >> 1) & 0x07);
                granule.subblock_gain[1][1] = (uint)(((data[30] & 0x01) << 2) + (data[31] >> 6));
                granule.subblock_gain[1][2] = (uint)((data[31] >> 3) & 0x07);
            }
            //当上面这个为1时
            else
            {
                granule.table_select[1][0] = (uint)(((data[28] & 0x01) << 4) + (data[29] >> 4));
                granule.table_select[1][1] = (uint)(((data[29] & 0x0f) << 1) + (data[30] >> 7));
                granule.table_select[1][2] = (uint)((data[30] >> 2) & 0x1f);

                granule.region0_count[1] = (byte)(((data[30] & 0x03) << 2) + (data[31] >> 6));

                granule.region1_count[1] = (byte)((data[31] >> 3) & 0x07);
            }

            granule.preflag[1]            = (byte)((data[31] >> 2) & 0x01);
            granule.scalefac_scale[1]     = (byte)((data[31] >> 1) & 0x01);
            granule.count1table_select[1] = (byte)(data[31] & 0x01);

            granule.slen1[1] = (byte)granule.slen[granule.scale_fac_compress[1]][0];
            granule.slen2[1] = (byte)granule.slen[granule.scale_fac_compress[1]][1];

            return(granule);
        }