private SoundMixer() { SamplesPerBuffer = Config.Instance.SampleRate / (Engine.AGB_FPS * Config.Instance.InterFrames); SampleRateReciprocal = 1f / Config.Instance.SampleRate; SamplesReciprocal = 1f / SamplesPerBuffer; dsChannels = new DirectSoundChannel[Config.Instance.DirectCount]; for (int i = 0; i < Config.Instance.DirectCount; i++) { dsChannels[i] = new DirectSoundChannel(); } gbChannels = new GBChannel[] { sq1 = new SquareChannel(), sq2 = new SquareChannel(), wave = new WaveChannel(), noise = new NoiseChannel() }; allChannels = dsChannels.Union(gbChannels).ToArray(); mutes = new bool[17]; // 0-15 for tracks, 16 for the program int amt = SamplesPerBuffer * 2; audio = new WaveBuffer(amt * 4) { FloatBufferCount = amt }; buffer = new BufferedWaveProvider(WaveFormat.CreateIeeeFloatWaveFormat(Config.Instance.SampleRate, 2)) { DiscardOnBufferOverflow = true }; @out = new WasapiOut(); @out.Init(buffer); @out.Play(); }
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); }
static SoundMixer() { SamplesPerBuffer = Config.SampleRate / (Engine.AGB_FPS * Engine.INTERFRAMES); SampleRateReciprocal = 1f / Config.SampleRate; SamplesReciprocal = 1f / SamplesPerBuffer; dsChannels = new DirectSoundChannel[Config.DirectCount]; for (int i = 0; i < Config.DirectCount; i++) { dsChannels[i] = new DirectSoundChannel(); } trackBuffers = new float[MAX_TRACKS][]; reverbs = new Reverb[MAX_TRACKS]; mutes = new bool[MAX_TRACKS]; int amt = (int)(SamplesPerBuffer * 2); audio = new WaveBuffer(amt * 4) { FloatBufferCount = amt }; for (int i = 0; i < MAX_TRACKS; i++) { trackBuffers[i] = new float[amt]; } gbChannels = new GBChannel[] { sq1 = new SquareChannel(), sq2 = new SquareChannel(), wave = new WaveChannel(), noise = new NoiseChannel() }; allChannels = dsChannels.Union(gbChannels).ToArray(); buffer = new BufferedWaveProvider(WaveFormat.CreateIeeeFloatWaveFormat((int)Config.SampleRate, 2)) { DiscardOnBufferOverflow = true }; @out = new WasapiOut(); @out.Init(buffer); @out.Play(); }