mirror of
https://github.com/bryanthaboi/gen1recomp.git
synced 2026-08-19 20:20:19 +02:00
Merge branch 'dev' of https://github.com/bryanthaboi/gen1recomp into dev
This commit is contained in:
@@ -515,6 +515,8 @@ def patch_audio_pool_gate():
|
|||||||
"\n"
|
"\n"
|
||||||
"\tprivate:\n"
|
"\tprivate:\n"
|
||||||
"\t\tstd::atomic<bool> poolPaused;\n"
|
"\t\tstd::atomic<bool> poolPaused;\n"
|
||||||
|
"\t\tbool poolUpdating;\n"
|
||||||
|
"\t\tlove::thread::ConditionalRef poolCondition;\n"
|
||||||
"\t};\n"
|
"\t};\n"
|
||||||
)
|
)
|
||||||
if header_original not in header:
|
if header_original not in header:
|
||||||
@@ -534,6 +536,7 @@ def patch_audio_pool_gate():
|
|||||||
"\t: pool(pool)\n"
|
"\t: pool(pool)\n"
|
||||||
"\t, finish(false)\n"
|
"\t, finish(false)\n"
|
||||||
"\t, poolPaused(false)\n"
|
"\t, poolPaused(false)\n"
|
||||||
|
"\t, poolUpdating(false)\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
)
|
)
|
||||||
if ctor_original not in text:
|
if ctor_original not in text:
|
||||||
@@ -542,9 +545,25 @@ def patch_audio_pool_gate():
|
|||||||
|
|
||||||
loop_original = "\t\tpool->update();\n\t\tsleep(5);\n"
|
loop_original = "\t\tpool->update();\n\t\tsleep(5);\n"
|
||||||
loop_replacement = (
|
loop_replacement = (
|
||||||
"\t\tif (!poolPaused.load(std::memory_order_acquire))\n"
|
"\t\tbool updatePool = false;\n"
|
||||||
|
"\t\t{\n"
|
||||||
|
"\t\t\tthread::Lock lock(mutex);\n"
|
||||||
|
"\t\t\tif (!poolPaused.load(std::memory_order_acquire))\n"
|
||||||
|
"\t\t\t{\n"
|
||||||
|
"\t\t\t\tpoolUpdating = true;\n"
|
||||||
|
"\t\t\t\tupdatePool = true;\n"
|
||||||
|
"\t\t\t}\n"
|
||||||
|
"\t\t}\n"
|
||||||
|
"\n"
|
||||||
|
"\t\tif (updatePool)\n"
|
||||||
|
"\t\t{\n"
|
||||||
"\t\t\tpool->update();\n"
|
"\t\t\tpool->update();\n"
|
||||||
"\n"
|
"\n"
|
||||||
|
"\t\t\tthread::Lock lock(mutex);\n"
|
||||||
|
"\t\t\tpoolUpdating = false;\n"
|
||||||
|
"\t\t\tpoolCondition->broadcast();\n"
|
||||||
|
"\t\t}\n"
|
||||||
|
"\n"
|
||||||
"\t\tsleep(5);\n"
|
"\t\tsleep(5);\n"
|
||||||
)
|
)
|
||||||
if loop_original not in text:
|
if loop_original not in text:
|
||||||
@@ -567,7 +586,13 @@ def patch_audio_pool_gate():
|
|||||||
"\n"
|
"\n"
|
||||||
"void Audio::PoolThread::setPoolPaused(bool paused)\n"
|
"void Audio::PoolThread::setPoolPaused(bool paused)\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
|
"\tthread::Lock lock(mutex);\n"
|
||||||
"\tpoolPaused.store(paused, std::memory_order_release);\n"
|
"\tpoolPaused.store(paused, std::memory_order_release);\n"
|
||||||
|
"\tif (paused)\n"
|
||||||
|
"\t{\n"
|
||||||
|
"\t\twhile (poolUpdating)\n"
|
||||||
|
"\t\t\tpoolCondition->wait(mutex);\n"
|
||||||
|
"\t}\n"
|
||||||
"}\n"
|
"}\n"
|
||||||
)
|
)
|
||||||
if finish_original not in text:
|
if finish_original not in text:
|
||||||
@@ -629,9 +654,44 @@ IOS_AUDIO_EVENT_HELPER = """static void gr_pushAudioEvent(const char *name)
|
|||||||
msg->release();
|
msg->release();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool gr_routeRecoveryPending = false;
|
||||||
|
static unsigned int gr_routeRecoveryAttempts = 0;
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
IOS_ROUTE_CHANGE_METHOD = """
|
IOS_ROUTE_CHANGE_METHOD = """
|
||||||
|
- (void)finishAudioRouteChange
|
||||||
|
{
|
||||||
|
@synchronized (self)
|
||||||
|
{
|
||||||
|
NSError *err = nil;
|
||||||
|
if (![[AVAudioSession sharedInstance] setActive:YES error:&err])
|
||||||
|
{
|
||||||
|
NSLog(@"Error reactivating AVAudioSession: %@", [err localizedDescription]);
|
||||||
|
if (++gr_routeRecoveryAttempts < 8)
|
||||||
|
{
|
||||||
|
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.25 * NSEC_PER_SEC)),
|
||||||
|
dispatch_get_main_queue(), ^{
|
||||||
|
[self finishAudioRouteChange];
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
gr_routeRecoveryPending = false;
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
gr_routeRecoveryPending = false;
|
||||||
|
gr_routeRecoveryAttempts = 0;
|
||||||
|
auto resumed = love::Module::getInstance<love::audio::Audio>(love::Module::M_AUDIO);
|
||||||
|
if (!resumed)
|
||||||
|
return;
|
||||||
|
resumed->resumeContext();
|
||||||
|
gr_pushAudioEvent("audioreset");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
- (void)audioSessionRouteChange:(NSNotification *)note
|
- (void)audioSessionRouteChange:(NSNotification *)note
|
||||||
{
|
{
|
||||||
@synchronized (self)
|
@synchronized (self)
|
||||||
@@ -649,22 +709,24 @@ IOS_ROUTE_CHANGE_METHOD = """
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
gr_pushAudioEvent("audiosuspend");
|
if (gr_routeRecoveryPending)
|
||||||
audio->pauseContext();
|
return;
|
||||||
|
gr_routeRecoveryPending = true;
|
||||||
|
gr_routeRecoveryAttempts = 0;
|
||||||
|
|
||||||
dispatch_async(dispatch_get_main_queue(), ^{
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||||||
@synchronized (self)
|
@synchronized (self)
|
||||||
{
|
{
|
||||||
NSError *err = nil;
|
auto suspended = love::Module::getInstance<love::audio::Audio>(love::Module::M_AUDIO);
|
||||||
if (![[AVAudioSession sharedInstance] setActive:YES error:&err])
|
if (!suspended)
|
||||||
NSLog(@"Error reactivating AVAudioSession: %@", [err localizedDescription]);
|
{
|
||||||
|
gr_routeRecoveryPending = false;
|
||||||
auto resumed = love::Module::getInstance<love::audio::Audio>(love::Module::M_AUDIO);
|
return;
|
||||||
if (resumed)
|
}
|
||||||
resumed->resumeContext();
|
gr_pushAudioEvent("audiosuspend");
|
||||||
|
suspended->pauseContext();
|
||||||
gr_pushAudioEvent("audioreset");
|
|
||||||
}
|
}
|
||||||
|
[self finishAudioRouteChange];
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -693,8 +755,13 @@ def patch_ios_audio_route():
|
|||||||
listener_anchor = "@interface LoveAudioInterruptionListener : NSObject\n"
|
listener_anchor = "@interface LoveAudioInterruptionListener : NSObject\n"
|
||||||
if listener_anchor not in text:
|
if listener_anchor not in text:
|
||||||
fail(f"audio listener interface not found in {IOS_MM}")
|
fail(f"audio listener interface not found in {IOS_MM}")
|
||||||
text = text.replace(listener_anchor,
|
listener_replacement = (
|
||||||
IOS_AUDIO_EVENT_HELPER + listener_anchor, 1)
|
IOS_AUDIO_EVENT_HELPER
|
||||||
|
+ listener_anchor
|
||||||
|
+ "- (void)finishAudioRouteChange;\n"
|
||||||
|
+ "@end\n"
|
||||||
|
)
|
||||||
|
text = text.replace(listener_anchor + "@end\n", listener_replacement, 1)
|
||||||
|
|
||||||
interruption_original = (
|
interruption_original = (
|
||||||
"\t\tNSNumber *type = note.userInfo[AVAudioSessionInterruptionTypeKey];\n"
|
"\t\tNSNumber *type = note.userInfo[AVAudioSessionInterruptionTypeKey];\n"
|
||||||
|
|||||||
@@ -179,7 +179,7 @@ local function playMusicSync(data, header, allowLoops)
|
|||||||
currentMusic = { source = source, engine = engine, threaded = false,
|
currentMusic = { source = source, engine = engine, threaded = false,
|
||||||
started = true, finished = false }
|
started = true, finished = false }
|
||||||
fillSync(MUSIC_FILL_INITIAL)
|
fillSync(MUSIC_FILL_INITIAL)
|
||||||
if not musicHeld then source:play() end
|
if not musicHeld then pcall(source.play, source) end
|
||||||
return source
|
return source
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
+10
-10
@@ -165,7 +165,7 @@ local function playPath(data, key, def, pitch, tempo, plain)
|
|||||||
reportBadDef("sfx", key, owner(data, "sfx", key), err)
|
reportBadDef("sfx", key, owner(data, "sfx", key), err)
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
s:setVolume(volumeFor(key))
|
pcall(s.setVolume, s, volumeFor(key))
|
||||||
cache[key] = s
|
cache[key] = s
|
||||||
src = s
|
src = s
|
||||||
end
|
end
|
||||||
@@ -619,12 +619,12 @@ function Sound.playPikaCry(data, n)
|
|||||||
-- extractPikachuCries); widenMono re-decodes to 16-bit stereo so they
|
-- extractPikachuCries); widenMono re-decodes to 16-bit stereo so they
|
||||||
-- stay off surround outputs (#626). Fresh extracts are already stereo.
|
-- stay off surround outputs (#626). Fresh extracts are already stereo.
|
||||||
s = widenMono(s, path)
|
s = widenMono(s, path)
|
||||||
s:setVolume(volumeFor(key))
|
pcall(s.setVolume, s, volumeFor(key))
|
||||||
cache[key] = s
|
cache[key] = s
|
||||||
src = s
|
src = s
|
||||||
end
|
end
|
||||||
src:stop()
|
pcall(src.stop, src)
|
||||||
src:play()
|
pcall(src.play, src)
|
||||||
played("cry", "PIKACHU_PCM_" .. n, "PIKACHU")
|
played("cry", "PIKACHU_PCM_" .. n, "PIKACHU")
|
||||||
return src
|
return src
|
||||||
end
|
end
|
||||||
@@ -659,12 +659,12 @@ function Sound.playCry(data, species, pikaClip)
|
|||||||
owner(data, "cries", species), err)
|
owner(data, "cries", species), err)
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
s:setVolume(volumeFor(key))
|
pcall(s.setVolume, s, volumeFor(key))
|
||||||
cache[key] = s
|
cache[key] = s
|
||||||
src = s
|
src = s
|
||||||
end
|
end
|
||||||
src:stop()
|
pcall(src.stop, src)
|
||||||
src:play()
|
pcall(src.play, src)
|
||||||
played("cry", species, species)
|
played("cry", species, species)
|
||||||
return src
|
return src
|
||||||
end
|
end
|
||||||
@@ -734,12 +734,12 @@ function Sound.startLoop(data, name)
|
|||||||
reportBadDef("sfx", name, owner(data, "sfx", name), err or "no source")
|
reportBadDef("sfx", name, owner(data, "sfx", name), err or "no source")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
s:setLooping(true)
|
pcall(s.setLooping, s, true)
|
||||||
s:setVolume(volumeFor(name))
|
pcall(s.setVolume, s, volumeFor(name))
|
||||||
loopCache[name] = s
|
loopCache[name] = s
|
||||||
src = s
|
src = s
|
||||||
end
|
end
|
||||||
src:play()
|
pcall(src.play, src)
|
||||||
looping[name] = src
|
looping[name] = src
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user