private void UpdateSquareWave_(Channel channel, int total_frames) { if (channel.status) { var square = channel.square_wave; while (total_frames > 0) { int frames = (int)(square.ticks / APU_TICKS); byte sample = Apu.CHANNELX_SAMPLE(channel, square.sample); if (frames <= total_frames) { square.ticks = square.period; square.position = (byte)((square.position + 1) % DUTY_CYCLE_COUNT); square.sample = Apu.GetDuty(square.duty, square.position); } else { frames = total_frames; square.ticks -= (uint)frames * APU_TICKS; } channel.accumulator += sample * (uint)frames; total_frames -= frames; } } }
public void UpdateNoise_(int total_frames) { var channel4 = this.Channel4; if (channel4.status) { var noise = this.noise; while (total_frames > 0) { int frames = (int)(noise.ticks / APU_TICKS); byte sample = Apu.CHANNELX_SAMPLE(channel4, noise.sample); if (noise.clock_shift <= NOISE_MAX_CLOCK_SHIFT) { if (frames <= total_frames) { ushort bit = (ushort)((noise.lfsr ^ (noise.lfsr >> 1)) & 1); if (noise.lfsr_width == LfsrWidth.LFSR_WIDTH_7) { noise.lfsr = (ushort)(((noise.lfsr >> 1) & ~0x40) | (bit << 6)); } else { noise.lfsr = (ushort)(((noise.lfsr >> 1) & ~0x4000) | (bit << 14)); } noise.sample = (byte)(~noise.lfsr & 1); noise.ticks = noise.period; } else { frames = total_frames; noise.ticks -= (uint)frames * APU_TICKS; } } else { frames = total_frames; } channel4.accumulator += sample * (uint)frames; total_frames = (int)(total_frames - frames); } } }