Пример #1
0
 protected void Init(byte ownerIdx, Note note, ADSR env)
 {
     State    = ADSRState.Initializing;
     OwnerIdx = ownerIdx;
     Note     = note;
     adsr.A   = (byte)(env.A & 0x7);
     adsr.D   = (byte)(env.D & 0x7);
     adsr.S   = (byte)(env.S & 0xF);
     adsr.R   = (byte)(env.R & 0x7);
 }
Пример #2
0
        public void Init(byte ownerIdx, Note note, ADSR env, SquarePattern pattern)
        {
            Init(ownerIdx, note, env);
            switch (pattern)
            {
            default: pat = GBSamples.SquareD12; break;

            case SquarePattern.D12: pat = GBSamples.SquareD25; break;

            case SquarePattern.D25: pat = GBSamples.SquareD50; break;

            case SquarePattern.D75: pat = GBSamples.SquareD75; break;
            }
        }
Пример #3
0
        internal void Init(byte ownerIdx, Note note, ADSR env, SquarePattern pattern)
        {
            Init(ownerIdx, note, env);
            switch (pattern)
            {
            default: pat = new float[] { 0.50f, 0.50f, 0.50f, 0.50f, -0.50f, -0.50f, -0.50f, -0.50f }; break;

            case SquarePattern.D12: pat = new float[] { 0.875f, -0.125f, -0.125f, -0.125f, -0.125f, -0.125f, -0.125f, -0.125f }; break;

            case SquarePattern.D25: pat = new float[] { 0.75f, 0.75f, -0.25f, -0.25f, -0.25f, -0.25f, -0.25f, -0.25f }; break;

            case SquarePattern.D75: pat = new float[] { 0.25f, 0.25f, 0.25f, 0.25f, 0.25f, 0.25f, -0.75f, -0.75f }; break;
            }
        }
Пример #4
0
        public DirectSoundChannel NewDSNote(byte owner, ADSR env, Note note, byte vol, sbyte pan, int pitch, bool bFixed, WrappedSample sample, Track[] tracks)
        {
            DirectSoundChannel nChn = null;
            var byOwner             = dsChannels.OrderByDescending(c => c.OwnerIdx);

            foreach (var i in byOwner) // Find free
            {
                if (i.State == ADSRState.Dead || i.OwnerIdx == 0xFF)
                {
                    nChn = i;
                    break;
                }
            }
            if (nChn == null) // Find releasing
            {
                foreach (var i in byOwner)
                {
                    if (i.State == ADSRState.Releasing)
                    {
                        nChn = i;
                        break;
                    }
                }
            }
            if (nChn == null) // Find prioritized
            {
                foreach (var i in byOwner)
                {
                    if (owner >= 16 || tracks[owner].Priority > tracks[i.OwnerIdx].Priority)
                    {
                        nChn = i;
                        break;
                    }
                }
            }
            if (nChn == null)                 // None available
            {
                var lowest = byOwner.First(); // Kill lowest track's instrument if the track is lower than this one
                if (lowest.OwnerIdx >= owner)
                {
                    nChn = lowest;
                }
            }
            if (nChn != null) // Could still be null from the above if
            {
                nChn.Init(owner, note, env, sample, vol, pan, pitch, bFixed);
            }
            return(nChn);
        }
Пример #5
0
        public GBChannel NewGBNote(byte owner, ADSR env, Note note, byte vol, sbyte pan, int pitch, M4AVoiceType type, object arg)
        {
            GBChannel nChn;

            switch (type)
            {
            case M4AVoiceType.Square1:
                nChn = sq1;
                if (nChn.State < ADSRState.Releasing && nChn.OwnerIdx < owner)
                {
                    return(null);
                }
                sq1.Init(owner, note, env, (SquarePattern)arg);
                break;

            case M4AVoiceType.Square2:
                nChn = sq2;
                if (nChn.State < ADSRState.Releasing && nChn.OwnerIdx < owner)
                {
                    return(null);
                }
                sq2.Init(owner, note, env, (SquarePattern)arg);
                break;

            case M4AVoiceType.Wave:
                nChn = wave;
                if (nChn.State < ADSRState.Releasing && nChn.OwnerIdx < owner)
                {
                    return(null);
                }
                wave.Init(owner, note, env, (int)arg);
                break;

            case M4AVoiceType.Noise:
                nChn = noise;
                if (nChn.State < ADSRState.Releasing && nChn.OwnerIdx < owner)
                {
                    return(null);
                }
                noise.Init(owner, note, env, (NoisePattern)arg);
                break;

            default: return(null);
            }
            nChn.SetVolume(vol, pan);
            nChn.SetPitch(pitch);
            return(nChn);
        }
Пример #6
0
        internal static void NewGBNote(byte owner, ADSR env, Note note, byte vol, sbyte pan, int pitch, GBType type, object arg)
        {
            GBChannel nChn;

            switch (type)
            {
            default:
                nChn = sq1;
                if (nChn.State < ADSRState.Releasing && nChn.OwnerIdx < owner)
                {
                    return;
                }
                sq1.Init(owner, note, env, (SquarePattern)arg);
                break;

            case GBType.Square2:
                nChn = sq2;
                if (nChn.State < ADSRState.Releasing && nChn.OwnerIdx < owner)
                {
                    return;
                }
                sq2.Init(owner, note, env, (SquarePattern)arg);
                break;

            case GBType.Wave:
                nChn = wave;
                if (nChn.State < ADSRState.Releasing && nChn.OwnerIdx < owner)
                {
                    return;
                }
                wave.Init(owner, note, env, (byte[])arg);
                break;

            case GBType.Noise:
                nChn = noise;
                if (nChn.State < ADSRState.Releasing && nChn.OwnerIdx < owner)
                {
                    return;
                }
                noise.Init(owner, note, env, (NoisePattern)arg);
                break;
            }
            nChn.SetVolume(vol, pan);
            nChn.SetPitch(pitch);
        }
Пример #7
0
        public void Init(byte ownerIdx, Note note, ADSR adsr, WrappedSample sample, byte vol, sbyte pan, int pitch, bool bFixed)
        {
            State       = ADSRState.Initializing;
            pos         = 0; processStep = 0; interPos = 0;
            OwnerIdx    = ownerIdx;
            Note        = note;
            this.adsr   = adsr;
            this.sample = sample;
            this.bFixed = bFixed;
            bGoldenSun  = (ROM.Instance.Game.Engine.HasGoldenSunSynths && sample.bLoop && sample.LoopPoint == 0 && sample.Length == 0);
            if (bGoldenSun)
            {
                gsPSG = ROM.Instance.Reader.ReadObject <GoldenSunPSG>(sample.GetOffset());
            }

            SetVolume(vol, pan);
            SetPitch(pitch);
        }
Пример #8
0
        internal void Init(byte ownerIdx, Note note, ADSR adsr, Sample sample, byte vol, sbyte pan, int pitch, bool bFixed)
        {
            State       = ADSRState.Initializing;
            pos         = 0; processStep = 0; interPos = 0;
            OwnerIdx    = ownerIdx;
            Note        = note;
            this.adsr   = adsr;
            this.sample = sample;
            this.bFixed = bFixed;
            bGoldenSun  = (sample.bLoop && sample.LoopPoint == 0 && sample.Length == 0);
            if (bGoldenSun)
            {
                gsPSG = ROM.Instance.ReadStruct <GoldenSunPSG>(sample.Offset);
            }

            SetVolume(vol, pan);
            SetPitch(pitch);
        }
Пример #9
0
        internal void Init(byte ownerIdx, Note note, ADSR env, byte[] data)
        {
            Init(ownerIdx, note, env);

            float sum = 0;

            for (int i = 0; i < 0x10; i++)
            {
                byte  b      = data[i];
                float first  = (b >> 4) / 16f;
                float second = (b & 0xF) / 16f;
                sum += sample[i * 2] = first;
                sum += sample[i * 2 + 1] = second;
            }
            float dcCorrection = sum / 0x20;

            for (int i = 0; i < 0x20; i++)
            {
                sample[i] -= dcCorrection;
            }
        }
Пример #10
0
 public void Init(byte ownerIdx, Note note, ADSR env, NoisePattern pattern)
 {
     Init(ownerIdx, note, env);
     pat = (pattern == NoisePattern.Fine ? GBSamples.NoiseFine : GBSamples.NoiseRough);
 }
Пример #11
0
        public void Init(byte ownerIdx, Note note, ADSR env, int address)
        {
            Init(ownerIdx, note, env);

            sample = GBSamples.PCM4ToFloat(address);
        }
Пример #12
0
 internal void Init(byte ownerIdx, Note note, ADSR env, NoisePattern pattern)
 {
     Init(ownerIdx, note, env);
     pat = (pattern == NoisePattern.Fine ? fine : rough);
 }