33
44#include < chrono>
55
6+ #include " xstudio/audio/enums.hpp"
67#include " xstudio/media_reader/media_reader.hpp"
78#include " xstudio/module/module.hpp"
89#include " xstudio/utility/chrono.hpp"
@@ -13,6 +14,43 @@ namespace xstudio::audio {
1314
1415enum AudioBehaviourOnSilence { StopPushingSamplesOnSilence, ContinuePushingSamplesOnSilence };
1516
17+
18+ static inline std::map<std::string, ScrubBehaviour> scrubBehaviourMap = {
19+ {" 1 Frame" , OneFrame},
20+ {" 1.25 Frames" , OnePt25Frames},
21+ {" 1.5 Frames" , OnePt5Frames},
22+ {" 2 Frames" , TwoFrames},
23+ {" 3 Frames" , ThreeFrames},
24+ {" 1/24th Sec" , OneFrameAt24Fps},
25+ {" 1/30th Sec" , OneFrameAt30Fps},
26+ {" 1/60th Sec" , OneFrameAt60Fps},
27+ {" Custom Duration" , Custom},
28+ };
29+
30+ struct ScrubHelper {
31+
32+ ScrubHelper () = default ;
33+
34+ void set_custom_duration_ms (const int ms) {
35+ scrub_window_millisecs_ = ms;
36+ }
37+ void set_behaviour (const std::string &behaviour) {
38+ const auto p = scrubBehaviourMap.find (behaviour);
39+ if (p != scrubBehaviourMap.end ()) scrub_behaviour_= p->second ;
40+ else scrub_behaviour_ = ScrubBehaviour::OneFrame;
41+ }
42+
43+ timebase::flicks scrub_duration (const utility::FrameRate & media_rate) const ;
44+ double scrub_duration_secs (const utility::FrameRate & media_rate) const {
45+ return timebase::to_seconds (scrub_duration (media_rate));
46+ }
47+
48+ private:
49+ int scrub_window_millisecs_ = {50 };
50+ ScrubBehaviour scrub_behaviour_ = {OneFrame};
51+
52+ };
53+
1654/* *
1755 * @brief Class for delivering audio to soundcard by maintaining a smoothed
1856 * measurment of the playhead position and re-sampling audio sources as
@@ -22,6 +60,8 @@ enum AudioBehaviourOnSilence { StopPushingSamplesOnSilence, ContinuePushingSampl
2260class AudioOutputControl {
2361
2462 public:
63+
64+
2565 /* *
2666 * @brief Constructor
2767 *
@@ -55,13 +95,14 @@ class AudioOutputControl {
5595 * @brief The audio volume (range is 0-100)
5696 */
5797 [[nodiscard]] float volume () const {
58- return override_volume_ == -1 .0f ? volume_ : override_volume_;
98+ return (override_volume_ == -1 .0f ? volume_ : override_volume_) * playhead_volume_ /
99+ 100 .0f ;
59100 }
60101
61102 /* *
62103 * @brief The audio volume muted
63104 */
64- [[nodiscard]] bool muted () const { return muted_; }
105+ [[nodiscard]] bool muted () const { return override_volume_ == - 1 . 0f ? muted_ : false ; }
65106
66107 /* *
67108 * @brief Queue audio buffer for streaming to the soundcard
@@ -81,6 +122,8 @@ class AudioOutputControl {
81122 */
82123 void playhead_position_changed (
83124 const timebase::flicks playhead_position,
125+ const timebase::flicks playhead_loop_in,
126+ const timebase::flicks playhead_loop_out,
84127 const bool forward,
85128 const float velocity,
86129 const bool playing,
@@ -101,11 +144,15 @@ class AudioOutputControl {
101144 const float volume,
102145 const bool muted,
103146 const bool audio_repitch,
104- const bool audio_scrubbing) {
105- volume_ = volume;
106- muted_ = muted;
107- audio_repitch_ = audio_repitch;
108- audio_scrubbing_ = audio_scrubbing;
147+ const bool audio_scrubbing,
148+ const std::string & scrub_behaviour,
149+ const int scrub_window_millisecs) {
150+ volume_ = volume;
151+ muted_ = muted;
152+ audio_repitch_ = audio_repitch;
153+ audio_scrubbing_ = audio_scrubbing;
154+ scrub_helper_.set_behaviour (scrub_behaviour);
155+ scrub_helper_.set_custom_duration_ms (scrub_window_millisecs);
109156 }
110157
111158 void set_override_volume (const float override_volume) {
@@ -138,6 +185,8 @@ class AudioOutputControl {
138185 int fade_in_out_ = {NoFade};
139186
140187 timebase::flicks playhead_position_;
188+ timebase::flicks playhead_loop_in_ = {timebase::flicks (std::numeric_limits<timebase::flicks::rep>::lowest ())};
189+ timebase::flicks playhead_loop_out_ = {timebase::flicks (std::numeric_limits<timebase::flicks::rep>::max ())};
141190 bool playing_forward_ = {true };
142191 utility::time_point playhead_position_update_tp_;
143192 timebase::flicks last_buffer_pts_;
@@ -148,8 +197,11 @@ class AudioOutputControl {
148197 bool muted_ = {false };
149198 bool playing_ = {false };
150199 float override_volume_ = {-1 .0f };
200+ float playhead_volume_ = {100 .0f };
151201 float last_volume_ = {100 .0f };
152202 float scrub_chunk_duration_frames_ = {1 .0f };
153203 bool apply_global_volume_ = {true };
204+
205+ ScrubHelper scrub_helper_;
154206};
155207} // namespace xstudio::audio
0 commit comments