public void Init(Track owner, Note note, ADSR adsr, int sampleOffset, byte vol, sbyte pan, int pitch, bool bFixed, bool bCompressed) { State = EnvelopeState.Initializing; _pos = 0; _interPos = 0; if (Owner != null) { Owner.Channels.Remove(this); } Owner = owner; Owner.Channels.Add(this); Note = note; _adsr = adsr; _sampleHeader = _mixer.Config.Reader.ReadObject <SampleHeader>(sampleOffset); _sampleOffset = sampleOffset + 0x10; _bFixed = bFixed; _bCompressed = bCompressed; _decompressedSample = bCompressed ? Utils.Decompress(_sampleOffset, _sampleHeader.Length) : null; _bGoldenSun = _mixer.Config.HasGoldenSunSynths && _sampleHeader.DoesLoop == 0x40000000 && _sampleHeader.LoopOffset == 0 && _sampleHeader.Length == 0; if (_bGoldenSun) { _gsPSG = _mixer.Config.Reader.ReadObject <GoldenSunPSG>(_sampleOffset); } SetVolume(vol, pan); SetPitch(pitch); }
public PSGChannel AllocPSGChannel(Track owner, ADSR env, Note note, byte vol, sbyte pan, int instPan, int pitch, VoiceType type, object arg) { PSGChannel nChn; switch (type) { case VoiceType.Square1: { nChn = _sq1; if (nChn.State < EnvelopeState.Releasing && nChn.Owner.Index < owner.Index) { return(null); } _sq1.Init(owner, note, env, instPan, (SquarePattern)arg); break; } case VoiceType.Square2: { nChn = _sq2; if (nChn.State < EnvelopeState.Releasing && nChn.Owner.Index < owner.Index) { return(null); } _sq2.Init(owner, note, env, instPan, (SquarePattern)arg); break; } case VoiceType.PCM4: { nChn = _pcm4; if (nChn.State < EnvelopeState.Releasing && nChn.Owner.Index < owner.Index) { return(null); } _pcm4.Init(owner, note, env, instPan, (int)arg); break; } case VoiceType.Noise: { nChn = _noise; if (nChn.State < EnvelopeState.Releasing && nChn.Owner.Index < owner.Index) { return(null); } _noise.Init(owner, note, env, instPan, (NoisePattern)arg); break; } default: return(null); } nChn.SetVolume(vol, pan); nChn.SetPitch(pitch); return(nChn); }
public void Init(Track owner, Note note, ADSR env, SquarePattern pattern) { Init(owner, note, env); switch (pattern) { default: _pat = Utils.SquareD12; break; case SquarePattern.D12: _pat = Utils.SquareD25; break; case SquarePattern.D25: _pat = Utils.SquareD50; break; case SquarePattern.D75: _pat = Utils.SquareD75; break; } }
public PCM8Channel AllocPCM8Channel(Track owner, ADSR env, Note note, byte vol, sbyte pan, int instPan, int pitch, bool bFixed, bool bCompressed, int sampleOffset) { PCM8Channel nChn = null; IOrderedEnumerable <PCM8Channel> byOwner = _pcm8Channels.OrderByDescending(c => c.Owner == null ? 0xFF : c.Owner.Index); foreach (PCM8Channel i in byOwner) // Find free { if (i.State == EnvelopeState.Dead || i.Owner == null) { nChn = i; break; } } if (nChn == null) // Find releasing { foreach (PCM8Channel i in byOwner) { if (i.State == EnvelopeState.Releasing) { nChn = i; break; } } } if (nChn == null) // Find prioritized { foreach (PCM8Channel i in byOwner) { if (owner.Priority > i.Owner.Priority) { nChn = i; break; } } } if (nChn == null) // None available { PCM8Channel lowest = byOwner.First(); // Kill lowest track's instrument if the track is lower than this one if (lowest.Owner.Index >= owner.Index) { nChn = lowest; } } if (nChn != null) // Could still be null from the above if { nChn.Init(owner, note, env, sampleOffset, vol, pan, instPan, pitch, bFixed, bCompressed); } return(nChn); }
protected void Init(Track owner, Note note, ADSR env) { State = EnvelopeState.Initializing; if (Owner != null) { Owner.Channels.Remove(this); } Owner = owner; Owner.Channels.Add(this); 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); }
public void Init(Track owner, Note note, ADSR env, NoisePattern pattern) { Init(owner, note, env); _pat = pattern == NoisePattern.Fine ? Utils.NoiseFine : Utils.NoiseRough; }
public void Init(Track owner, Note note, ADSR env, int sampleOffset) { Init(owner, note, env); _sample = Utils.PCM4ToFloat(sampleOffset); }