예제 #1
0
        public void RawSet(string Name, string Value, SafeRawDelegate SafeRawMethod, EncodeDelegate EncodeMethod, DecodeDelegate DecodeMethod)
        {
            if (Name.Trim().Length == 0)
            {
                return;
            }
            string SafeName  = SafeRawMethod(Name);
            string SafeValue = SafeRawMethod(Value);
            string Key       = MatchAndGetKey(SafeName, EncodeMethod, DecodeMethod);

            if (Key == null)
            {
                ParameterStore[SafeName] = new List <string>()
                {
                    SafeValue
                }
            }
            ;
            else
            {
                ParameterStore[Key] = new List <string>()
                {
                    SafeValue
                }
            };
        }
예제 #2
0
        // https://github.com/xiph/opus/issues/42 w
        public VoiceClient(SampleRate sampleRate     = SampleRate._48k,
                           Bitrate bitRate           = Bitrate._192k,
                           Channels channels         = Channels.Two,
                           FrameDelay frameDelay     = FrameDelay.Delay20,
                           BitDepthEnum bitDepthEnum = BitDepthEnum.Float32)
        {
            this.frameDelay = (int)frameDelay;
            this.sampleRate = (int)sampleRate;
            this.bitRate    = (int)bitRate;
            this.channels   = (int)channels;
            this.bitDepth   = (int)bitDepthEnum;

            this.Encoder = new LibOpusEncoder(this.sampleRate, this.channels, this.bitRate, this.frameDelay);

            Encode = bitDepthEnum switch
            {
                BitDepthEnum.Float32 => Encoder.EncodeFloat,
                BitDepthEnum.UInt16 => Encoder.Encode,
                _ => throw new NotSupportedException(nameof(BitDepth))
            };

            if (bitDepthEnum == BitDepthEnum.Float32)
            {
                Encode = Encoder.EncodeFloat;
            }
            else
            {
                Encode = Encoder.Encode;
            }

            _arrayPool = ArrayPool <byte> .Shared;
        }
예제 #3
0
 string MatchAndGetKey(string Name, EncodeDelegate EncodeMethod, DecodeDelegate DecodeMethod)
 {
     foreach (string Key in ParameterStore.Keys)
     {
         if (Key.Equals(Name))
         {
             return(Key);
         }
     }
     foreach (string Key in ParameterStore.Keys)
     {
         if (DecodeMethod(Key).Equals(DecodeMethod(Name)))
         {
             return(Key);
         }
     }
     foreach (string Key in ParameterStore.Keys)
     {
         if (Key.Equals(DecodeMethod(Name)))
         {
             return(Key);
         }
     }
     foreach (string Key in ParameterStore.Keys)
     {
         if (DecodeMethod(Key).Equals(Name))
         {
             return(Key);
         }
     }
     return(null);
 }
예제 #4
0
 public ManualCodec(IEmittingCodec emittingCodec) : base(typeof(T), emittingCodec)
 {
     calculateSizeDelegate = (CalculateSizeDelegate)CalculateSizeMethod.CreateDelegate(typeof(CalculateSizeDelegate));
     encodeDelegate        = (EncodeDelegate)EncodeMethod.CreateDelegate(typeof(EncodeDelegate));
     decodeDelegate        = (DecodeDelegate)DecodeMethod.CreateDelegate(typeof(DecodeDelegate));
     decodeFastDelegate    = (DecodeDelegate)DecodeFastMethod.CreateDelegate(typeof(DecodeDelegate));
 }
예제 #5
0
파일: Encoder.cs 프로젝트: belzecue/Tools
 public StdEncoder Add(string tag, EncodeDelegate cody)
 {
     if (cody != null)
     {
         Add(tag, cody());
     }
     return(this);
 }
예제 #6
0
 public ManualCodec(ICodecContainer codecContainer, IEmittingCodec emittingCodec) : base(typeof(T), emittingCodec)
 {
     this.codecContainer   = codecContainer;
     calculateSizeDelegate = (CalculateSizeDelegate)CalculateSizeMethod.CreateDelegate(typeof(CalculateSizeDelegate));
     encodeDelegate        = (EncodeDelegate)EncodeMethod.CreateDelegate(typeof(EncodeDelegate));
     decodeDelegate        = (DecodeDelegate)DecodeMethod.CreateDelegate(typeof(DecodeDelegate));
     decodeFastDelegate    = (DecodeDelegate)DecodeFastMethod.CreateDelegate(typeof(DecodeDelegate));
 }
예제 #7
0
        public void RawRemove(string Name, SafeRawDelegate SafeRawMethod, EncodeDelegate EncodeMethod, DecodeDelegate DecodeMethod)
        {
            string SafeName = SafeRawMethod(Name);
            string Key      = MatchAndGetKey(SafeName, EncodeMethod, DecodeMethod);

            if (Key != null)
            {
                ParameterStore.Remove(Key);
            }
        }
예제 #8
0
 private Encoder(
     GetCharEncodeLengthDelegate GetCharEncodeLength,
     GetEncodeLengthDelegate GetEncodeLength,
     EncodeCharDelegate EncodeChar,
     EncodeDelegate Encode)
 {
     this.GetCharEncodeLength = GetCharEncodeLength;
     this.GetEncodeLength     = GetEncodeLength;
     this.EncodeChar          = EncodeChar;
     this.Encode = Encode;
 }
예제 #9
0
        public bool RawHas(string Name, SafeRawDelegate SafeRawMethod, EncodeDelegate EncodeMethod, DecodeDelegate DecodeMethod)
        {
            string SafeName = SafeRawMethod(Name);
            string Key      = MatchAndGetKey(SafeName, EncodeMethod, DecodeMethod);

            if (Key == null)
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }
예제 #10
0
        public List <string> RawGetAll(string Name, SafeRawDelegate SafeRawMethod, EncodeDelegate EncodeMethod, DecodeDelegate DecodeMethod)
        {
            string SafeName = SafeRawMethod(Name);
            string Key      = MatchAndGetKey(Name, EncodeMethod, DecodeMethod);

            if (Key == null)
            {
                throw new Exception("Parameter not found");
            }
            else
            {
                return(new List <string>(ParameterStore[Key]));
            }
        }
예제 #11
0
        public string RawGet(string Name, SafeRawDelegate SafeRawMethod, EncodeDelegate EncodeMethod, DecodeDelegate DecodeMethod)
        {
            string SafeName = SafeRawMethod(Name);
            string Key      = MatchAndGetKey(SafeName, EncodeMethod, DecodeMethod);

            if (Key == null)
            {
                throw new Exception("Parameter not found");
            }
            else
            {
                List <string> Values = ParameterStore[Key];
                return(Values[0]);
            }
        }
예제 #12
0
        private static EncodeDelegate[] MakeListOnEncode()
        {
            var listOnEncode = new EncodeDelegate[values.Length];

            listOnEncode[O.AtomicNumber]         = (atom, container) => atom.AtomicNumber;
            listOnEncode[O.MassNumber]           = (atom, container) => atom.MassNumber ?? 32451179;
            listOnEncode[O.FormalCharge]         = (atom, container) => atom.FormalCharge ?? 32451193;
            listOnEncode[O.NConnectedAtoms]      = (atom, container) => container.GetConnectedBonds(atom).Count();
            listOnEncode[O.BondOrderSum]         = (atom, container) => container.GetBondOrderSum(atom).GetHashCode(); // Fixed CDK's bug?? HashCode() removed.
            listOnEncode[O.OrbitalHybridization] = (atom, container) =>
            {
                var hybridization = atom.Hybridization;
                return(!hybridization.IsUnset() ? (int)hybridization : 32451301);
            };
            listOnEncode[O.FreeRadicals] = (atom, container) => container.GetConnectedSingleElectrons(atom).Count();
            return(listOnEncode);
        }
예제 #13
0
파일: HcpRuntime.cs 프로젝트: adamarvid/hcp
        protected override void OnLoad()
        {
            _load              = GetMethod <LoadDelegate>("hcp_Load", true);
            _unload            = GetMethod <UnloadDelegate>("hcp_Unload", false);
            _toValue           = GetMethod <ToValueDelegate>("hcp_tovalue", false);
            _getArgumentHandle = GetMethod <GetArgumentHandleDelegate>("hcp_argat", false);
            _getMessage        = GetMethod <GetMessageDelegate>("hcp_GetMessage", false);
            _encode            = GetMethod <EncodeDelegate>("hcp_Encode", false);
            _decode            = GetMethod <DecodeDelegate>("hcp_Decode", false);
            _newCodec          = GetMethod <NewCodecDelegate>("hcp_NewCodec", false);
            _closeCodec        = GetMethod <CloseCodecDelegate>("hcp_CloseCodec", false);
            _loadCodec         = GetMethod <LoadCodecDelegate>("hcp_LoadCodec", false);
            _loadModel         = GetMethod <LoadModelDelegate>("hcp_LoadModel", false);

            try {
                _state = _load();
            } catch (Exception x) {
                throw new Exception("Error occured while calling 'hcp_Load': " + x.Message);
            }
        }
예제 #14
0
        public void GetDelegates()
        {
            DspToolInfo dll = DllInfo[DllType];

            IntPtr pDecode            = Native.GetProcAddress(_pDll, "decode");
            IntPtr pEncode            = Native.GetProcAddress(_pDll, "encode");
            IntPtr pDspCorrelateCoefs = _pDll + dll.CorrelateCoefsAddress;
            IntPtr pDspEncodeFrame    = _pDll + dll.EncodeFrameAddress;

            if (DllType == DspToolType.OpenSource)
            {
                pDspCorrelateCoefs = Native.GetProcAddress(_pDll, "correlateCoefs");
                pDspEncodeFrame    = Native.GetProcAddress(_pDll, "encodeFrame");
            }

            Decode = Marshal.GetDelegateForFunctionPointer <DecodeDelegate>(pDecode);
            Encode = Marshal.GetDelegateForFunctionPointer <EncodeDelegate>(pEncode);
            DspCorrelateCoefsDll = Marshal.GetDelegateForFunctionPointer <DspCorrelateCoefsDelegate>(pDspCorrelateCoefs);
            DspEncodeFrameDll    = Marshal.GetDelegateForFunctionPointer <DspEncodeFrameDelegate>(pDspEncodeFrame);
        }
예제 #15
0
        public void RawAdd(string Name, string Value, SafeRawDelegate SafeRawMethod, EncodeDelegate EncodeMethod, DecodeDelegate DecodeMethod)
        {
            if (Name.Trim().Length == 0)
            {
                return;
            }
            string SafeName  = SafeRawMethod(Name);
            string SafeValue = SafeRawMethod(Value);
            string Key       = MatchAndGetKey(SafeName, EncodeMethod, DecodeMethod);

            if (Key == null)
            {
                List <string> Values = new List <string>();
                Values.Add(SafeValue);
                ParameterStore.Add(SafeName, Values);
            }
            else
            {
                ParameterStore[Key].Add(SafeValue);
            }
        }
예제 #16
0
 public CfgEncoder Add(string tag, EncodeDelegate cody) => cody == null ? this : Add(tag, cody());
예제 #17
0
 public string RawGet(string Name, SafeRawDelegate SafeRawMethod, EncodeDelegate EncodeMethod, DecodeDelegate DecodeMethod)
 {
     string SafeName = SafeRawMethod(Name);
     string Key = MatchAndGetKey(SafeName, EncodeMethod, DecodeMethod);
     if (Key == null)
     {
         throw new Exception("Parameter not found");
     }
     else
     {
         List<string> Values = ParameterStore[Key];
         return Values[0];
     }
 }
예제 #18
0
 public void RawSet(string Name, List<string> Values, SafeRawDelegate SafeRawMethod, EncodeDelegate EncodeMethod, DecodeDelegate DecodeMethod)
 {
     if (Name.Trim().Length == 0) return;
     string SafeName = SafeRawMethod(Name);
     List<string> SafeValues = new List<string>();
     foreach (string Value in Values)
     {
         SafeValues.Add(SafeRawMethod(Value));
     }
     string Key = MatchAndGetKey(SafeName, EncodeMethod, DecodeMethod);
     if (Key == null)
     {
         ParameterStore.Add(SafeName, SafeValues);
     }
     else
     {
         ParameterStore[Key] = SafeValues;
     }
 }
예제 #19
0
 string MatchAndGetKey(string Name, EncodeDelegate EncodeMethod, DecodeDelegate DecodeMethod)
 {
     foreach(string Key in ParameterStore.Keys)
     {
         if(Key.Equals(Name)) return Key;
     }
     foreach(string Key in ParameterStore.Keys)
     {
         if(DecodeMethod(Key).Equals(DecodeMethod(Name))) return Key;
     }
     foreach(string Key in ParameterStore.Keys)
     {
         if(Key.Equals(DecodeMethod(Name))) return Key;
     }
     foreach(string Key in ParameterStore.Keys)
     {
         if(DecodeMethod(Key).Equals(Name)) return Key;
     }
     return null;
 }
예제 #20
0
 public void RawSet(string Name, string Value, SafeRawDelegate SafeRawMethod, EncodeDelegate EncodeMethod, DecodeDelegate DecodeMethod)
 {
     if (Name.Trim().Length == 0) return;
     string SafeName = SafeRawMethod(Name);
     string SafeValue = SafeRawMethod(Value);
     string Key = MatchAndGetKey(SafeName, EncodeMethod, DecodeMethod);
     if(Key == null)
         ParameterStore[SafeName] = new List<string>() { SafeValue };
     else
         ParameterStore[Key] = new List<string>() { SafeValue };
 }
예제 #21
0
 public void RawSet(string Name, int Position, string Value, SafeRawDelegate SafeRawMethod, EncodeDelegate EncodeMethod, DecodeDelegate DecodeMethod)
 {
     if (Name.Trim().Length == 0) return;
     string SafeName = SafeRawMethod(Name);
     string SafeValue = SafeRawMethod(Value);
     if (Position < 0) return;
     string Key = MatchAndGetKey(SafeName, EncodeMethod, DecodeMethod);
     if (Key == null)
     {
         ParameterStore[SafeName] = new List<string>() { SafeValue };
     }
     else
     {
         if (Position >= ParameterStore[Key].Count)
         {
             this.Add(Key, SafeValue);
         }
         else
         {
             ParameterStore[Key][Position] = SafeValue;
         }
     }
 }
예제 #22
0
 public bool RawHas(string Name, SafeRawDelegate SafeRawMethod, EncodeDelegate EncodeMethod, DecodeDelegate DecodeMethod)
 {
     string SafeName = SafeRawMethod(Name);
     string Key = MatchAndGetKey(SafeName, EncodeMethod, DecodeMethod);
     if (Key == null)
     {
         return false;
     }
     else
     {
         return true;
     }
 }
예제 #23
0
 public void RawRemove(string Name, SafeRawDelegate SafeRawMethod, EncodeDelegate EncodeMethod, DecodeDelegate DecodeMethod)
 {
     string SafeName = SafeRawMethod(Name);
     string Key = MatchAndGetKey(SafeName, EncodeMethod, DecodeMethod);
     if (Key != null)
     {
         ParameterStore.Remove(Key);
     }
 }
예제 #24
0
 public List<string> RawGetAll(string Name, SafeRawDelegate SafeRawMethod, EncodeDelegate EncodeMethod, DecodeDelegate DecodeMethod)
 {
     string SafeName = SafeRawMethod(Name);
     string Key = MatchAndGetKey(Name, EncodeMethod, DecodeMethod);
     if (Key == null)
     {
         throw new Exception("Parameter not found");
     }
     else
     {
         return new List<string>(ParameterStore[Key]);
     }
 }
예제 #25
0
        public void RawSet(string Name, List <string> Values, SafeRawDelegate SafeRawMethod, EncodeDelegate EncodeMethod, DecodeDelegate DecodeMethod)
        {
            if (Name.Trim().Length == 0)
            {
                return;
            }
            string        SafeName   = SafeRawMethod(Name);
            List <string> SafeValues = new List <string>();

            foreach (string Value in Values)
            {
                SafeValues.Add(SafeRawMethod(Value));
            }
            string Key = MatchAndGetKey(SafeName, EncodeMethod, DecodeMethod);

            if (Key == null)
            {
                ParameterStore.Add(SafeName, SafeValues);
            }
            else
            {
                ParameterStore[Key] = SafeValues;
            }
        }
예제 #26
0
 public void RawAdd(string Name, string Value, SafeRawDelegate SafeRawMethod, EncodeDelegate EncodeMethod, DecodeDelegate DecodeMethod)
 {
     if (Name.Trim().Length == 0) return;
     string SafeName = SafeRawMethod(Name);
     string SafeValue = SafeRawMethod(Value);
     string Key = MatchAndGetKey(SafeName, EncodeMethod, DecodeMethod);
     if (Key == null)
     {
         List<string> Values = new List<string>();
         Values.Add(SafeValue);
         ParameterStore.Add(SafeName, Values);
     }
     else
     {
         ParameterStore[Key].Add(SafeValue);
     }
 }
예제 #27
0
        /// <summary>Posts a message to the user’s Ping.fm services.</summary>
        public PingResponse Post(OutgoingMessage message)
        {
            string         url      = "http://api.ping.fm/v1/user.post";
            string         postdata = "api_key={0}&user_app_key={1}";
            string         method   = message.Method;
            EncodeDelegate encoder  = UrlEncode;

            postdata = string.Format(postdata, api_key, user_application_key, method);
            if (message.Encoding == PingEncoding.Base64)
            {
                postdata += "&encoding=base64";
                encoder   = Base64Encode;
            }
            if (string.IsNullOrEmpty(message.Trigger))
            {
                if (string.IsNullOrEmpty(method))
                {
                    method = "default";
                }
                postdata += "&post_method=" + UrlEncode(method);
            }
            else
            {
                url       = "http://api.ping.fm/v1/user.tpost";
                postdata += "&trigger=" + UrlEncode(message.Trigger);
            }
            if (!string.IsNullOrEmpty(message.Title))
            {
                postdata += "&title=" + encoder(message.Title);
            }
            if (!string.IsNullOrEmpty(message.Body))
            {
                postdata += "&body=" + encoder(message.Body);
            }
            if (!string.IsNullOrEmpty(message.Service))
            {
                postdata += "&service=" + UrlEncode(message.Service);
            }
            if (!string.IsNullOrEmpty(message.Exclude))
            {
                postdata += "&exclude=" + UrlEncode(message.Exclude);
            }
            if (!string.IsNullOrEmpty(message.Location))
            {
                postdata += "&location=" + encoder(message.Location);
            }
            if (!string.IsNullOrEmpty(message.Tags))
            {
                postdata += "&tags=" + encoder(message.Tags);
            }
            if (!string.IsNullOrEmpty(message.Mood))
            {
                postdata += "&mood=" + encoder(message.Mood);
            }
            if (message.Debug)
            {
                postdata += "&debug=1";
            }
            if (message.MediaFilenames != null)
            {
                foreach (string s in message.MediaFilenames)
                {
                    postdata += "&media=" + Base64Encode(GetMediaContent(s));
                }
            }
            string       response = GetWebResponse(url, postdata);
            XmlReader    xr       = XmlReader.Create(new System.IO.StringReader(response));
            PingResponse r        = (PingResponse)DeserializeObject(xr, typeof(PingResponse));

            xr.Close();
            mLastResponse = r;
            return(r);
        }
예제 #28
0
        public void RawSet(string Name, int Position, string Value, SafeRawDelegate SafeRawMethod, EncodeDelegate EncodeMethod, DecodeDelegate DecodeMethod)
        {
            if (Name.Trim().Length == 0)
            {
                return;
            }
            string SafeName  = SafeRawMethod(Name);
            string SafeValue = SafeRawMethod(Value);

            if (Position < 0)
            {
                return;
            }
            string Key = MatchAndGetKey(SafeName, EncodeMethod, DecodeMethod);

            if (Key == null)
            {
                ParameterStore[SafeName] = new List <string>()
                {
                    SafeValue
                };
            }
            else
            {
                if (Position >= ParameterStore[Key].Count)
                {
                    this.Add(Key, SafeValue);
                }
                else
                {
                    ParameterStore[Key][Position] = SafeValue;
                }
            }
        }