コード例 #1
0
        /// <summary>
        /// Sets up a new pattern to be played.
        /// </summary>
        private void SetUpPattern()
        {
            bool areAllLooping    = true;
            Sfx  longest          = null;
            Sfx  longestNoLoop    = null;
            int  audioBufferIndex = _referenceSfx == null ? 0 : _referenceSfx.audioBufferIndex;

            for (int i = 0; i < 4; i += 1)
            {
                if (patternData[_patternIndex].channels[i].isSilent)
                {
                    sfxs[i] = null;
                    continue;
                }

                byte[] _sfxData = new byte[68];
                Buffer.BlockCopy(_ram, util.ADDR_SFX + 68 * patternData[_patternIndex].channels[i].sfxIndex, _sfxData, 0, 68);
                sfxs[i] = new Sfx(_sfxData, patternData[_patternIndex].channels[i].sfxIndex, ref _audioBuffer, ref _oscillator, _sampleRate, audioBufferIndex);
                sfxs[i].Start();

                if (!sfxs[i].HasLoop())
                {
                    areAllLooping = false;
                    if (longestNoLoop == null || longestNoLoop.duration < sfxs[i].duration)
                    {
                        longestNoLoop = sfxs[i];
                    }
                }

                if (longest == null || longest.duration < sfxs[i].duration)
                {
                    longest = sfxs[i];
                }
            }

            _referenceSfx = areAllLooping ? longest : longestNoLoop;
            // Remove loop from reference sfx, otherwise it'll keep looping forever.
            _referenceSfx.endLoop = _referenceSfx.startLoop;
        }
コード例 #2
0
 /// <summary>
 /// Initializes audio unit.
 /// </summary>
 public void Init()
 {
     sfxChannels   = new Sfx[channelCount];
     musicChannels = new Sfx[channelCount];
     musicPlayer   = new MusicPlayer(ref _memory, ref audioBuffer, sampleRate);
 }