Example #1
0
        public virtual int init(int bytesPerFrame, int channels, int outputChannels, int codingMode)
        {
            ChannelUnit.init();

            ctx = new Context();
            ctx.outputChannels = outputChannels;
            ctx.dsp            = new Atrac3plusDsp();
            for (int i = 0; i < ctx.numChannelBlocks; i++)
            {
                ctx.channelUnits[i]     = new ChannelUnit();
                ctx.channelUnits[i].Dsp = ctx.dsp;
            }

            // initialize IPQF
            ctx.ipqfDctCtx = new FFT();
            ctx.ipqfDctCtx.mdctInit(5, true, 31.0 / 32768.9);

            ctx.mdctCtx = new FFT();
            ctx.dsp.initImdct(ctx.mdctCtx);

            Atrac3plusDsp.initWaveSynth();

            ctx.gaincCtx = new Atrac();
            ctx.gaincCtx.initGainCompensation(6, 2);

            return(0);
        }
Example #2
0
        public void OnNext(MqttApplicationMessage value)
        {
            var m = _ClientTopic.Match(value.Topic);

            if (m.Success)
            {
                var  cli    = m.Captures[0].Value;
                bool online = false;
                if (value.Payload != null && value.Payload.Length > 0)
                {
                    online = value.Payload[0] > 0;
                }
                _logger.LogInformation("presence: {0} online? {1}", cli, online);
            }
            else
            {
                m = _TempTopic.Match(value.Topic);

                if (m.Success)
                {
                    var name = m.Captures[0].Value;
                    if (value.Payload == null || value.Payload.Length < 1)
                    {
                        return;
                    }
                    ChannelValueType type  = (ChannelValueType)value.Payload[0];
                    ChannelUnit      units = (ChannelUnit)value.Payload[1];

                    decimal d = decimal.Zero;
                    switch (type)
                    {
                    case ChannelValueType.t_float:
                    {
                        float f = BitConverter.ToSingle(value.Payload, 2);
                        d = Convert.ToDecimal(f);
                        break;
                    }

                    case ChannelValueType.t_int:
                    {
                        int i = BitConverter.ToInt32(value.Payload, 2);
                        d = Convert.ToDecimal(i);
                        break;
                    }
                    }

                    _pub.publish(name, d, units);

                    _logger.LogInformation("{0} - {1} {2} {3}", value.Topic, name, units, d);
                }
            }
        }
Example #3
0
    public void PublicChat(int player_id, string content)
    {
        if (!this.player_id_to_unit_no.ContainsKey(player_id))
        {
            return;
        }

        int         unit_no      = this.player_id_to_unit_no[player_id];
        ChannelUnit channel_unit = this.GetChannelUnit(unit_no);

        if (channel_unit == null)
        {
            return;
        }
        channel_unit.AddChatContent(player_id, content);
    }
Example #4
0
        /// <summary>
        /// publish values to the webservice
        /// </summary>
        /// <param name="channel"></param>
        /// <param name="value"></param>
        /// <param name="unit"></param>
        public async void publish(string channel, decimal value, ChannelUnit unit)
        {
            var payload = Newtonsoft.Json.JsonConvert.SerializeObject(new { channel = channel, value = value, units = unit.ToString() });
            var client  = new HttpClient();

            client.Timeout = TimeSpan.FromSeconds(10.0);

            var url = _config.publish.uri;
            /* @TODO lookup channel url if it's configured */

            var t = await client.PutAsync(url, new StringContent(payload, Encoding.UTF8));

            if (!t.IsSuccessStatusCode)
            {
                _logger.LogError("Error putting value: {0} => {1}", _config.publish.url, payload);
            }
        }
Example #5
0
    public void Leave(int player_id)
    {
        if (!this.player_id_to_unit_no.ContainsKey(player_id))
        {
            return;
        }

        int unit_no = this.player_id_to_unit_no[player_id];

        this.player_id_to_unit_no.Remove(player_id);
        ChannelUnit channel_unit = this.GetChannelUnit(unit_no);

        if (channel_unit == null)
        {
            return;
        }
        channel_unit.Leave(player_id);
    }
Example #6
0
    public void Enter(int player_id, int unit_no)
    {
        if (this.player_id_to_unit_no.ContainsKey(player_id))
        {
            //不需要重复进入
            if (this.player_id_to_unit_no[player_id] == unit_no)
            {
                return;
            }
        }

        ChannelUnit channel_unit = this.GetChannelUnit(unit_no);

        if (channel_unit == null)
        {
            return;
        }
        this.Leave(player_id);
        channel_unit.Enter(player_id);
        this.player_id_to_unit_no[player_id] = unit_no;
    }