Exemplo n.º 1
0
        private unsafe VoiceState GetState()
        {
            VoiceState result = new VoiceState();

            GetStateNative(Instance.ToPointer(), out result, 0);
            return(result);
        }
Exemplo n.º 2
0
        public bool JoinAnchorRoom()
        {
            if (VoiceState.Inited != State)
            {
                Debug.Log("Error:GVoiceManager.JoinAnchorRoom VoiceState.Inited = " + State);
                if (IsInRoom)
                {
                    EventDispatcher.Instance.DispatchEvent(new ShowUIHintBoard(GameUtils.GetDictionaryText(301040)));
                }
                return(false);
            }

            bool canSpeek = false;

            if (IsAnchor)
            {
                canSpeek = true;
                NetManager.Instance.StartCoroutine(AnchorEnterRoom());
            }
            Debug.Log("GVoiceManager.JoinAnchorRoom roomName=" + AnchorRoom + " isAnchor=" + canSpeek);

            m_voiceengine.SetMode(GCloudVoiceMode.RealTime);
            if ((int)GCloudVoiceErr.GCLOUD_VOICE_SUCC != m_voiceengine.JoinNationalRoom(AnchorRoom, canSpeek ? GCloudVoiceRole.ANCHOR : GCloudVoiceRole.AUDIENCE, TimeOutMillSeconds))
            {
                return(false);
            }
            State     = VoiceState.JoiningRoom;
            mRoomType = RoomType.Anchor;
            return(true);
        }
        public void Start(int channel, int note, int velocity)
        {
            this.note      = note;
            this.velocity  = velocity;
            this.channel   = channel;
            time           = 0.0;
            fadeMultiplier = 1.0f;
            decayCounter   = 0;
            fadeCounter    = 0;

            //Set note parameters in samples
            attack  = inst.getAttack(note);
            release = inst.getRelease(note);
            hold    = inst.getHold(note);
            decay   = inst.getDecay(note);

            //Set counters and initial state
            decayCounter = decay;
            if (attack == 0)
            {
                state = VoiceState.Sustain;
            }
            else
            {
                state       = VoiceState.Attack;
                fadeCounter = attack;
            }
            inUse = true;
        }
Exemplo n.º 4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="BindableVoiceState"/> class.
        /// </summary>
        internal BindableVoiceState(
            IMessenger messenger,
            IDiscordService discordService,
            QuarrelClient quarrelClient,
            IDispatcherService dispatcherService,
            VoiceState state) :
            base(messenger, discordService, quarrelClient, dispatcherService)
        {
            _state = state;

            JoinStreamCommand = new RelayCommand(JoinStream);

            _messenger.Register <VoiceStateUpdatedMessage>(this, (_, m) =>
            {
                if (m.VoiceState.User.Id == State.User.Id)
                {
                    _dispatcherService.RunOnUIThread(() =>
                    {
                        OnPropertyChanged(nameof(State));
                        OnPropertyChanged(nameof(CanJoin));
                    });
                }
            });
            _messenger.Register <StreamCreatedMessage>(this, (_, m) =>
            {
                if (m.StreamKey.EndsWith(State.User.Id.ToString()))
                {
                    _dispatcherService.RunOnUIThread(() =>
                    {
                        IsWatching = true;
                    });
                }
            });
        }
Exemplo n.º 5
0
        /// <summary>
        ///     Updates the voice state and sends the data to the Lavalink Node if the voice server
        ///     is also provided.
        /// </summary>
        /// <param name="voiceState">the voice state data</param>
        /// <returns>a task that represents the asynchronous operation</returns>
        /// <exception cref="InvalidOperationException">thrown if the player is destroyed</exception>
        internal Task UpdateAsync(VoiceState voiceState)
        {
            EnsureNotDestroyed();

            _voiceState = voiceState;
            return(UpdateAsync());
        }
Exemplo n.º 6
0
        public void Start(int channel, int note, int velocity)
        {
            this.note = note;
            this.velocity = velocity;
            this.channel = channel;
            time = 0.0;
            fadeMultiplier = 1.0f;
            decayCounter = 0;
            fadeCounter = 0;

            //Set note parameters in samples
            attack = inst.getAttack(note);
            release = inst.getRelease(note);
            hold = inst.getHold(note);
            decay = inst.getDecay(note);

            //Set counters and initial state
            decayCounter = decay;
            if (attack == 0)
                state = VoiceState.Sustain;
            else
            {
                state = VoiceState.Attack;
                fadeCounter = attack;
            }
            inUse = true;
        }
Exemplo n.º 7
0
 public void End()
 {
     if (voiceState == VoiceState.Playing)
     {
         voiceState = VoiceState.ReleaseRequested;
     }
 }
Exemplo n.º 8
0
        /// <summary>
        /// Create a new <see cref="DataSourceVersion2Command"/>.
        /// </summary>
        /// <param name="voiceState">The <see cref="VoiceState"/> to generate the command from.</param>
        /// <param name="state">The <see cref="VoiceUpdateState"/> to generate the command from.</param>
        /// <param name="outputBufferIndex">The output buffer index to use.</param>
        /// <param name="channelIndex">The target channel index.</param>
        /// <param name="nodeId">The node id associated to this command.</param>
        public void GenerateDataSourceVersion2(ref VoiceState voiceState, Memory <VoiceUpdateState> state, ushort outputBufferIndex, ushort channelIndex, int nodeId)
        {
            DataSourceVersion2Command command = new DataSourceVersion2Command(ref voiceState, state, outputBufferIndex, channelIndex, nodeId);

            command.EstimatedProcessingTime = _commandProcessingTimeEstimator.Estimate(command);

            AddCommand(command);
        }
Exemplo n.º 9
0
        /// <summary>
        /// Create a new <see cref="AdpcmDataSourceCommandVersion1"/>.
        /// </summary>
        /// <param name="voiceState">The <see cref="VoiceState"/> to generate the command from.</param>
        /// <param name="state">The <see cref="VoiceUpdateState"/> to generate the command from.</param>
        /// <param name="outputBufferIndex">The output buffer index to use.</param>
        /// <param name="nodeId">The node id associated to this command.</param>
        public void GenerateAdpcmDataSourceVersion1(ref VoiceState voiceState, Memory <VoiceUpdateState> state, ushort outputBufferIndex, int nodeId)
        {
            AdpcmDataSourceCommandVersion1 command = new AdpcmDataSourceCommandVersion1(ref voiceState, state, outputBufferIndex, nodeId);

            command.EstimatedProcessingTime = _commandProcessingTimeEstimator.Estimate(command);

            AddCommand(command);
        }
Exemplo n.º 10
0
        /// <summary>
        ///     Updates the voice state and sends the data to the Lavalink Node if the voice server
        ///     is also provided.
        /// </summary>
        /// <param name="voiceState">the voice state data</param>
        /// <returns>a task that represents the asynchronous operation</returns>
        /// <exception cref="InvalidOperationException">thrown if the player is destroyed</exception>
        internal Task UpdateAsync(VoiceState voiceState)
        {
            EnsureNotDestroyed();

            VoiceState     = voiceState;
            VoiceChannelId = voiceState.VoiceChannelId;
            return(UpdateAsync());
        }
Exemplo n.º 11
0
        private void OnVoiceStateUpdated(object sender, VoiceState e)
        {
            _messenger.Send(new VoiceStateUpdatedMessage(e));

            if (e.User.Id == MyId)
            {
                _messenger.Send(new MyVoiceStateUpdatedMessage(e));
            }
        }
Exemplo n.º 12
0
        private Task OnVoiceStateUpdated(SocketUser user, SocketVoiceState oldSocketVoiceState, SocketVoiceState socketVoiceState)
        {
            var guildId       = socketVoiceState.VoiceChannel?.Guild?.Id ?? oldSocketVoiceState.VoiceChannel.Guild.Id;
            var oldVoiceState = new VoiceState(oldSocketVoiceState.VoiceChannel?.Id, guildId, oldSocketVoiceState.VoiceSessionId);
            var voiceState    = new VoiceState(socketVoiceState.VoiceChannel?.Id, guildId, socketVoiceState.VoiceSessionId);
            var args          = new VoiceStateUpdateEventArgs(user.Id, voiceState, oldVoiceState);

            return(VoiceStateUpdated.InvokeAsync(this, args));
        }
Exemplo n.º 13
0
        /// <summary>
        ///     The asynchronous callback when a voice state update was received.
        /// </summary>
        /// <param name="voiceServer">the voice state data</param>
        /// <returns>a task that represents the asynchronous operation</returns>
        private Task OnVoiceStateUpdated(global::DSharpPlus.EventArgs.VoiceStateUpdateEventArgs eventArgs)
        {
            var sessionId     = eventArgs.GetSessionId();
            var guildId       = eventArgs.Before?.Channel?.Guild?.Id ?? eventArgs.After.Channel.Guild.Id;
            var oldVoiceState = new VoiceState(eventArgs.Before?.Channel?.Id, guildId, sessionId);
            var voiceState    = new VoiceState(eventArgs.After.Channel?.Id, guildId, sessionId);
            var args          = new Events.VoiceStateUpdateEventArgs(eventArgs.User.Id, voiceState, oldVoiceState);

            return(VoiceStateUpdated.InvokeAsync(this, args));
        }
Exemplo n.º 14
0
        /// <summary>
        ///     Asynchronously triggered when the player has connected to a voice channel.
        /// </summary>
        /// <param name="voiceServer">the voice server connected to</param>
        /// <param name="voiceState">the voice state</param>
        /// <returns>a task that represents the asynchronous operation</returns>
        public async override Task OnConnectedAsync(VoiceServer voiceServer, VoiceState voiceState)
        {
            // check if a volume has been stored
            if (_volumes.TryGetValue(GuildId, out var volume) && Volume != volume)
            {
                // here the volume is restored
                await SetVolumeAsync(volume);
            }

            await base.OnConnectedAsync(voiceServer, voiceState);
        }
Exemplo n.º 15
0
 private async void ConnectToVoiceChannel(VoiceServerUpdate data, VoiceState state)
 {
     var message = new ValueSet
     {
         ["type"]     = "connect",
         ["config"]   = JsonConvert.SerializeObject(data),
         ["state"]    = JsonConvert.SerializeObject(state),
         ["inputId"]  = _settingsService.Roaming.GetValue <string>(SettingKeys.InputDevice),
         ["outputId"] = _settingsService.Roaming.GetValue <string>(SettingKeys.OutputDevice),
     };
     AppServiceResponse response = await SendServiceMessage(message);
 }
Exemplo n.º 16
0
 private async void Gateway_VoiceStateUpdated(object sender, Gateway.GatewayEventArgs <VoiceState> e)
 {
     await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal,
                                                                   () =>
     {
         if (e.EventData.UserId == DisplayedUser.UserId)
         {
             DisplayedUser = e.EventData;
             OnPropertyChanged(null, DisplayedUserProperty);
         }
     });
 }
Exemplo n.º 17
0
 public CS_VOICESTATE_TYPE TryGetVoiceState(ulong uid)
 {
     for (int i = 0; i < this.m_voiceStateList.Count; i++)
     {
         VoiceState state = this.m_voiceStateList[i];
         if ((state != null) && (state.uid == uid))
         {
             return(state.state);
         }
     }
     return(CS_VOICESTATE_TYPE.CS_VOICESTATE_NONE);
 }
Exemplo n.º 18
0
 public void Stop()
 {
     if (_synth.FadeOutDuration == 0)
     {
         IsAlive = false;
     }
     else
     {
         _fadeCounter = (int)((1.0f - _fadeMultiplier) * _synth.FadeOutDuration);
         _state = VoiceState.Release;
     }
 }
Exemplo n.º 19
0
        public void Start(RegionPair region, int channel, int key, int velocity)
        {
            this.exclusiveClass = region.ExclusiveClass;
            this.channel        = channel;
            this.key            = key;
            this.velocity       = velocity;

            if (velocity > 0)
            {
                // According to the Polyphone's implementation, the initial attenuation should be reduced to 40%.
                // I'm not sure why, but this indeed improves the loudness variability.
                var sampleAttenuation = 0.4F * region.InitialAttenuation;
                var filterAttenuation = 0.5F * region.InitialFilterQ;
                var decibels          = 2 * SoundFontMath.LinearToDecibels(velocity / 127F) - sampleAttenuation - filterAttenuation;
                noteGain = SoundFontMath.DecibelsToLinear(decibels);
            }
            else
            {
                noteGain = 0F;
            }

            cutoff    = region.InitialFilterCutoffFrequency;
            resonance = SoundFontMath.DecibelsToLinear(region.InitialFilterQ);

            vibLfoToPitch = 0.01F * region.VibratoLfoToPitch;
            modLfoToPitch = 0.01F * region.ModulationLfoToPitch;
            modEnvToPitch = 0.01F * region.ModulationEnvelopeToPitch;

            modLfoToCutoff = region.ModulationLfoToFilterCutoffFrequency;
            modEnvToCutoff = region.ModulationEnvelopeToFilterCutoffFrequency;
            dynamicCutoff  = modLfoToCutoff != 0 || modEnvToCutoff != 0;

            modLfoToVolume = region.ModulationLfoToVolume;
            dynamicVolume  = modLfoToVolume > 0.05F;

            instrumentPan    = SoundFontMath.Clamp(region.Pan, -50F, 50F);
            instrumentReverb = 0.01F * region.ReverbEffectsSend;
            instrumentChorus = 0.01F * region.ChorusEffectsSend;

            volEnv.Start(region, key, velocity);
            modEnv.Start(region, key, velocity);
            vibLfo.StartVibrato(region, key, velocity);
            modLfo.StartModulation(region, key, velocity);
            oscillator.Start(synthesizer.SoundFont.WaveDataArray, region);
            filter.ClearBuffer();
            filter.SetLowPassFilter(cutoff, resonance);

            smoothedCutoff = cutoff;

            voiceState  = VoiceState.Playing;
            voiceLength = 0;
        }
Exemplo n.º 20
0
        private Task OnVoiceStateUpdated(SocketUser user, SocketVoiceState oldSocketVoiceState, SocketVoiceState socketVoiceState)
        {
            var guildId = oldSocketVoiceState.VoiceChannel?.Guild?.Id ?? socketVoiceState.VoiceChannel.Guild.Id;

            // create voice state
            var voiceState = new VoiceState(
                voiceChannelId: socketVoiceState.VoiceChannel?.Id,
                guildId: guildId,
                voiceSessionId: socketVoiceState.VoiceSessionId);

            // invoke event
            return(VoiceStateUpdated.InvokeAsync(this, new VoiceStateUpdateEventArgs(user.Id, voiceState)));
        }
Exemplo n.º 21
0
        /// <inheritdoc/>
        public VoiceState[] GetVoiceStates()
        {
            VoiceState[] states = new VoiceState[_users.Count];
            int          i      = 0;

            foreach (var user in _users)
            {
                states[i] = Context.Voice.GetVoiceState(user) !;
                i++;
            }

            return(states);
        }
Exemplo n.º 22
0
        private void GenerateDataSource(ref VoiceState voiceState, Memory <VoiceUpdateState> dspState, int channelIndex)
        {
            if (voiceState.MixId != Constants.UnusedMixId)
            {
                ref MixState mix = ref _mixContext.GetState(voiceState.MixId);

                _commandBuffer.GenerateDepopPrepare(dspState,
                                                    _rendererContext.DepopBuffer,
                                                    mix.BufferCount,
                                                    mix.BufferOffset,
                                                    voiceState.NodeId,
                                                    voiceState.WasPlaying);
            }
Exemplo n.º 23
0
 public void SetVoiceState(ulong uid, CS_VOICESTATE_TYPE state)
 {
     for (int i = 0; i < this.m_voiceStateList.Count; i++)
     {
         VoiceState state2 = this.m_voiceStateList[i];
         if ((state2 != null) && (state2.uid == uid))
         {
             state2.state = state;
             return;
         }
     }
     this.m_voiceStateList.Add(new VoiceState(uid, state));
 }
Exemplo n.º 24
0
        /// <summary>
        /// Speak the specified text using RT-Voice. You can override this
        /// if you need to do anything extra.
        /// </summary>
        /// <param name="text">Text.</param>
        public virtual void Speak(string text)
        {
            var voice     = GetVoice();
            var voiceName = (voice == null) ? "Default Speaker" : voice.Name;

            if (DialogueDebug.LogInfo)
            {
                Debug.Log("Dialogue System: RT-Voice speaking with " + voiceName + ": '" + text + "'", this);
            }
            Speaker.Silence();
            m_audioSource.Stop();
            voiceState = VoiceState.Starting;
            Speaker.Speak(text, m_audioSource, voice, true);
        }
Exemplo n.º 25
0
        internal void Update(MemberVoiceState model)
        {
            if (model.IsSelfMuted == true)
            {
                _voiceState |= VoiceState.SelfMuted;
            }
            else if (model.IsSelfMuted == false)
            {
                _voiceState &= ~VoiceState.SelfMuted;
            }
            if (model.IsSelfDeafened == true)
            {
                _voiceState |= VoiceState.SelfDeafened;
            }
            else if (model.IsSelfDeafened == false)
            {
                _voiceState &= ~VoiceState.SelfDeafened;
            }
            if (model.IsServerMuted == true)
            {
                _voiceState |= VoiceState.ServerMuted;
            }
            else if (model.IsServerMuted == false)
            {
                _voiceState &= ~VoiceState.ServerMuted;
            }
            if (model.IsServerDeafened == true)
            {
                _voiceState |= VoiceState.ServerDeafened;
            }
            else if (model.IsServerDeafened == false)
            {
                _voiceState &= ~VoiceState.ServerDeafened;
            }
            if (model.IsServerSuppressed == true)
            {
                _voiceState |= VoiceState.ServerSuppressed;
            }
            else if (model.IsServerSuppressed == false)
            {
                _voiceState &= ~VoiceState.ServerSuppressed;
            }

            /*if (model.SessionId != null)
             *                  SessionId = model.SessionId;
             *          if (model.Token != null)
             *                  Token = model.Token;*/

            _voiceChannelId = model.ChannelId;             //Allows null
        }
Exemplo n.º 26
0
        private async void ConnectToVoiceChannel(VoiceServerUpdate data, VoiceState state)
        {
            voipCall?.NotifyCallEnded();
            VoipCallCoordinator vcc = VoipCallCoordinator.GetDefault();
            var status = await vcc.ReserveCallResourcesAsync("WebRTCBackgroundTask.VoipBackgroundTask");

            // TODO: More info for Mobile
            voipCall = vcc.RequestNewOutgoingCall(string.Empty, string.Empty, "Quarrel", VoipPhoneCallMedia.Audio);
            voipCall.NotifyCallActive();

            voiceConnection        = new VoiceConnection(data, state, webrtcManager);
            voiceConnection.Speak += Speak;
            await voiceConnection.ConnectAsync();
        }
Exemplo n.º 27
0
 public NoteData(SourceVoice v, float freqRatio, byte velocity = 127, bool perc = false)
 {
     if (velocity > 127)
     {
         throw new ArgumentOutOfRangeException("velocity", "Velocity cannot be greater than 127.");
     }
     Voice          = v;
     FrequencyRatio = freqRatio;
     Velocity       = 0f;
     IsPercussion   = perc;
     PercussionPan  = 63;
     FadeVolume     = 1f;
     State          = VoiceState.Active;
 }
 //--Private Methods
 private void resetVoice()
 {
     inUse          = false;
     state          = VoiceState.None;
     note           = 0;
     time           = 0.0;
     fadeMultiplier = 1.0f;
     decayCounter   = 0;
     fadeCounter    = 0;
     pan            = 0.0f;
     channel        = 0;
     rightpan       = 1.0f;
     leftpan        = 1.0f;
     velocity       = 127;
 }
Exemplo n.º 29
0
        public VoiceConnection(VoiceServerUpdate config, VoiceState state)
        {
            //var qualifiers = ResourceContext.GetForCurrentView().QualifierValues;
            //mobile = (qualifiers.ContainsKey("DeviceFamily") && qualifiers["DeviceFamily"] == "Mobile");

            _webMessageSocket  = new WebMessageSocket();
            _udpSocket         = new UDPSocket();
            _state             = state;
            _voiceServerConfig = config;


            eventHandlers     = GetEventHandlers();
            operationHandlers = GetOperationHandlers();

            PrepareSocket();
        }
Exemplo n.º 30
0
        private void ReleaseIfNecessary(Channel channelInfo)
        {
            if (voiceLength < synthesizer.MinimumVoiceDuration)
            {
                return;
            }

            if (voiceState == VoiceState.ReleaseRequested && !channelInfo.HoldPedal)
            {
                volEnv.Release();
                modEnv.Release();
                oscillator.Release();

                voiceState = VoiceState.Released;
            }
        }
        /// <inheritdoc/>
        /// <exception cref="ObjectDisposedException">thrown if the instance is disposed</exception>
        protected Task OnVoiceStateUpdated(DiscordClient _, global::DSharpPlus.EventArgs.VoiceStateUpdateEventArgs eventArgs)
        {
            // session id is the same as the resume key so DSharpPlus should be able to give us the
            // session key in either before or after voice state
            var sessionId = eventArgs.Before?.GetSessionId() ?? eventArgs.After.GetSessionId();

            // create voice state
            var voiceState = new VoiceState(
                voiceChannelId: eventArgs.After?.Channel?.Id,
                guildId: eventArgs.Guild.Id,
                voiceSessionId: sessionId);

            // invoke event
            return(VoiceStateUpdated.InvokeAsync(this,
                                                 new Events.VoiceStateUpdateEventArgs(eventArgs.User.Id, voiceState)));
        }
Exemplo n.º 32
0
        public void Process(float[,] workingBuffer)
        {
            if (IsAlive)
            {
                int samplesPerBuffer = workingBuffer.GetLength(1);
                for (int i = 0; i < samplesPerBuffer; i++)
                {
                    if (_state == VoiceState.Attack)
                    {
                        _fadeMultiplier = (float)_fadeCounter / _synth.FadeInDuration;

                        ++_fadeCounter;
                        if (_fadeCounter >= _synth.FadeInDuration)
                        {
                            _state = VoiceState.Sustain;
                        }
                    }
                    else if (_state == VoiceState.Release)
                    {
                        _fadeMultiplier = 1.0f - (float)_fadeCounter / _synth.FadeOutDuration;

                        ++_fadeCounter;
                        if (_fadeCounter >= _synth.FadeOutDuration)
                        {
                            IsAlive = false;
                            return;
                        }
                    }
                    else
                    {
                        _fadeMultiplier = 1.0f;
                    }

                    float sample = _synth.Oscillator(_frequency, _time);
                    workingBuffer[0, i] += sample * 0.2f * _fadeMultiplier;
                    _time += 1.0f / Synth.SampleRate;
                }
            }
        }
Exemplo n.º 33
0
 public void Stop()
 {
     if (hold == 0)
     {
         if (release == 0)
         {
             state = VoiceState.None;
             inUse = false;
         }
         else
         {
             state = VoiceState.Release;
             fadeCounter = release;
         }
     }
     else
     {
         state = VoiceState.Hold;
         fadeCounter = hold;
     }
 }
Exemplo n.º 34
0
 //--Private Methods
 private void resetVoice()
 {
     inUse = false;
     state = VoiceState.None;
     note = 0;
     time = 0.0;
     fadeMultiplier = 1.0f;
     decayCounter = 0;
     fadeCounter = 0;
     pan = 0.0f;
     channel = 0;
     rightpan = 1.0f;
     leftpan = 1.0f;
     velocity = 127;
 }
Exemplo n.º 35
0
        public void Process(float[,] workingBuffer, int startIndex, int endIndex)
        {
            if (inUse)
            {
                //quick checks to do before we go through our main loop
                if (synth.Channels == 2 && pan != synth.PanPositions[channel])
                    this.setPan(synth.PanPositions[channel]);
                //set sampleRate for tune
                variableSampleRate = synth.SampleRate * Math.Pow(2.0, (synth.TunePositions[channel] * -1.0) / 12.0);
                //main loop
                for (int i = startIndex; i < endIndex; i++)
                {
                    //manage states and calculate volume level
                    switch (state)
                    {
                        case VoiceState.Attack:
                            fadeCounter--;
                            if (fadeCounter <= 0)
                            {
                                state = VoiceState.Sustain;
                                fadeMultiplier = 1.0f;
                            }
                            else
                            {
                                fadeMultiplier = 1.0f - (fadeCounter / (float)attack);
                            }
                            break;
                        case VoiceState.Sustain:
                            decayCounter--;
                            if (decayCounter <= 0)
                            {
                                state = VoiceState.None;
                                inUse = false;
                                fadeMultiplier = 0.0f;
                            }
                            else
                            {
                                fadeMultiplier = decayCounter / (float)decay;
                            }
                            break;
                        case VoiceState.Hold:
                            fadeCounter--;//not used for volume
                            decayCounter--;
                            if (decayCounter <= 0)
                            {
                                state = VoiceState.None;
                                inUse = false;
                                fadeMultiplier = 0.0f;
                            }
                            else if (fadeCounter <= 0)
                            {
                                state = VoiceState.Release;
                                fadeCounter = release;
                            }
                            else
                            {
                                fadeMultiplier = decayCounter / (float)decay;
                            }
                            break;
                        case VoiceState.Release:
                            fadeCounter--;
                            if (fadeCounter <= 0)
                            {
                                state = VoiceState.None;
                                inUse = false;
                            }
                            else
                            {//Multiply decay with fadeout so volume doesn't suddenly rise when releasing notes
                                fadeMultiplier = (decayCounter / (float)decay) * (fadeCounter / (float)release);
                            }
                            break;
                    }
                    //end of state management
                    //Decide how to sample based on channels available
                    
                    //mono output
                    if (synth.Channels == 1)
                    {
                        float sample = inst.getSampleAtTime(note, 0, synth.SampleRate, ref time);
                        sample = sample * (velocity / 127.0f) * synth.VolPositions[channel];
                        workingBuffer[0, i] += (sample * fadeMultiplier * gainControl);
                    }
                    //mono sample to stereo output
                    else if (synth.Channels == 2 && inst.allSamplesSupportDualChannel() == false)
                    {
                        float sample = inst.getSampleAtTime(note, 0, synth.SampleRate, ref time);
                        sample = sample * (velocity / 127.0f) * synth.VolPositions[channel];

                        workingBuffer[0, i] += (sample * fadeMultiplier * leftpan * gainControl);
                        workingBuffer[1, i] += (sample * fadeMultiplier * rightpan * gainControl);
                    }
                    //both support stereo
                    else
                    {

                    }
                    time += 1.0 / variableSampleRate;
                    //bailout of the loop if there is no reason to continue.
                    if (inUse == false)
                        return;
                }
            }
        }
Exemplo n.º 36
0
 public void StopImmediately()
 {
     state = VoiceState.None;
     inUse = false;
 }
Exemplo n.º 37
0
 public void Stop()
 {
     if (_synth.FadeOutDuration == 0)
     {
         IsAlive = false;
     }
     else
     {
         _fadeCounter = (int)((1.0f - _fadeMultiplier) * _synth.FadeOutDuration);
         _state = VoiceState.Release;
     }
 }
Exemplo n.º 38
0
        public void Start(float frequency)
        {
            _frequency = frequency;
            _time = 0.0f;
            _fadeMultiplier = 0.0f;

            _fadeCounter = 0;

            if (_synth.FadeInDuration == 0)
            {
                _state = VoiceState.Sustain;
            }
            else
            {
                _state = VoiceState.Attack;
            }

            IsAlive = true;
        }