This commit is contained in:
Demur Rumed 2025-07-04 06:30:32 +00:00
commit 49a1d62009
4 changed files with 20 additions and 20 deletions

View file

@ -15,20 +15,20 @@ extern bool freezeGame;
bool SfxExtractor::isAllSilence(int16_t* buffer, size_t count) { bool SfxExtractor::isAllSilence(int16_t* buffer, size_t count) {
for (size_t i = 0; i < count; i++) { for (size_t i = 0; i < count; i++) {
if (!isSilentSample(buffer[i]))//Tolerance for low-amplitude dither noise. if (!isSilentSample(buffer[i])) // Tolerance for low-amplitude dither noise.
return false; return false;
} }
return true; return true;
} }
bool SfxExtractor::isSilentSample(int16_t sample) { bool SfxExtractor::isSilentSample(int16_t sample) {
return abs(sample) <= SFX_EXTRACTION_SILENCE_THRESHOLD; return abs(sample) <= SFX_EXTRACTION_SILENCE_THRESHOLD;
} }
// Find the beginning of a captured signal. // Find the beginning of a captured signal.
size_t SfxExtractor::adjustedStartOfInput() { size_t SfxExtractor::adjustedStartOfInput() {
size_t startOfInput = 0; size_t startOfInput = 0;
while (startOfInput + 2 < SFX_EXTRACTION_BUFFER_SIZE * 2 && isSilentSample(tempBuffer[startOfInput]) && isSilentSample(tempBuffer[startOfInput + 1])) { while (startOfInput + 2 < SFX_EXTRACTION_BUFFER_SIZE * 2 && isSilentSample(tempBuffer[startOfInput]) &&
isSilentSample(tempBuffer[startOfInput + 1])) {
startOfInput += 2; startOfInput += 2;
} }
return startOfInput; return startOfInput;
@ -93,9 +93,9 @@ void SfxExtractor::setup() {
} }
void SfxExtractor::ripNextSfx() { void SfxExtractor::ripNextSfx() {
//This entire method is expected to be atomic; Don't try to narrow the scope of this lock please! // This entire method is expected to be atomic; Don't try to narrow the scope of this lock please!
//Todo: remove the thread altogether as we don't actually need or want parallelism here. // Todo: remove the thread altogether as we don't actually need or want parallelism here.
auto lock = OTRAudio_Lock(); auto lock = OTRAudio_Lock();
if (captureThreadState == CT_READY || captureThreadState == CT_PRIMING) if (captureThreadState == CT_READY || captureThreadState == CT_PRIMING)
return; // Keep going. return; // Keep going.
// Was the last sfx a loop? If so then we need to stop it, and then we need to run audio out to nowhere for as long // Was the last sfx a loop? If so then we need to stop it, and then we need to run audio out to nowhere for as long
@ -168,10 +168,11 @@ void SfxExtractor::frameCallback() {
} }
void SfxExtractor::prime() { void SfxExtractor::prime() {
int frameLimit = 0;//A couple of sounds don't come to a full stop until another sound is loaded, but should be effectively silent after a couple of seconds. int frameLimit = 0; // A couple of sounds don't come to a full stop until another sound is loaded, but should be
// effectively silent after a couple of seconds.
do { do {
AudioMgr_CreateNextAudioBuffer(tempBuffer + 0, SFX_EXTRACTION_ONE_FRAME); AudioMgr_CreateNextAudioBuffer(tempBuffer + 0, SFX_EXTRACTION_ONE_FRAME);
} while (frameLimit ++ < 200 && !isAllSilence(tempBuffer + 0, SFX_EXTRACTION_ONE_FRAME * 2)); } while (frameLimit++ < 200 && !isAllSilence(tempBuffer + 0, SFX_EXTRACTION_ONE_FRAME * 2));
captureThreadState = CT_FINISHED; captureThreadState = CT_FINISHED;
} }

View file

@ -3,8 +3,7 @@
#define SFX_EXTRACTION_BUFFER_SIZE 32000 * 15 #define SFX_EXTRACTION_BUFFER_SIZE 32000 * 15
#define SFX_EXTRACTION_ONE_FRAME 560 #define SFX_EXTRACTION_ONE_FRAME 560
#define SFX_EXTRACTION_SILENCE_THRESHOLD 6//Corresponds to an amplitude of -75dB. #define SFX_EXTRACTION_SILENCE_THRESHOLD 6 // Corresponds to an amplitude of -75dB.
enum CaptureThreadStates { enum CaptureThreadStates {
CT_WAITING, // for a sound to start ripping. CT_WAITING, // for a sound to start ripping.