Esempio n. 1
0
 public override void Init()
 {
     base.Init();
     writeIndex = 0;
     Buffering = 0;
     waveInDispose();
     waveIn = new WaveIn()
     {
         DeviceNumber = master.form.SoundList.SelectedIndex,
     };
     waveIn.DataAvailable += WaveIn_DataAvailable;
     waveIn.BufferMilliseconds = 14;
     waveIn.WaveFormat = new WaveFormat(rate, 16, 2);
     waveIn.StartRecording();
     Buffer_Low = CreateFilterBuffer();
     Buffer_Mid = CreateFilterBuffer();
     Buffer_High = CreateFilterBuffer();
     Param_Low = CreateFilterParam(FilterType.LowPass, 800, 3f);
     Param_Mid = CreateFilterParam(FilterType.BandPass, 2000, 0.1f);
     Param_High = CreateFilterParam(FilterType.HighPass, 8000, 2f);
 }
Esempio n. 2
0
 private float BiquadFilter(FilterParam param, ref FilterBuffer buffer, float input)
 {
     float result = (param.b[0] / param.a[0]) * input
                     + (param.b[1] / param.a[0]) * buffer.input[0]
                     + (param.b[2] / param.a[0]) * buffer.input[1]
                     - (param.a[1] / param.a[0]) * buffer.output[0]
                     - (param.a[2] / param.a[0]) * buffer.output[1];
     if (float.IsNaN(result))
     {
         result = 0;
     }
     if(float.IsInfinity(result))
     {
         result = 0;
     }
     buffer.input[1] = buffer.input[0];
     buffer.input[0] = input;
     buffer.output[1] = buffer.output[0];
     buffer.output[0] = result;
     return result;
 }
 public void Add(string key, FilterParam filter)
 {
     _params[key] = filter;
 }
        public bool ApplyFilter(Maid maid, string slotName, Material mat, string propName, FilterParam filter)
        {
            var tex2d = mat.GetTexture(propName) as Texture2D;

            if (tex2d == null || string.IsNullOrEmpty(tex2d.name))
            {
                return(false);
            }

            var key     = CreateKey(MaidHelper.GetGuid(maid), slotName, mat.name, tex2d.name);
            var filter2 = new FilterParam(filter);

            _filterParams.Add(key.ToString(), filter2);

            FilterTexture(tex2d, filter2);
            return(true);
        }
        private void FilterTexture(
            Dictionary <string, List <Material> > slotMaterials,
            List <Texture2D> textures, Maid maid, string slotName, int materialIndex, string propName
            )
        {
            Material  material = null;
            Texture2D texture  = null;

            {
                List <Material> materials;
                if (slotMaterials.TryGetValue(slotName, out materials) && materials != null)
                {
                    material = materials.ElementAtOrDefault(materialIndex);
                    if (material != null)
                    {
                        texture = material.GetTexture(propName) as Texture2D;
                    }
                }
            }
            if (material == null || texture == null)
            {
                return;
            }

            FilterParam filterParam = Get(maid, slotName, material, propName);

            if (!filterParam.Dirty.Value)
            {
                return;
            }

            originalTextureCache.SetDirty(texture);
            filterParam.ClearDirtyFlag();

            float outputBase  = filterParam.OutputMin * 0.01f;
            float outputScale = (filterParam.OutputMax - filterParam.OutputMin) * 0.01f;

            float inputExp   = Mathf.Log(filterParam.InputMid * 0.01f) / Mathf.Log(0.5f);
            float inputBase  = (-filterParam.InputMin / (filterParam.InputMax - filterParam.InputMin));
            float inputScale = 1f / ((filterParam.InputMax - filterParam.InputMin) * 0.01f);

            float hue        = filterParam.Hue / 360f;
            float saturation = filterParam.Saturation / 100f;
            float lightness  = filterParam.Lightness / 100f;

            Filter(texture, originalTextureCache.GetOriginalTexture(texture), (color) =>
            {
                Color c = color;

                c.r = Mathf.Clamp01(c.r * inputScale + inputBase);
                c.g = Mathf.Clamp01(c.g * inputScale + inputBase);
                c.b = Mathf.Clamp01(c.b * inputScale + inputBase);

                c.r = Mathf.Pow(c.r, inputExp);
                c.g = Mathf.Pow(c.g, inputExp);
                c.b = Mathf.Pow(c.b, inputExp);

                Vector4 hsl = ColorUtil.ColorToHsl(c);
                hsl.x       = (hsl.x + hue) % 1f;
                hsl.y      *= saturation;
                hsl.z      *= lightness;
                c           = ColorUtil.HslToColor(hsl);

                c.r = c.r * outputScale + outputBase;
                c.g = c.g * outputScale + outputBase;
                c.b = c.b * outputScale + outputBase;

                return(c);
            });
        }
Esempio n. 6
0
        ///// <summary>
        ///// 区域下所有的学校
        ///// </summary>
        ///// <param name="regionId"></param>
        ///// <returns></returns>
        //private Task<List<TagVOItem>> RegionSchool(int regionId) => this._reader.GetRepositoryAsync<CourseEntity>()
        //        .Queryable(c => c.RegionCode == regionId)
        //        .Select(t => new TagVOItem
        //        {
        //            Id = t.SchoolCode,
        //            Name = t.SchoolName

        //        })
        //        .Distinct()
        //        .ToListAsync();



        public async Task <IList <TagVO> > QueryFilterAsync(FilterParam param)
        {
            Expression <Func <TagsEntity, bool> > filter = t => true;

            //if (_pm.IsRegionAuditor)
            //{
            //    filter = filter.And(t => t.RegtionId == regionId);
            //}
            //else if (_pm.IsSchoolAuditor)
            //{
            //    filter = filter.And(t => t.SchoolId == schoolId);
            //}
            //else
            //{
            //    filter = filter.And(t => t.Creator == userId);
            //}


            IQueryable <string> courseId = null;


            //如果是管理员审核
            if (param.QueryType == ConstData.Filter_CourseAudit)
            {
                if (this._pm.IsSchoolAuditor)
                {
                    var sc = await this._appUser.GetSchool();

                    filter = filter.And(t => t.SchoolId == sc.Code);
                }
                if (this._pm.IsRegionAuditor)
                {
                    var re = await this._appUser.GetRegion();

                    filter = filter.And(t => t.RegtionId == re.Code);
                }

                Expression <Func <CourseEntity, bool> > courseFilter = _ => true;

                courseFilter = await QueryTools.FilterByPermissionAsync(courseFilter, _appUser, _pm);

                courseId = this._reader.GetRepositoryAsync <CourseEntity>()
                           .Queryable(courseFilter)
                           .Select(c => c.ID);
            }


            //个人
            if (param.QueryType is ConstData.Filter_CourseQuery)
            {
                if (this._appUser.IsLogin is false)
                {
                    throw new CPPermissionException("无权限、请登录");
                }

                var collabratorQuery = this._reader.GetRepositoryAsync <CollabratorEntity>()
                                       .Queryable(c => c.ObjId == this._appUser.UserId)
                                       .Select(c => c.CourseId);

                filter = filter.And(t => t.Creator == this._appUser.UserId || collabratorQuery.Contains(t.CourseId));
            }


            var query = this._reader.GetRepositoryAsync <TagsEntity>().Queryable(filter);


            //如果是全部,未登录只显示上架的产品,反之显示上架和通过的
            if (param.QueryType is ConstData.Filter_All)
            {
                Expression <Func <CourseEntity, bool> > subFilter = _ => true;

                var(re, sc) = await this._appUser.GetReScCodeAsync();

                subFilter = QueryTools.QueryByAuthor(subFilter, this._appUser.IsLogin, param.OrgType, param.OrgId, re, sc);

                var subQuery = this._reader.GetRepositoryAsync <CourseEntity>()
                               .Queryable(subFilter)
                               .Select(c => c.ID);



                query = query.Join(subQuery, t => t.CourseId, c => c, (t, c) => t);
            }



            //学习
            if (param.QueryType is ConstData.Filter_Learning)
            {
                if (this._appUser.IsLogin is false)
                {
                    throw new CPPermissionException("无权限、请登录");
                }

                // 加入学习的课程...
                var subQuery = this._reader.GetRepositoryAsync <PlatformUserJoinedCourseEntity>()
                               .Queryable(t => t.UserId == this._appUser.UserId)
                               .Select(p => p.CourseId)
                               .Distinct();

                query = query.Join(subQuery, t => t.CourseId, p => p, (t, p) => t);
            }


            //审核过滤
            if (courseId is not null)
            {
                query = query.Join(courseId, t => t.CourseId, c => c, (t, c) => t);
            }

            //if (param.QueryType is ConstData.Filter_CourseQuery)
            //{
            //   var collabratorQuery = this._reader.GetRepositoryAsync<CollabratorEntity>()
            //                            .Queryable(c => c.ObjId == this._appUser.UserId)
            //                            .Select(c => c.CourseId);

            //    query = query.Join(collabratorQuery, t => t.CourseId, c => c, (t, c) => t);
            //}


            var items = await query
                        .GroupBy(t => new { t.Name, /*t.CategoryId, */ t.TypeName })
                        .Select(t => new TagsEntity
            {
                Name     = t.Key.Name,
                TypeName = t.Key.TypeName,
                //CategoryId = t.Key.CategoryId
            }).ToListAsync();


            //第一层
            var rev = await this.InitAsync(param.OrgId);

            if (items.NoData())
            {
                return(await CheckReturnAsync(rev));  //rev?.Where(r => r.Items is not null and { Count: > 0 }).ToList();
            }


            //根据第一层属性,添加相应标签
            foreach (var item in items)
            {
                if (item.TypeName is null or {
                    Length: <= 0
                })
 public Task<IEnumerable<Review>> Post([FromBody]FilterParam filter,
     [FromUri(BinderType = typeof(TypeConverterModelBinder))] int? page,
     [FromUri(BinderType = typeof(TypeConverterModelBinder))] int? pagesize)
 {
     return _reviewRepository.GetReviewsAsync(page??1, pagesize??1000, filter?.ToDbFilter<Review>());
 }
 public void Add(string key, FilterParam filter) {
     params_[key] = filter;
 }
 public FilterParam(FilterParam filter) {
     Dirty      = new DirtyFlag();
     Hue        = new DirtyValue(Dirty, HueRange,    filter.Hue.Value);
     Saturation = new DirtyValue(Dirty, SaturRange,  filter.Saturation.Value);
     Lightness  = new DirtyValue(Dirty, LightRange,  filter.Lightness.Value);
     InputMin   = new DirtyValue(Dirty, InpMinRange, filter.InputMin.Value);
     InputMax   = new DirtyValue(Dirty, InpMaxRange, filter.InputMax.Value);
     InputMid   = new DirtyValue(Dirty, InpMidRange, filter.InputMid.Value);
     OutputMin  = new DirtyValue(Dirty, OutMinRange, filter.OutputMin.Value);
     OutputMax  = new DirtyValue(Dirty, OutMaxRange, filter.OutputMax.Value);
 }
 public Texture2D ApplyFilter(Texture2D srcTex, FilterParam filter) 
 {
     var dstTex = UnityEngine.Object.Instantiate(srcTex) as Texture2D;
     FilterTexture(dstTex, srcTex, filter);
     return dstTex;
 }
        public void FilterTexture(Texture2D dstTex, Texture2D srcTex, FilterParam filterParam) 
        {
            float outputBase = filterParam.OutputMin * 0.01f;
            float outputScale = (filterParam.OutputMax - filterParam.OutputMin) * 0.01f;

            float inputDelta = filterParam.InputMax - filterParam.InputMin;
            if (inputDelta < 0.001f) inputDelta = 0.01f; // ゼロ除算を避けるため
            float mid = filterParam.InputMid;
            if (mid < 0.001f) mid = 0.01f;               // NegativeInfinityを避けるため
            float inputExp = Mathf.Log(mid * 0.01f) / Mathf.Log(0.5f);
            float inputBase = (-filterParam.InputMin / (inputDelta));
            float inputScale = 1f / (inputDelta * 0.01f);

            float hue        = filterParam.Hue / 360f;
            float saturation = filterParam.Saturation / 100f;
            float lightness  = filterParam.Lightness / 100f;

            Filter(dstTex, srcTex, (color) =>
                   {
                       Color c = color;

                       c.r = Mathf.Clamp01(c.r * inputScale + inputBase);
                       c.g = Mathf.Clamp01(c.g * inputScale + inputBase);
                       c.b = Mathf.Clamp01(c.b * inputScale + inputBase);

                       if (!NumberUtil.Equals(inputExp, 1f)) {
                           c.r = Mathf.Pow(c.r, inputExp);
                           c.g = Mathf.Pow(c.g, inputExp);
                           c.b = Mathf.Pow(c.b, inputExp);
                       }

                       Vector4 hsl = ColorUtil.RGBToHsl(c);
                       hsl.x = (hsl.x + hue) % 1f;
                       hsl.y *= saturation;
                       hsl.z *= lightness;
                       c = ColorUtil.HslToRGB(hsl);

                       c.r = c.r * outputScale + outputBase;
                       c.g = c.g * outputScale + outputBase;
                       c.b = c.b * outputScale + outputBase;
                       return c;
                });
        }
        // キャッシュにテクスチャソースを保持する
        private void FilterTexture(Texture2D texture, FilterParam filter)
        {
            TextureHolder orgTex = originalTexCache.GetOrAdd(texture);
            orgTex.dirty  = false;
            filter.ClearDirtyFlag();

            FilterTexture(texture, orgTex.texture, filter);
        }
        public bool ApplyFilter(Maid maid, string slotName, Material mat, string propName, FilterParam filter) {
            var tex2d = mat.GetTexture(propName) as Texture2D;
            if (tex2d == null || string.IsNullOrEmpty(tex2d.name)) return false;

            var key = CreateKey(maid.Param.status.guid, slotName, mat.name, tex2d.name);
            var filter2 = new FilterParam(filter);
            filterParams.Add(key.ToString(), filter2);

            FilterTexture(tex2d, filter2);
            return true;
        }
        public bool DuplicateFilter(Maid maid, string slotName, Material mat, string fromPropName, string toPropName) {
            var srcTex2d = mat.GetTexture(fromPropName) as Texture2D;
            if (srcTex2d == null || string.IsNullOrEmpty(srcTex2d.name)) return false;

            FilterParam srcFilter = GetFilter(maid, slotName, mat.name, srcTex2d.name);
            
            var dstTex2d = mat.GetTexture(toPropName) as Texture2D;
            if (dstTex2d == null || string.IsNullOrEmpty(dstTex2d.name)) return false;

            var key = CreateKey(maid.Param.status.guid, slotName, mat.name, dstTex2d.name);
            var dstFilter = new FilterParam(srcFilter);
            filterParams.Add(key.ToString(), dstFilter);

            FilterTexture(dstTex2d, dstFilter);
            return true;
        }
Esempio n. 15
0
 private float[] BiquadLowPassFilter(FilterParam param, float[] Source)
 {
     float[] result = new float[Source.Length];
     float in1 = 0, in2 = 0, out1 = 0, out2 = 0;
     for (int i = 0; i < Source.Length - 1; i++)
     {
         result[i] = (param.b[0] / param.a[0]) * Source[i]
                     + (param.b[1] / param.a[0]) * in1
                     + (param.b[2] / param.a[0]) * in2
                     - (param.a[1] / param.a[0]) * out1
                     - (param.a[2] / param.a[0]) * out2;
         in2 = in1;
         in1 = Source[i];
         out2 = out1;
         out1 = result[i];
     }
     return result;
 }
 public FilterParam GetOrAdd(string key)
 {
     FilterParam p;
     if (params_.TryGetValue(key, out p))
     {
         return p;
     }
     p = new FilterParam();
     params_[key] = p;
     return p;
 }
Esempio n. 17
0
 private FilterParam CreateFilterParam(FilterType type, float freq, float Q)
 {
     FilterParam result = new FilterParam();
     result.a = new float[3];
     result.b = new float[3];
     float omega = 2.0f * (float)Math.PI * freq / Q;
     float alpha = (float)Math.Sin(omega) / Q;
     float cosOmega = (float)Math.Cos(omega);
     switch (type)
     {
         case FilterType.LowPass:
             result.b[1] = 1.0f - cosOmega;
             result.b[0] = result.b[1] / 2.0f;
             result.b[2] = result.b[0];
             result.a[0] = 1.0f + alpha;
             result.a[1] = -2.0f * cosOmega;
             result.a[2] = 1.0f - alpha;
             break;
         case FilterType.BandPass:
             result.b[0] = Q * alpha;
             result.b[1] = 0;
             result.b[2] = -1.0f * result.b[0];
             result.a[0] = 1.0f + alpha;
             result.a[1] = -2.0f * cosOmega;
             result.a[2] = 1.0f - alpha;
             break;
         case FilterType.HighPass:
             result.b[1] = 1.0f + cosOmega;
             result.b[0] = result.b[1] / 2.0f;
             result.b[1] *= -1.0f;
             result.b[2] = result.b[0];
             result.a[0] = 1.0f + alpha;
             result.a[1] = -2.0f * cosOmega;
             result.a[2] = 1.0f - alpha;
             break;
     }
     return result;
 }
Esempio n. 18
0
 public static Image <Gray, byte> FilterImage(Image <Bgr, byte> imgSrc, FilterParam filter)
 {
     return(imgSrc.InRange(filter.GetMinus(), filter.GetMaxi()));
 }
 void ThreadWork(object _param)
 {
     FilterParam param = (FilterParam)_param;
     //filter(param.data, param.data_size, param.fs, param.pitch, param.formant);
 }
Esempio n. 20
0
        private static Expression GetLambda <T>(this FilterParam filterParam, Type type, ParameterExpression param)
        {
            PropertyInfo prop = type.GetProperty(filterParam.Field);

            if (prop == null)
            {
                return(null);
            }
            var propType = param.Type.GetRuntimeProperty(prop.Name).PropertyType;

            filterParam.Value = filterParam.Value.ChangeType_ByConvert(propType);


            Expression lambda = null;
            Expression left   = Expression.Property(param, typeof(T).GetProperty(prop.Name));
            Expression right  = propType.IsGenericType && propType.GetGenericTypeDefinition() == typeof(Nullable <>) ? (Expression)Expression.Convert(Expression.Constant(filterParam.Value), propType) : Expression.Constant(filterParam.Value);

            switch (filterParam.Compare)
            {
            case CompareType.IN:
                lambda = Expression.Call(left, typeof(string).GetMethod("Contains"), right);
                break;

            case CompareType.BIN:
                lambda = Expression.Call(right, typeof(string).GetMethod("Contains"), left);
                break;

            case CompareType.SIN:
                break;

            case CompareType.NSIN:
                break;

            case CompareType.EQ:
                lambda = Expression.Equal(left, right);
                break;

            case CompareType.NE:
                lambda = Expression.NotEqual(left, right);
                break;

            case CompareType.LE:
                lambda = Expression.LessThanOrEqual(left, right);
                break;

            case CompareType.LT:
                lambda = Expression.LessThan(left, right);
                break;

            case CompareType.GE:
                lambda = Expression.GreaterThanOrEqual(left, right);
                break;

            case CompareType.GT:
                lambda = Expression.GreaterThan(left, right);
                break;

            default:
                lambda = Expression.Equal(left, right);
                break;
            }
            Expression left1 = Expression.Constant(1);

            return(lambda);
        }