/// <summary> /// Constructs a stream that will accept PCM audio input, and automatically encode it to Opus and packetize it using Ogg, /// writing the output pages to an underlying stream (usually a file stream). /// You are allowed to change the encoding parameters mid-stream using the properties of the OpusEncoder; the only thing you /// cannot change is the sample rate and num# of channels. /// </summary> /// <param name="outputStream">A base stream to accept the encoded ogg file output</param> /// <param name="sampleRate"></param> /// <param name="channelCount"></param> /// <param name="preSkip"></param> /// <param name="sampleCount"></param> /// <param name="fileTags">(optional) A set of tags to include in the encoded file</param> /// <param name="inputSampleRate">The actual real sample rate of your input data (NOT the encoder's sample rate). /// The opus encoder usually requires 48Khz input, but most MP3s and such will give you 44.1Khz. To get the /// sample rates to line up properly in this case, set the encoder to 48000 and pass inputSampleRate = 44100, /// and the write stream will perform resampling for you automatically (Note that resampling will slow down /// the encoding).</param> public OpusOggWriteStream(Stream outputStream, int sampleRate, int channelCount, int preSkip, int sampleCount = -1, OpusTags fileTags = null, int inputSampleRate = 0) { _inputSampleRate = inputSampleRate; if (_inputSampleRate == 0) { _inputSampleRate = sampleRate; } _logicalStreamId = new Random().Next(); _encoderSampleRate = sampleRate; _inputChannels = channelCount; _outputStream = outputStream; //_opusFrameIndex = 0; _granulePosition = 0; _opusFrameSamples = (int)((long)_encoderSampleRate * FRAME_SIZE_MS / 1000); _opusFrame = new short[_opusFrameSamples * _inputChannels]; _crc = new Crc(); _resampler = SpeexResampler.Create(_inputChannels, _inputSampleRate, _encoderSampleRate, 5); _preSkipSamples = preSkip; _sampleCount = sampleCount == -1 ? int.MaxValue : preSkip + sampleCount; BeginNewPage(); WriteOpusHeadPage(); WriteOpusTagsPage(fileTags); }
/// <summary> /// Constructs a stream that will accept PCM audio input, and automatically encode it to Opus and packetize it using Ogg, /// writing the output pages to an underlying stream (usually a file stream). /// You are allowed to change the encoding parameters mid-stream using the properties of the OpusEncoder; the only thing you /// cannot change is the sample rate and num# of channels. /// </summary> /// <param name="encoder">An opus encoder to use for output</param> /// <param name="outputStream">A base stream to accept the encoded ogg file output</param> /// <param name="fileTags">(optional) A set of tags to include in the encoded file</param> /// <param name="inputSampleRate">The actual real sample rate of your input data (NOT the encoder's sample rate). /// The opus encoder usually requires 48Khz input, but most MP3s and such will give you 44.1Khz. To get the /// sample rates to line up properly in this case, set the encoder to 48000 and pass inputSampleRate = 44100, /// and the write stream will perform resampling for you automatically (Note that resampling will slow down /// the encoding).</param> public OpusOggWriteStream(OpusEncoder encoder, Stream outputStream, OpusTags fileTags = null, int inputSampleRate = 0, int logicalStreamId = 0) { _encoder = encoder; if (_encoder.UseDTX) { throw new ArgumentException("DTX is not currently supported in Ogg streams"); } _inputSampleRate = inputSampleRate; if (_inputSampleRate == 0) { _inputSampleRate = _encoder.SampleRate; } if (logicalStreamId == 0) { logicalStreamId = new Random().Next(); } _logicalStreamId = logicalStreamId; _encoderSampleRate = encoder.SampleRate; _inputChannels = encoder.NumChannels; _outputStream = outputStream; _opusFrameIndex = 0; _granulePosition = 0; _opusFrameSamples = (int)((long)_encoderSampleRate * FRAME_SIZE_MS / 1000); _opusFrame = new short[_opusFrameSamples * _inputChannels]; _crc = new Crc(); _resampler = SpeexResampler.Create(_inputChannels, _inputSampleRate, _encoderSampleRate, 5); BeginNewPage(); WriteOpusHeadPage(); WriteOpusTagsPage(fileTags); }
public Sid(int[][] newWaveformTable, uint sampleRate, uint cyclesNum, uint cyclesDen) { waveformTable = newWaveformTable; envelopes = new Envelope[3]; for (int i = 0; i < 3; i++) { envelopes[i] = new Envelope(); } envelopeOutput = new int[3]; voices = new Voice[3]; for (int i = 0; i < 3; i++) { voices[i] = new Voice(newWaveformTable); } voiceOutput = new int[3]; filterEnable = new bool[3]; for (int i = 0; i < 3; i++) { filterEnable[i] = false; } resampler = new SpeexResampler(0, cyclesNum, sampleRate * cyclesDen, cyclesNum, sampleRate * cyclesDen, null, null); }
public void ConnectToMachine(MachineBase m, EMU7800.Win.GameProgram g) { framebuffer = m.CreateFrameBuffer(); BufferWidth = framebuffer.VisiblePitch; BufferHeight = framebuffer.Scanlines; vidbuffer = new int[BufferWidth * BufferHeight]; uint newsamplerate = (uint)m.SoundSampleFrequency; if (newsamplerate != samplerate) { // really shouldn't happen (after init), but if it does, we're ready if (resampler != null) { resampler.Dispose(); } resampler = new SpeexResampler(3, newsamplerate, 44100, newsamplerate, 44100, null, null); samplerate = newsamplerate; dcfilter = DCFilter.DetatchedMode(256); } if (g.MachineType == MachineType.A7800PAL || g.MachineType == MachineType.A2600PAL) { palette = TIATables.PALPalette; } else { palette = TIATables.NTSCPalette; } }
public void Dispose() { if (_resampler != null) { _resampler.Dispose(); _resampler = null; } }
public void Dispose() { if (resampler != null) { resampler.Dispose(); resampler = null; } }
public DobieStation(CoreLoadParameters <object, DobieSyncSettings> lp) : base(lp.Comm, new Configuration { MaxWidth = 640, MaxHeight = 480, DefaultWidth = 640, DefaultHeight = 480, DefaultFpsNumerator = 294912000, DefaultFpsDenominator = 4920115, MaxSamples = 1024, SystemId = "PS2" }) { if (lp.Discs.Count != 1) { throw new InvalidOperationException("Must load a CD or DVD with PS2 core!"); } ControllerDefinition = DualShock; _syncSettings = lp.SyncSettings ?? new DobieSyncSettings(); _syncSettingsActual = lp.SyncSettings ?? new DobieSyncSettings(); _disc = new DiscSectorReader(lp.Discs[0].DiscData); _cdCallback = ReadCd; _core = PreInit <LibDobieStation>(new WaterboxOptions { Filename = "dobie.wbx", SbrkHeapSizeKB = 64 * 1024, SealedHeapSizeKB = 4 * 1024, InvisibleHeapSizeKB = 4 * 1024, PlainHeapSizeKB = 256, MmapHeapSizeKB = 2 * 1024 * 1024, SkipCoreConsistencyCheck = lp.Comm.CorePreferences.HasFlag(CoreComm.CorePreferencesFlags.WaterboxCoreConsistencyCheck), SkipMemoryConsistencyCheck = lp.Comm.CorePreferences.HasFlag(CoreComm.CorePreferencesFlags.WaterboxMemoryConsistencyCheck), }, new[] { _cdCallback }); var bios = lp.Comm.CoreFileProvider.GetFirmware("PS2", "BIOS", true); _exe.AddReadonlyFile(new byte[0x840000], "MEMCARD0"); var worked = _core.Initialize(bios, (ulong)(lp.Discs[0].DiscData.Session1.Tracks[2].LBA - lp.Discs[0].DiscData.Session1.Tracks[1].LBA) * 2048, _cdCallback, _syncSettingsActual.GetNativeSettings() ); if (!worked) { throw new InvalidOperationException("Initialize failed!"); } _exe.RemoveReadonlyFile("MEMCARD0"); PostInit(); _resampler = new SpeexResampler((SpeexResampler.Quality) 6, 480, 441, 48000, 44100, null, this); _serviceProvider.Register <ISoundProvider>(_resampler); }
public override void Dispose() { base.Dispose(); if (_resampler != null) { _resampler.Dispose(); _resampler = null; } }
void SetupResampler(double fps, double sps) { Console.WriteLine("FPS {0} SPS {1}", fps, sps); // todo: more precise? uint spsnum = (uint)sps * 1000; uint spsden = (uint)1000; resampler = new SpeexResampler(SpeexResampler.Quality.QUALITY_DESKTOP, 44100 * spsden, spsnum, (uint)sps, 44100, null, null); }
/// <summary> /// Creates a N64 Audio subsystem /// </summary> /// <param name="api">Mupen64 api which is used for fetching sound</param> public N64Audio(mupen64plusApi core) { this.api = new mupen64plusAudioApi(core); _samplingRate = api.GetSamplingRate(); Resampler = new SpeexResampler(6, SamplingRate, 44100, SamplingRate, 44100); core.VInterrupt += DoAudioFrame; }
public MelonDS(byte[] file, CoreComm comm, object settings, object syncSettings) { _serviceProvider = new BasicServiceProvider(this); ControllerDefinition = new ControllerDefinition { Name = "NDS Controller" }; ControllerDefinition.BoolButtons.Add("Left"); ControllerDefinition.BoolButtons.Add("Right"); ControllerDefinition.BoolButtons.Add("Up"); ControllerDefinition.BoolButtons.Add("Down"); ControllerDefinition.BoolButtons.Add("A"); ControllerDefinition.BoolButtons.Add("B"); ControllerDefinition.BoolButtons.Add("X"); ControllerDefinition.BoolButtons.Add("Y"); ControllerDefinition.BoolButtons.Add("L"); ControllerDefinition.BoolButtons.Add("R"); ControllerDefinition.BoolButtons.Add("Start"); ControllerDefinition.BoolButtons.Add("Select"); ControllerDefinition.BoolButtons.Add("LidOpen"); ControllerDefinition.BoolButtons.Add("LidClose"); ControllerDefinition.BoolButtons.Add("Power"); ControllerDefinition.BoolButtons.Add("Touch"); ControllerDefinition.AxisControls.Add("TouchX"); ControllerDefinition.AxisRanges.Add(new ControllerDefinition.AxisRange(0, 128, 255)); ControllerDefinition.AxisControls.Add("TouchY"); ControllerDefinition.AxisRanges.Add(new ControllerDefinition.AxisRange(0, 96, 191)); CoreComm = comm; _resampler = new SpeexResampler(SpeexResampler.Quality.QUALITY_DEFAULT, 32768, 44100, 32768, 44100); SetUpFiles(); PutSettings(settings as MelonSettings); PutSyncSettings(syncSettings as MelonSyncSettings); if (!Init()) { throw new Exception("Failed to init NDS."); } InitMemoryDomains(); fixed(byte *f = file) { LoadROM(f, file.Length); } }
public MelonDS(byte[] file, CoreComm comm, MelonSettings settings, MelonSyncSettings syncSettings) { _serviceProvider = new BasicServiceProvider(this); ControllerDefinition = new ControllerDefinition { Name = "NDS Controller" }; ControllerDefinition.BoolButtons.Add("Left"); ControllerDefinition.BoolButtons.Add("Right"); ControllerDefinition.BoolButtons.Add("Up"); ControllerDefinition.BoolButtons.Add("Down"); ControllerDefinition.BoolButtons.Add("A"); ControllerDefinition.BoolButtons.Add("B"); ControllerDefinition.BoolButtons.Add("X"); ControllerDefinition.BoolButtons.Add("Y"); ControllerDefinition.BoolButtons.Add("L"); ControllerDefinition.BoolButtons.Add("R"); ControllerDefinition.BoolButtons.Add("Start"); ControllerDefinition.BoolButtons.Add("Select"); ControllerDefinition.BoolButtons.Add("LidOpen"); ControllerDefinition.BoolButtons.Add("LidClose"); ControllerDefinition.BoolButtons.Add("Power"); ControllerDefinition.BoolButtons.Add("Touch"); ControllerDefinition.AddXYPair("Touch{0}", AxisPairOrientation.RightAndUp, 0.RangeTo(255), 128, 0.RangeTo(191), 96); //TODO verify direction against hardware CoreComm = comm; _resampler = new SpeexResampler(SpeexResampler.Quality.QUALITY_DEFAULT, 32768, 44100, 32768, 44100); SetUpFiles(); PutSettings(settings as MelonSettings); PutSyncSettings(syncSettings as MelonSyncSettings); if (!Init()) { throw new Exception("Failed to init NDS."); } InitMemoryDomains(); fixed(byte *f = file) { LoadROM(f, file.Length); } }
public Sid(int[][] newWaveformTable, int newSampleRate, Region newRegion) { uint cyclesPerSec = 0; uint cyclesNum; uint cyclesDen; uint sampleRate = 44100; switch (newRegion) { case Region.NTSC: cyclesNum = 14318181; cyclesDen = 14; break; case Region.PAL: cyclesNum = 17734472; cyclesDen = 18; break; default: return; } waveformTable = newWaveformTable; envelopes = new Envelope[3]; for (int i = 0; i < 3; i++) { envelopes[i] = new Envelope(); } envelopeOutput = new int[3]; voices = new Voice[3]; for (int i = 0; i < 3; i++) { voices[i] = new Voice(newWaveformTable); } voiceOutput = new int[3]; filterEnable = new bool[3]; for (int i = 0; i < 3; i++) { filterEnable[i] = false; } resampler = new SpeexResampler(0, cyclesNum, sampleRate * cyclesDen, cyclesNum, sampleRate * cyclesDen, null, null); }
public void ConnectToMachine(MachineBase m, GameProgram g) { _frameHz = m.FrameHZ; Framebuffer = m.CreateFrameBuffer(); BufferWidth = Framebuffer.VisiblePitch; BufferHeight = Framebuffer.Scanlines; _vidbuffer = new int[BufferWidth * BufferHeight]; uint newsamplerate = (uint)m.SoundSampleFrequency; if (newsamplerate != _samplerate) { // really shouldn't happen (after init), but if it does, we're ready _resampler?.Dispose(); _resampler = new SpeexResampler((SpeexResampler.Quality) 3, newsamplerate, 44100, newsamplerate, 44100, null, null); _samplerate = newsamplerate; _dcfilter = new DCFilter(256); } if (g.MachineType == MachineType.A2600PAL) { _palette = TIATables.PALPalette; } else if (g.MachineType == MachineType.A7800PAL) { _palette = MariaTables.PALPalette; } else if (g.MachineType == MachineType.A2600NTSC) { _palette = TIATables.NTSCPalette; } else { _palette = MariaTables.NTSCPalette; } }
public NDS(CoreLoadParameters <NDSSettings, NDSSyncSettings> lp) : base(lp.Comm, new Configuration { DefaultWidth = 256, DefaultHeight = 384, MaxWidth = 256, MaxHeight = 384, MaxSamples = 1024, DefaultFpsNumerator = 33513982, DefaultFpsDenominator = 560190, SystemId = VSystemID.Raw.NDS, }) { _syncSettings = lp.SyncSettings ?? new NDSSyncSettings(); _settings = lp.Settings ?? new NDSSettings(); IsDSi = _syncSettings.UseDSi; var roms = lp.Roms.Select(r => r.RomData).ToList(); if (roms.Count > (IsDSi ? 1 : 3)) { throw new InvalidOperationException("Wrong number of ROMs!"); } IsDSiWare = IsDSi && RomIsWare(roms[0]); bool gbacartpresent = roms.Count > 1; bool gbasrampresent = roms.Count == 3; InitMemoryCallbacks(); _tracecb = MakeTrace; _threadstartcb = ThreadStartCallback; _core = PreInit <LibMelonDS>(new WaterboxOptions { Filename = "melonDS.wbx", SbrkHeapSizeKB = 2 * 1024, SealedHeapSizeKB = 4, InvisibleHeapSizeKB = 4 * 1024, PlainHeapSizeKB = 4, MmapHeapSizeKB = 1024 * 1024, SkipCoreConsistencyCheck = CoreComm.CorePreferences.HasFlag(CoreComm.CorePreferencesFlags.WaterboxCoreConsistencyCheck), SkipMemoryConsistencyCheck = CoreComm.CorePreferences.HasFlag(CoreComm.CorePreferencesFlags.WaterboxMemoryConsistencyCheck), }, new Delegate[] { _readcb, _writecb, _execcb, _tracecb, _threadstartcb }); var bios7 = IsDSi || _syncSettings.UseRealBIOS ? CoreComm.CoreFileProvider.GetFirmwareOrThrow(new("NDS", "bios7")) : null; var bios9 = IsDSi || _syncSettings.UseRealBIOS ? CoreComm.CoreFileProvider.GetFirmwareOrThrow(new("NDS", "bios9")) : null; var bios7i = IsDSi ? CoreComm.CoreFileProvider.GetFirmwareOrThrow(new("NDS", "bios7i")) : null; var bios9i = IsDSi ? CoreComm.CoreFileProvider.GetFirmwareOrThrow(new("NDS", "bios9i")) : null; var nand = IsDSi ? CoreComm.CoreFileProvider.GetFirmwareOrThrow(new("NDS", "nand")) : null; var fw = IsDSi ? CoreComm.CoreFileProvider.GetFirmwareOrThrow(new("NDS", "firmwarei")) : CoreComm.CoreFileProvider.GetFirmware(new("NDS", "firmware")); var tmd = IsDSi && IsDSiWare ? GetTMDData(roms[0]) : null; bool skipfw = _syncSettings.SkipFirmware || !_syncSettings.UseRealBIOS || fw == null; LibMelonDS.LoadFlags loadFlags = LibMelonDS.LoadFlags.NONE; if (_syncSettings.UseRealBIOS || IsDSi) { loadFlags |= LibMelonDS.LoadFlags.USE_REAL_BIOS; } if (skipfw && !IsDSi) { loadFlags |= LibMelonDS.LoadFlags.SKIP_FIRMWARE; } if (gbacartpresent) { loadFlags |= LibMelonDS.LoadFlags.GBA_CART_PRESENT; } if (_syncSettings.FirmwareOverride || lp.DeterministicEmulationRequested) { loadFlags |= LibMelonDS.LoadFlags.FIRMWARE_OVERRIDE; } if (IsDSi) { loadFlags |= LibMelonDS.LoadFlags.IS_DSI; } if (IsDSi && IsDSiWare) { loadFlags |= LibMelonDS.LoadFlags.LOAD_DSIWARE; } if (_syncSettings.ThreadedRendering) { loadFlags |= LibMelonDS.LoadFlags.THREADED_RENDERING; } var fwSettings = new LibMelonDS.FirmwareSettings(); var name = Encoding.UTF8.GetBytes(_syncSettings.FirmwareUsername); fwSettings.FirmwareUsernameLength = name.Length; fwSettings.FirmwareLanguage = _syncSettings.FirmwareLanguage; if (!IsDSi && _syncSettings.FirmwareStartUp == NDSSyncSettings.StartUp.AutoBoot) { fwSettings.FirmwareLanguage |= (NDSSyncSettings.Language) 0x40; } fwSettings.FirmwareBirthdayMonth = _syncSettings.FirmwareBirthdayMonth; fwSettings.FirmwareBirthdayDay = _syncSettings.FirmwareBirthdayDay; fwSettings.FirmwareFavouriteColour = _syncSettings.FirmwareFavouriteColour; var message = _syncSettings.FirmwareMessage.Length != 0 ? Encoding.UTF8.GetBytes(_syncSettings.FirmwareMessage) : new byte[1] { 0 }; fwSettings.FirmwareMessageLength = message.Length; var loadData = new LibMelonDS.LoadData { DsRomLength = roms[0].Length, GbaRomLength = gbacartpresent ? roms[1].Length : 0, GbaRamLength = gbasrampresent ? roms[2].Length : 0, NandLength = nand?.Length ?? 0, AudioBitrate = _settings.AudioBitrate, }; if (_syncSettings.UseRealBIOS || IsDSi) { _exe.AddReadonlyFile(bios7, "bios7.rom"); _exe.AddReadonlyFile(bios9, "bios9.rom"); } if (IsDSi) { _exe.AddReadonlyFile(bios7i, "bios7i.rom"); _exe.AddReadonlyFile(bios9i, "bios9i.rom"); if (IsDSiWare) { _exe.AddReadonlyFile(roms[0], "dsiware.rom"); } } if (fw != null) { if (IsDSi || NDSFirmware.MaybeWarnIfBadFw(fw, CoreComm)) // fw checks dont work on dsi firmware, don't bother { if (_syncSettings.FirmwareOverride || lp.DeterministicEmulationRequested) { NDSFirmware.SanitizeFw(fw); } } _exe.AddReadonlyFile(fw, IsDSi ? "firmwarei.bin" : "firmware.bin"); } unsafe { fixed(byte * dsRomPtr = roms[0], gbaRomPtr = gbacartpresent?roms[1] : null, gbaRamPtr = gbasrampresent?roms[2] : null, nandPtr = nand, tmdPtr = tmd, namePtr = name, messagePtr = message) { loadData.DsRomData = (IntPtr)dsRomPtr; loadData.GbaRomData = (IntPtr)gbaRomPtr; loadData.GbaRamData = (IntPtr)gbaRamPtr; loadData.NandData = (IntPtr)nandPtr; loadData.TmdData = (IntPtr)tmdPtr; fwSettings.FirmwareUsername = (IntPtr)namePtr; fwSettings.FirmwareMessage = (IntPtr)messagePtr; if (!_core.Init(loadFlags, ref loadData, ref fwSettings)) { throw new InvalidOperationException("Init returned false!"); } } } if (fw != null) { _exe.RemoveReadonlyFile(IsDSi ? "firmwarei.bin" : "firmware.bin"); } if (IsDSi && IsDSiWare) { _exe.RemoveReadonlyFile("dsiware.rom"); } PostInit(); ((MemoryDomainList)this.AsMemoryDomains()).SystemBus = new NDSSystemBus(this.AsMemoryDomains()["ARM9 System Bus"], this.AsMemoryDomains()["ARM7 System Bus"]); DeterministicEmulation = lp.DeterministicEmulationRequested || (!_syncSettings.UseRealTime); InitializeRtc(_syncSettings.InitialTime); _frameThreadPtr = _core.GetFrameThreadProc(); if (_frameThreadPtr != IntPtr.Zero) { Console.WriteLine($"Setting up waterbox thread for 0x{_frameThreadPtr:X16}"); _frameThreadStart = CallingConventionAdapters.GetWaterboxUnsafeUnwrapped().GetDelegateForFunctionPointer <Action>(_frameThreadPtr); _core.SetThreadStartCallback(_threadstartcb); } _resampler = new SpeexResampler(SpeexResampler.Quality.QUALITY_DEFAULT, 32768, 44100, 32768, 44100, null, this); _serviceProvider.Register <ISoundProvider>(_resampler); _disassembler = new NDSDisassembler(); _serviceProvider.Register <IDisassemblable>(_disassembler); const string TRACE_HEADER = "ARM9+ARM7: PC, opcode, registers (r0, r1, r2, r3, r4, r5, r6, r7, r8, r9, r10, r11, r12, r13, r14, r15, Cy, CpuMode)"; Tracer = new TraceBuffer(TRACE_HEADER); _serviceProvider.Register(Tracer); }
void InitAudio() { resampler = new SpeexResampler(6, 64081, 88200, 32041, 44100); }
public NDS(CoreLoadParameters <NDSSettings, NDSSyncSettings> lp) : base(lp.Comm, new Configuration { DefaultWidth = 256, DefaultHeight = 384, MaxWidth = 256, MaxHeight = 384, MaxSamples = 1024, DefaultFpsNumerator = 33513982, DefaultFpsDenominator = 560190, SystemId = VSystemID.Raw.NDS, }) { var roms = lp.Roms.Select(r => r.RomData).ToList(); if (roms.Count > 3) { throw new InvalidOperationException("Wrong number of ROMs!"); } bool gbacartpresent = roms.Count > 1; bool gbasrampresent = roms.Count == 3; _tracecb = MakeTrace; _core = PreInit <LibMelonDS>(new WaterboxOptions { Filename = "melonDS.wbx", SbrkHeapSizeKB = 2 * 1024, SealedHeapSizeKB = 4, InvisibleHeapSizeKB = 4, PlainHeapSizeKB = 4, MmapHeapSizeKB = 1024 * 1024, SkipCoreConsistencyCheck = CoreComm.CorePreferences.HasFlag(CoreComm.CorePreferencesFlags.WaterboxCoreConsistencyCheck), SkipMemoryConsistencyCheck = CoreComm.CorePreferences.HasFlag(CoreComm.CorePreferencesFlags.WaterboxMemoryConsistencyCheck), }, new Delegate[] { _tracecb }); _syncSettings = lp.SyncSettings ?? new NDSSyncSettings(); _settings = lp.Settings ?? new NDSSettings(); var bios7 = _syncSettings.UseRealBIOS ? CoreComm.CoreFileProvider.GetFirmwareOrThrow(new("NDS", "bios7")) : null; var bios9 = _syncSettings.UseRealBIOS ? CoreComm.CoreFileProvider.GetFirmwareOrThrow(new("NDS", "bios9")) : null; var fw = CoreComm.CoreFileProvider.GetFirmware(new("NDS", "firmware")); bool skipfw = _syncSettings.SkipFirmware || !_syncSettings.UseRealBIOS || fw == null; LibMelonDS.LoadFlags flags = LibMelonDS.LoadFlags.NONE; if (_syncSettings.UseRealBIOS) { flags |= LibMelonDS.LoadFlags.USE_REAL_BIOS; } if (skipfw) { flags |= LibMelonDS.LoadFlags.SKIP_FIRMWARE; } if (gbacartpresent) { flags |= LibMelonDS.LoadFlags.GBA_CART_PRESENT; } if (_settings.AccurateAudioBitrate) { flags |= LibMelonDS.LoadFlags.ACCURATE_AUDIO_BITRATE; } if (_syncSettings.FirmwareOverride || lp.DeterministicEmulationRequested) { flags |= LibMelonDS.LoadFlags.FIRMWARE_OVERRIDE; } var fwSettings = new LibMelonDS.FirmwareSettings(); var name = Encoding.UTF8.GetBytes(_syncSettings.FirmwareUsername); fwSettings.FirmwareUsernameLength = name.Length; fwSettings.FirmwareLanguage = _syncSettings.FirmwareLanguage; if (_syncSettings.FirmwareStartUp == NDSSyncSettings.StartUp.AutoBoot) { fwSettings.FirmwareLanguage |= (NDSSyncSettings.Language) 0x40; } fwSettings.FirmwareBirthdayMonth = _syncSettings.FirmwareBirthdayMonth; fwSettings.FirmwareBirthdayDay = _syncSettings.FirmwareBirthdayDay; fwSettings.FirmwareFavouriteColour = _syncSettings.FirmwareFavouriteColour; var message = _syncSettings.FirmwareMessage.Length != 0 ? Encoding.UTF8.GetBytes(_syncSettings.FirmwareMessage) : new byte[1] { 0 }; fwSettings.FirmwareMessageLength = message.Length; _exe.AddReadonlyFile(roms[0], "game.rom"); if (gbacartpresent) { _exe.AddReadonlyFile(roms[1], "gba.rom"); if (gbasrampresent) { _exe.AddReadonlyFile(roms[2], "gba.ram"); } } if (_syncSettings.UseRealBIOS) { _exe.AddReadonlyFile(bios7, "bios7.rom"); _exe.AddReadonlyFile(bios9, "bios9.rom"); } if (fw != null) { if (NDSFirmware.MaybeWarnIfBadFw(fw, CoreComm)) { if (_syncSettings.FirmwareOverride || lp.DeterministicEmulationRequested) { NDSFirmware.SanitizeFw(fw); } } _exe.AddReadonlyFile(fw, "firmware.bin"); } unsafe { fixed(byte *namePtr = &name[0], messagePtr = &message[0]) { fwSettings.FirmwareUsername = (IntPtr)namePtr; fwSettings.FirmwareMessage = (IntPtr)messagePtr; if (!_core.Init(flags, fwSettings)) { throw new InvalidOperationException("Init returned false!"); } } } _exe.RemoveReadonlyFile("game.rom"); if (gbacartpresent) { _exe.RemoveReadonlyFile("gba.rom"); if (gbasrampresent) { _exe.RemoveReadonlyFile("gba.ram"); } } if (_syncSettings.UseRealBIOS) { _exe.RemoveReadonlyFile("bios7.rom"); _exe.RemoveReadonlyFile("bios9.rom"); } if (fw != null) { _exe.RemoveReadonlyFile("firmware.bin"); } PostInit(); ((MemoryDomainList)this.AsMemoryDomains()).SystemBus = new NDSSystemBus(this.AsMemoryDomains()["ARM9 System Bus"], this.AsMemoryDomains()["ARM7 System Bus"]); DeterministicEmulation = lp.DeterministicEmulationRequested || (!_syncSettings.UseRealTime); InitializeRtc(_syncSettings.InitialTime); _resampler = new SpeexResampler(SpeexResampler.Quality.QUALITY_DEFAULT, 32768, 44100, 32768, 44100, null, this); _serviceProvider.Register <ISoundProvider>(_resampler); _disassembler = new NDSDisassembler(); _serviceProvider.Register <IDisassemblable>(_disassembler); const string TRACE_HEADER = "ARM9+ARM7: PC, opcode, registers (r0, r1, r2, r3, r4, r5, r6, r7, r8, r9, r10, r11, r12, r13, r14, r15, Cy, CpuMode)"; Tracer = new TraceBuffer(TRACE_HEADER); _serviceProvider.Register <ITraceable>(Tracer); }
private void InitAudio() { _resampler = new SpeexResampler(SpeexResampler.Quality.QUALITY_DESKTOP, 64080, 88200, 32040, 44100); }
//public byte[] snes_get_memory_data_read(LibsnesApi.SNES_MEMORY id) //{ // var size = (int)api.snes_get_memory_size(id); // if (size == 0) return new byte[0]; // var ret = api.snes_get_memory_data(id); // return ret; //} private void InitAudio() { _resampler = new SpeexResampler((SpeexResampler.Quality) 6, 64081, 88200, 32041, 44100); }
public override void Dispose() { base.Dispose(); _resampler?.Dispose(); _resampler = null; }