Make playback and recording stereo; add per-head delay balance

- fillBlock now outputs interleaved stereo; AudioTrack and native Oboe
  configured for 2 channels; MasterRecorder writes a stereo WAV.
- AudioEffect gains processStereo() (default mono-collapse); the tape delay
  overrides it to pan each of its 4 heads with a level-preserving linear pan
  (feedback still uses the mono sum, so loop behaviour is unchanged).
- New per-head balance param + a horizontal balance slider under each head's
  division fader (center-detented, L/C/R readout), with a revision read so it
  redraws.

Note: only the delay produces stereo width; other insert effects stay mono
and collapse upstream stereo, so place the delay last to keep its panning.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Reactorcoremeltdown
2026-07-16 15:55:33 +02:00
co-authored by Claude Opus 4.8
parent 3a752b88ab
commit c630dc3694
6 changed files with 165 additions and 60 deletions
+10 -8
View File
@@ -75,16 +75,17 @@ public:
JNIEnv *env = callbackEnv();
if (!env || !g_callback || !g_renderMethod || !g_buffer) {
for (int i = 0; i < numFrames; ++i) out[i] = 0.0f;
for (int i = 0; i < numFrames * 2; ++i) out[i] = 0.0f; // stereo silence
return oboe::DataCallbackResult::Continue;
}
const int n = numFrames < g_frames ? numFrames : g_frames;
// Ask Kotlin to render n frames into the reused Java buffer ...
// Ask Kotlin to render n frames; fillBlock writes 2*n interleaved-stereo
// samples into the reused Java buffer ...
env->CallVoidMethod(g_callback, g_renderMethod, g_buffer, n);
// ... then copy them out to Oboe (and pad any remainder with silence — the
// Java buffer is sized to the stream capacity, so this should not trigger).
env->GetFloatArrayRegion(g_buffer, 0, n, out);
for (int i = n; i < numFrames; ++i) out[i] = 0.0f;
// ... then copy them out to Oboe (2 samples/frame) and pad any remainder with
// silence (the Java buffer is sized to the stream capacity, so rare).
env->GetFloatArrayRegion(g_buffer, 0, n * 2, out);
for (int i = n * 2; i < numFrames * 2; ++i) out[i] = 0.0f;
// Adaptive buffer sizing (timing path): a callback that renders slower than
// its deadline will drain the buffer; a couple in a row means we're about to
@@ -177,7 +178,7 @@ bool openAndStartStream() {
->setPerformanceMode(oboe::PerformanceMode::LowLatency)
->setSharingMode(oboe::SharingMode::Shared)
->setFormat(oboe::AudioFormat::Float)
->setChannelCount(oboe::ChannelCount::Mono)
->setChannelCount(oboe::ChannelCount::Stereo)
->setSampleRate(g_sampleRate)
->setDataCallback(&g_dataCallback)
->setErrorCallback(&g_errorCallback);
@@ -225,7 +226,8 @@ Java_com_reactorcoremeltdown_sizzletracker_audio_NativeAudioBridge_nativeStart(
// min(numFrames, g_frames) frames, and low-latency bursts are far smaller.
g_frames = kMaxBufferFrames;
if (g_frames < framesPerCallback) g_frames = framesPerCallback;
g_buffer = static_cast<jfloatArray>(env->NewGlobalRef(env->NewFloatArray(g_frames)));
// Interleaved stereo: 2 samples per frame.
g_buffer = static_cast<jfloatArray>(env->NewGlobalRef(env->NewFloatArray(g_frames * 2)));
if (!openAndStartStream()) {
env->DeleteGlobalRef(g_buffer);