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 } }; }
// 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; }
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); }
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)); }
public StdEncoder Add(string tag, EncodeDelegate cody) { if (cody != null) { Add(tag, cody()); } return(this); }
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)); }
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); } }
private Encoder( GetCharEncodeLengthDelegate GetCharEncodeLength, GetEncodeLengthDelegate GetEncodeLength, EncodeCharDelegate EncodeChar, EncodeDelegate Encode) { this.GetCharEncodeLength = GetCharEncodeLength; this.GetEncodeLength = GetEncodeLength; this.EncodeChar = EncodeChar; this.Encode = Encode; }
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); } }
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])); } }
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]); } }
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); }
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); } }
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); }
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); } }
public CfgEncoder Add(string tag, EncodeDelegate cody) => cody == null ? this : Add(tag, cody());
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]; } }
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; } }
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; }
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 }; }
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; } } }
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; } }
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]); } }
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; } }
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); } }
/// <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); }
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; } } }