Audio experiments

This commit is contained in:
2026-05-05 12:18:42 +10:00
parent f836c53d10
commit 9a8748687a
6 changed files with 719 additions and 80 deletions

View File

@@ -57,11 +57,13 @@
#include "RuntimeHost.h"
#include <atomic>
#include <condition_variable>
#include <cstdint>
#include <functional>
#include <map>
#include <memory>
#include <mutex>
#include <thread>
#include <vector>
#include <deque>
@@ -101,6 +103,8 @@ public:
void VideoFrameArrived(IDeckLinkVideoInputFrame* inputFrame, bool hasNoInputSource);
void AudioPacketArrived(IDeckLinkAudioInputPacket* audioPacket);
HRESULT RenderAudioSamples(BOOL preroll);
HRESULT ScheduleAudioToWaterLevel();
void AudioSchedulingLoop();
void PlayoutFrameCompleted(IDeckLinkVideoFrame* completedFrame, BMDOutputFrameCompletionResult result);
private:
@@ -124,7 +128,7 @@ private:
BMDTimeValue mFrameDuration;
BMDTimeScale mFrameTimescale;
unsigned mTotalPlayoutFrames;
uint64_t mNextAudioSampleFrame;
uint64_t mAudioOutputSampleTime;
unsigned mInputFrameWidth;
unsigned mInputFrameHeight;
unsigned mOutputFrameWidth;
@@ -166,11 +170,34 @@ private:
std::unique_ptr<ControlServer> mControlServer;
std::unique_ptr<OscServer> mOscServer;
bool mAudioEnabled;
bool mAudioOutputEnabled;
bool mAudioScheduleEnabled;
bool mAudioPrerollEnabled;
bool mAudioScheduleSilence;
bool mAudioScheduleTone;
bool mAudioPrerolling;
std::atomic<bool> mAudioSchedulerRunning;
std::atomic<bool> mPlayoutCallbackActive;
std::thread mAudioSchedulerThread;
std::mutex mAudioStateMutex;
AudioDelayBuffer mAudioDelayBuffer;
std::mutex mAudioAnalyzerMutex;
AudioAnalyzer mAudioAnalyzer;
AudioAnalysisSnapshot mAudioAnalysis;
struct TimestampedAudioPacket
{
AudioFrameBlock block;
std::vector<int32_t> scheduledOutputSamples;
BMDTimeValue streamTime = 0;
};
std::deque<TimestampedAudioPacket> mAudioPacketQueue;
std::deque<TimestampedAudioPacket> mScheduledAudioPacketRetainQueue;
std::deque<int32_t> mAudioSampleQueue;
std::condition_variable mAudioPacketQueued;
unsigned mQueuedAudioSampleFrames = 0;
uint64_t mAudioUnderrunCount = 0;
uint64_t mAudioToneSampleIndex = 0;
bool mHasFirstAudioPacketTime = false;
BMDTimeValue mFirstAudioPacketTime = 0;
struct LayerProgram
{
@@ -224,8 +251,7 @@ private:
bool PollRuntimeChanges();
void broadcastRuntimeState();
void initializeAudioDelay();
unsigned delayedAudioSampleFrames() const;
AudioFrameBlock popAudioForVideoFrame(uint64_t videoFrameIndex);
BMDTimeValue delayedAudioStreamTime() const;
void updateAudioDataTexture(const AudioAnalysisSnapshot& analysis);
void updateAudioStatus();
bool updateGlobalParamsBuffer(const RuntimeRenderState& state, unsigned availableSourceHistoryLength, unsigned availableTemporalHistoryLength);