- Three source trees: core/ (shared C++ engine, moved from ios/core), app/ (Android UI), ios/app/ (iOS UI) - Android plays through core/ via JNI (EngineHost, jni_engine.cpp): the Oboe callback renders natively; the Kotlin model is mirrored as project text and applied as a diff, so playback continues through edits - The Kotlin engine moves to the unit tests as ReferenceEngine (golden reference) - Shared MasterRecorder in core/src/host, used by both apps; host_test - versions.properties: one versionName/versionCode for both platforms, continuing Android's numbering (iOS 0.6.0/11 -> 0.37.0/71) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
55 lines
1.8 KiB
C++
55 lines
1.8 KiB
C++
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
// The engine's MasterSink as a WAV writer (MasterRecorder.kt): the audio thread
|
|
// writes interleaved stereo floats into a single-producer/single-consumer ring
|
|
// (about two seconds), a writer thread drains it into a 16-bit stereo WAV at
|
|
// [path] and patches the header sizes at the end. No allocation, locks or I/O on
|
|
// the audio thread. Used by both apps' engine hosts.
|
|
|
|
#pragma once
|
|
|
|
#include <atomic>
|
|
#include <cstdint>
|
|
#include <cstdio>
|
|
#include <functional>
|
|
#include <string>
|
|
#include <thread>
|
|
#include <vector>
|
|
|
|
#include "sizzle/Engine.hpp"
|
|
|
|
namespace sizzle::host {
|
|
|
|
class MasterRecorder final : public engine::MasterSink {
|
|
public:
|
|
explicit MasterRecorder(int sampleRate);
|
|
~MasterRecorder() override;
|
|
|
|
/** Where the next take is written (set before arming). */
|
|
void setPath(std::string path) { path_ = std::move(path); }
|
|
/** Called when a take starts capturing (the thread that started it: main or MIDI). */
|
|
std::function<void()> onStarted;
|
|
/** Called on the writer thread when the file is finished: its path, or "" when
|
|
* writing failed, and the take's start in milliseconds since the epoch. */
|
|
std::function<void(const std::string &path, int64_t startMillis)> onFinished;
|
|
|
|
bool isActive() const override { return active_.load(); }
|
|
bool begin() override;
|
|
void write(float left, float right) override;
|
|
void endCapture() override { capturing_.store(false); }
|
|
|
|
private:
|
|
bool writeLoop(const std::string &path);
|
|
void writeHeader(FILE *f, uint64_t sampleCount);
|
|
|
|
const int sr_;
|
|
std::vector<float> ring_;
|
|
std::string path_;
|
|
std::atomic<uint64_t> writePos_{0}, readPos_{0};
|
|
std::atomic<bool> capturing_{false}, active_{false};
|
|
std::thread writer_;
|
|
};
|
|
|
|
} // namespace sizzle::host
|