internal void Reset() { // Wav exporter if ((_wavExporter != null)) { // We stop recording just in case StopRecording(); } else { _wavExporter = new WavExporter(); _channel1WavExporter = new WavExporter(); _channel2WavExporter = new WavExporter(); _channel3WavExporter = new WavExporter(); _channel4WavExporter = new WavExporter(); } _frameSequencer = new FrameSequencer(); // We setup the channels _channel1 = new SquareChannel(_memory, _frameSequencer, SampleRate, NumChannels, SampleSize, 0, MMR.NR10, MMR.NR11, MMR.NR12, MMR.NR13, MMR.NR14); // NOTE(Cristian): Channel 2 doesn't have frequency sweep _channel2 = new SquareChannel(_memory, _frameSequencer, SampleRate, NumChannels, SampleSize, 1, 0, MMR.NR21, MMR.NR22, MMR.NR23, MMR.NR24); _channel3 = new WaveChannel(_memory, _frameSequencer, SampleRate, NumChannels, SampleSize, 2); _channel4 = new NoiseChannel(_memory, _frameSequencer, SampleRate, NumChannels, SampleSize, 3); _state.LeftChannelEnabled = true; _state.RightChannelEnabled = true; Channel1Run = true; Channel2Run = true; Channel3Run = true; Channel4Run = true; _memory.LowLevelWrite((ushort)MMR.NR10, 0x80); _memory.LowLevelWrite((ushort)MMR.NR11, 0xBF); _memory.LowLevelWrite((ushort)MMR.NR12, 0xF3); _memory.LowLevelWrite((ushort)MMR.NR13, 0xFF); _memory.LowLevelWrite((ushort)MMR.NR14, 0xBF); _memory.LowLevelWrite(0xFF15, 0xFF); _memory.LowLevelWrite((ushort)MMR.NR21, 0x3F); _memory.LowLevelWrite((ushort)MMR.NR22, 0x00); _memory.LowLevelWrite((ushort)MMR.NR23, 0xFF); _memory.LowLevelWrite((ushort)MMR.NR24, 0xBF); _memory.LowLevelWrite((ushort)MMR.NR30, 0x7F); _memory.LowLevelWrite((ushort)MMR.NR31, 0xFF); _memory.LowLevelWrite((ushort)MMR.NR32, 0x9F); _memory.LowLevelWrite((ushort)MMR.NR33, 0xBF); _memory.LowLevelWrite((ushort)MMR.NR34, 0xBF); // No info _memory.LowLevelWrite(0xFF1F, 0xFF); _memory.LowLevelWrite((ushort)MMR.NR41, 0xFF); _memory.LowLevelWrite((ushort)MMR.NR42, 0x00); _memory.LowLevelWrite((ushort)MMR.NR43, 0x00); _memory.LowLevelWrite((ushort)MMR.NR44, 0xBF); // No info _memory.LowLevelWrite((ushort)MMR.NR50, 0x77); _memory.LowLevelWrite((ushort)MMR.NR51, 0xF3); _memory.LowLevelWrite((ushort)MMR.NR52, 0xF1); // We fill 0xFF27-0xFF2F with 0xFF for (ushort r = 0xFF27; r <= 0xFF2F; ++r) { _memory.LowLevelWrite(r, 0xFF); } _buffer = new byte[_sampleRate * _numChannels * _sampleSize * _milliseconds / 1000]; }