コード例 #1
0
ファイル: Example_03.cs プロジェクト: uniphonic/G-Audio
        protected override void ButtonClicked(int buttonIndex)
        {
            // local reference to the cached sample for readability
            IGATProcessedSample cachedSample = _processedSamples[buttonIndex];

            // pitch is scale semi tone plus corresponding slider value, translated as a frequency ratio
            double pitch = GATMaths.GetRatioForInterval(( float )scaleSemiTones[buttonIndex] + SliderValues[buttonIndex]);

            // If we have already played this sample and pitch has changed, we call Release().
            // If we wouldn't, the sample bank would keep a cached version of the sample at the previous pitch,
            // Quickly saturating memory.
            if (cachedSample != null && cachedSample.Pitch != pitch)
            {
                cachedSample.Release();
            }

            if (envelopeModule != null)              // If we have an envelope module, we just pass it's envelope to the bank
            {                                        // when requesting a processed sample. All processing is automated.
                cachedSample = sampleBank.GetProcessedSample(sampleName, envelopeModule.Envelope, pitch);
            }
            else
            {                                                                    // Else, we pass null: the entire sample will be pitch shifted and cached.
                cachedSample = sampleBank.GetProcessedSample(sampleName, null, pitch);
            }

            cachedSample.Play(TrackNb);                    // IGATProcessedSample also has it's own set of Play methods. Here, playback
            // will be routed through the default player's track TrackNb.
            _processedSamples[buttonIndex] = cachedSample; // keep a reference of the processed sample to release later.
        }
コード例 #2
0
    void IGATAudioThreadStreamClient.HandleAudioThreadStream(float[] data, int offset, bool emptyData, IGATAudioThreadStream stream)
    {
        int trackIndex = -1;
        int i;

        if (stream == _playerStream)
        {
            for (i = 0; i < _playerChannelsLevels.Length; i++)
            {
                _playerChannelsLevels[i] = GATMaths.GetAbsMaxValueFromInterleaved(data, offset, stream.BufferSizePerChannel * stream.NbOfChannels, i, stream.NbOfChannels);
            }
            _shouldRepaint = true;
            return;
        }

        for (i = 0; i < _trackStreams.Length; i++)
        {
            if (stream == _trackStreams[i])
            {
                trackIndex = i;
                break;
            }
        }

        if (trackIndex == -1)
        {
            return;
        }

        if (emptyData)
        {
            _trackLevels[trackIndex] = 0f;
            _shouldRepaint           = true;
            return;
        }

        _trackLevels[trackIndex] = GATMaths.GetAbsMaxValue(data, offset, GATInfo.AudioBufferSizePerChannel);
        _shouldRepaint           = true;
    }