Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding audio to video rendering #256

Open
wants to merge 31 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
ff5c1f0
Basic video rendering with audio
HolgerFoerterer Apr 2, 2023
dd95a97
Fixed playback rounding error
HolgerFoerterer Apr 2, 2023
8b5d05b
Testing at 48kHz
HolgerFoerterer Apr 2, 2023
5b39556
Adaptive sample rate, using record method to avoid update on FFT readout
HolgerFoerterer Apr 2, 2023
2f11a0b
Clearing buffers after recording
HolgerFoerterer Apr 2, 2023
314079a
Trying out BASS_DATA_NOREMOVE for FFT
HolgerFoerterer Apr 2, 2023
4c20e28
Re-established live mode behavior of FFTs
HolgerFoerterer Apr 2, 2023
d939ec4
Fixed clearing of audio fifo buffers
HolgerFoerterer Apr 2, 2023
42c8e6a
Changed sample frame rate to reflect last frame timing
HolgerFoerterer Apr 2, 2023
45363b2
Changed FFT update on recording to only trigger when new audio data i…
HolgerFoerterer Apr 2, 2023
c96f56b
Intermediate version (start of record buffer is still wrong)
HolgerFoerterer Apr 5, 2023
b558903
Fixed audio offset and buffer clearing
HolgerFoerterer Apr 5, 2023
9ba6438
Removed clicking at the end of recording
HolgerFoerterer Apr 5, 2023
489a79e
Approaching a final version, switched to MP3 audio encoding for now
HolgerFoerterer Apr 15, 2023
2b1890c
Playback speed changed back to 1.0 for recording
HolgerFoerterer Apr 15, 2023
be48ee8
Click issue?
HolgerFoerterer Apr 15, 2023
f76fb9b
Trying another method of playback
HolgerFoerterer Apr 15, 2023
f31ea29
Readressing timing, playing and pausing of sources plus buffer sizes
HolgerFoerterer Apr 15, 2023
477be8a
Test: Audio more exact?
HolgerFoerterer Apr 15, 2023
45ff2d1
Test: shorten the audio buffer later on
HolgerFoerterer Apr 15, 2023
1582346
Doubled timings...
HolgerFoerterer Apr 15, 2023
4db7379
Last buffer change for today
HolgerFoerterer Apr 15, 2023
55dce97
Changed moment of setting bpm for video recording
HolgerFoerterer Apr 28, 2023
8d7c513
Forcing time update on new render and saving more of the bass state o…
HolgerFoerterer Apr 29, 2023
6585395
Changed buffer size and refactored Bass initialization
HolgerFoerterer Apr 29, 2023
8da9590
Corrected audio frame shift
HolgerFoerterer Apr 29, 2023
963a171
Removed debug message
HolgerFoerterer Apr 29, 2023
7f204b3
Added some hints and cleaning up audio buffers when rendering image s…
HolgerFoerterer Apr 29, 2023
51e768d
Refactoring, bug fixes: progress, buffer sizes and wave tail
HolgerFoerterer May 8, 2023
702173b
Bugfix: Correct amount of frames
HolgerFoerterer May 8, 2023
519b88a
Merge branch 'dev' into audio-engine
pixtur May 29, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 46 additions & 17 deletions Core/Animation/Playback.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,55 +18,78 @@ namespace T3.Core.Animation
/// - Time is used for all UI interactions and everything that is driven by keyframes.
///
/// RunTime is the time since application.
/// IsLive is true if we are playing live, false if we are rendering
/// </summary>
public class Playback
{
public Playback()
public Playback()
{
_isLive = true;
Current = this;
}

public static Playback Current { get; set; }
public PlaybackSettings Settings { get; set; }

/// <summary>
/// The absolute current time as controlled by the timeline interaction in bars.
/// </summary>
public virtual double TimeInBars { get; set; }

/// <summary>
/// The current time used for animation (would advance from <see cref="TimeInBars"/> if Idle Motion is enabled.
/// </summary>
public double FxTimeInBars { get; protected set; }

/// <summary>
/// Convenience function to convert from internal TimeInBars mapped to seconds for current BPM.
/// </summary>
public double TimeInSecs { get => TimeInBars * 240 / Bpm;
set => TimeInBars = value * Bpm / 240f; }
public double TimeInSecs { get => TimeInBars * 240 / Bpm;
set => TimeInBars = value * Bpm / 240; }

public TimeRange LoopRange;

public double Bpm { get; set; } = 120;

public double Bpm = 120;
public bool IsLive
{
get => _isLive;
set {
_isLive = value;
if (value)
{
PlaybackSpeed = 0;
_lastFrameStart = RunTimeInSecs;
}
else
{
_lastFrameStart = TimeInSecs;
}
}
}

public double PlaybackSpeed { get; set; }
public bool IsLooping = false;

public static double RunTimeInSecs => _runTimeWatch.Elapsed.TotalSeconds;
public static double RunTimeInSecs => _runTimeWatch.Elapsed.TotalSeconds;
public static double LastFrameDuration { get; private set; }
public double LastFrameDurationInBars => BarsFromSeconds(LastFrameDuration);

public virtual void Update(bool idleMotionEnabled = false)
{
Current = this;
var currentRuntime = RunTimeInSecs;
// if we are not live, TimeInBars is provided externally
var currentRuntime = (IsLive) ? RunTimeInSecs : TimeInSecs;

LastFrameDuration = currentRuntime - _lastFrameStart;
_lastFrameStart = currentRuntime;

var timeSinceLastFrameInSecs = LastFrameDuration;
var isPlaying = Math.Abs(PlaybackSpeed) > 0.001;

if (isPlaying)
if (!IsLive)
{
FxTimeInBars = TimeInBars;
}
else if (isPlaying)
{
TimeInBars += timeSinceLastFrameInSecs * PlaybackSpeed * Bpm / 240.0;
FxTimeInBars = TimeInBars;
Expand All @@ -84,11 +107,16 @@ public virtual void Update(bool idleMotionEnabled = false)
}
}

if (IsLooping && TimeInBars > LoopRange.End)
// don't support looping if recording (looping sound is not implemented yet)
if (IsLive && IsLooping && TimeInBars > LoopRange.End)
{
TimeInBars = TimeInBars - LoopRange.End > 1.0 // Jump to start if too far out of time region
? LoopRange.Start
: TimeInBars - (LoopRange.End - LoopRange.Start);
double loopDuration = LoopRange.End - LoopRange.Start;

// Jump to start if loop is negative or sound is too far out of time region
if (loopDuration <= 0 || TimeInBars - LoopRange.End > 1.0)
TimeInBars = LoopRange.Start;
else
TimeInBars -= loopDuration;
}

_previousTime = TimeInBars;
Expand All @@ -107,5 +135,6 @@ public double SecondsFromBars(double bars)
private static double _lastFrameStart;
private double _previousTime;
private static readonly Stopwatch _runTimeWatch = Stopwatch.StartNew();
private bool _isLive;
}
}
Loading