forked from sin365/AxibugEmuOnline
优化音频读取方式
This commit is contained in:
parent
66f0cc5bd7
commit
aad4c1775a
@ -323,6 +323,10 @@ PrefabInstance:
|
||||
propertyPath: m_LocalEulerAnglesHint.z
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 4232056521131536012, guid: f8bea3f8aa351bb46ada33b2274729ea, type: 3}
|
||||
propertyPath: RomName
|
||||
value: tortoise4.nes
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 4232056521131536013, guid: f8bea3f8aa351bb46ada33b2274729ea, type: 3}
|
||||
propertyPath: m_Name
|
||||
value: NesEmulator
|
||||
|
@ -1,6 +1,4 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using UnityEngine;
|
||||
using UnityEngine;
|
||||
using VirtualNes.Core;
|
||||
|
||||
namespace AxibugEmuOnline.Client
|
||||
@ -8,12 +6,13 @@ namespace AxibugEmuOnline.Client
|
||||
|
||||
public class AudioProvider : MonoBehaviour
|
||||
{
|
||||
public NesEmulator NesEmu;
|
||||
|
||||
[SerializeField]
|
||||
private AudioSource m_as;
|
||||
|
||||
private SoundBuffer _buffer = new SoundBuffer(4096);
|
||||
|
||||
public void Initialize()
|
||||
public void Start()
|
||||
{
|
||||
var dummy = AudioClip.Create("dummy", 1, 1, AudioSettings.outputSampleRate, false);
|
||||
|
||||
@ -28,7 +27,9 @@ namespace AxibugEmuOnline.Client
|
||||
{
|
||||
int step = channels;
|
||||
|
||||
var bufferCount = _buffer.Available();
|
||||
if (NesEmu == null || NesEmu.NesCore == null) return;
|
||||
|
||||
ProcessSound(NesEmu.NesCore, (uint)(data.Length / channels));
|
||||
|
||||
for (int i = 0; i < data.Length; i += step)
|
||||
{
|
||||
@ -43,9 +44,9 @@ namespace AxibugEmuOnline.Client
|
||||
}
|
||||
}
|
||||
|
||||
public void ProcessSound(NES nes)
|
||||
void ProcessSound(NES nes, uint feedCount)
|
||||
{
|
||||
nes.apu.Process(_buffer, (uint)(Supporter.Config.sound.nRate * Time.deltaTime));
|
||||
nes.apu.Process(_buffer, feedCount);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -9,15 +9,24 @@ namespace AxibugEmuOnline.Client
|
||||
{
|
||||
public class NesEmulator : MonoBehaviour
|
||||
{
|
||||
private NES m_nesIns;
|
||||
public NES NesCore { get; private set; }
|
||||
|
||||
public VideoProvider VideoProvider;
|
||||
public AudioProvider AudioProvider;
|
||||
|
||||
#if UNITY_EDITOR
|
||||
public string RomName;
|
||||
#endif
|
||||
|
||||
private void Start()
|
||||
{
|
||||
Application.targetFrameRate = 60;
|
||||
StartGame("ff1.nes");
|
||||
VideoProvider.NesEmu = this;
|
||||
AudioProvider.NesEmu = this;
|
||||
|
||||
#if UNITY_EDITOR
|
||||
StartGame(RomName);
|
||||
#endif
|
||||
}
|
||||
|
||||
public void StartGame(string romName)
|
||||
@ -29,32 +38,30 @@ namespace AxibugEmuOnline.Client
|
||||
|
||||
try
|
||||
{
|
||||
m_nesIns = new NES(romName);
|
||||
NesCore = new NES(romName);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
m_nesIns = null;
|
||||
NesCore = null;
|
||||
Debug.LogError(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public void StopGame()
|
||||
{
|
||||
m_nesIns?.Dispose();
|
||||
m_nesIns = null;
|
||||
NesCore?.Dispose();
|
||||
NesCore = null;
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (m_nesIns != null)
|
||||
if (NesCore != null)
|
||||
{
|
||||
m_nesIns.EmulateFrame(true);
|
||||
NesCore.EmulateFrame(true);
|
||||
|
||||
var screenBuffer = m_nesIns.ppu.GetScreenPtr();
|
||||
var lineColorMode = m_nesIns.ppu.GetLineColorMode();
|
||||
var screenBuffer = NesCore.ppu.GetScreenPtr();
|
||||
var lineColorMode = NesCore.ppu.GetLineColorMode();
|
||||
VideoProvider.SetDrawData(screenBuffer, lineColorMode, 256, 240);
|
||||
|
||||
AudioProvider.ProcessSound(m_nesIns);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -10,7 +10,7 @@ GameObject:
|
||||
m_Component:
|
||||
- component: {fileID: 4785916497946256520}
|
||||
- component: {fileID: 9003897287163669553}
|
||||
- component: {fileID: 7558824780418593440}
|
||||
- component: {fileID: 8726979175317618791}
|
||||
m_Layer: 0
|
||||
m_Name: AudioProvider
|
||||
m_TagString: Untagged
|
||||
@ -44,8 +44,8 @@ MonoBehaviour:
|
||||
m_Script: {fileID: 11500000, guid: a6a09b6a4cf4c2d4f994a13fd7e89d6f, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
m_as: {fileID: 7558824780418593440}
|
||||
--- !u!82 &7558824780418593440
|
||||
m_as: {fileID: 8726979175317618791}
|
||||
--- !u!82 &8726979175317618791
|
||||
AudioSource:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
@ -158,7 +158,7 @@ GameObject:
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
m_IsActive: 0
|
||||
--- !u!224 &1038087993597378172
|
||||
RectTransform:
|
||||
m_ObjectHideFlags: 0
|
||||
@ -407,6 +407,7 @@ MonoBehaviour:
|
||||
m_EditorClassIdentifier:
|
||||
VideoProvider: {fileID: 4232056520112715744}
|
||||
AudioProvider: {fileID: 9003897287163669553}
|
||||
RomName:
|
||||
--- !u!1 &4232056521759880276
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
@ -495,7 +496,7 @@ GameObject:
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
m_IsActive: 0
|
||||
--- !u!4 &393435831810118449
|
||||
Transform:
|
||||
m_ObjectHideFlags: 0
|
||||
|
@ -7,6 +7,8 @@ namespace AxibugEmuOnline.Client
|
||||
{
|
||||
public class VideoProvider : MonoBehaviour
|
||||
{
|
||||
public NesEmulator NesEmu;
|
||||
|
||||
public RawImage Image;
|
||||
|
||||
private UInt32[] wrapTexBuffer;
|
||||
|
@ -82,7 +82,7 @@ PlayerSettings:
|
||||
androidFullscreenMode: 1
|
||||
defaultIsNativeResolution: 1
|
||||
macRetinaSupport: 1
|
||||
runInBackground: 0
|
||||
runInBackground: 1
|
||||
captureSingleScreen: 0
|
||||
muteOtherAudioSources: 0
|
||||
Prepare IOS For Recording: 0
|
||||
|
Loading…
Reference in New Issue
Block a user