OSSIA
Open Scenario System for Interactive Application
Loading...
Searching...
No Matches
sound_impl.hpp
1#pragma once
2#include <ossia/dataflow/audio_stretch_mode.hpp>
3#include <ossia/dataflow/nodes/timestretch/raw_stretcher.hpp>
4#include <ossia/dataflow/nodes/timestretch/repitch_stretcher.hpp>
5#include <ossia/dataflow/nodes/timestretch/rubberband_stretcher.hpp>
6#include <ossia/detail/variant.hpp>
7
8namespace ossia
9{
10struct resampler
11{
12 void reset(
13 time_value date, ossia::audio_stretch_mode mode, std::size_t channels,
14 std::size_t fileSampleRate)
15 {
16 // TODO use the date parameter to buffer ! else transport won't work
17 switch(mode)
18 {
19 case audio_stretch_mode::None: {
20 if(auto s = ossia::get_if<ossia::raw_stretcher>(&m_stretch))
21 {
22 s->next_sample_to_read = date.impl;
23 }
24 else
25 {
26 m_stretch.emplace<raw_stretcher>(date.impl);
27 }
28 break;
29 }
30 case audio_stretch_mode::Repitch:
31 case audio_stretch_mode::RepitchMediumQ:
32 case audio_stretch_mode::RepitchFastestQ: {
33 if(auto s = ossia::get_if<ossia::repitch_stretcher>(&m_stretch);
34 s && s->repitchers.size() == channels)
35 {
36 s->next_sample_to_read = date.impl;
37 }
38 else
39 {
40 m_stretch.emplace<repitch_stretcher>(
41 get_samplerate_preset(mode), channels, 1024, date.impl);
42 }
43 break;
44 }
45 case audio_stretch_mode::RubberBandStandard:
46 case audio_stretch_mode::RubberBandPercussive:
47 case ossia::audio_stretch_mode::RubberBandStandardHQ:
48 case ossia::audio_stretch_mode::RubberBandPercussiveHQ: {
49 m_stretch.emplace<rubberband_stretcher>(
50 get_rubberband_preset(mode), channels, fileSampleRate, date.impl);
51 break;
52 }
53 }
54 }
55
56 template <typename T>
57 void
58 run(T& audio_fetcher, const ossia::token_request& t, ossia::exec_state_facade e,
59 double tempo_ratio, std::size_t chan, std::size_t len, int64_t samples_to_read,
60 int64_t samples_to_write, int64_t samples_offset, ossia::audio_port& ap)
61 {
62 ossia::visit([&](auto& stretcher) {
63 stretcher.run(
64 audio_fetcher, t, e, tempo_ratio, chan, len, samples_to_read, samples_to_write,
65 samples_offset, ap);
66 });
67 }
68
69 ossia::variant<raw_stretcher, rubberband_stretcher, repitch_stretcher> m_stretch;
70};
71
72}
Definition git_info.h:7