Anklang-0.3.0.dev956+gd75ac925 anklang-0.3.0.dev956+gd75ac925
ASE — Anklang Sound Engine (C++)

« « « Anklang Documentation
Loading...
Searching...
No Matches
transport.hh
Go to the documentation of this file.
1 // This Source Code Form is licensed MPL-2.0: http://mozilla.org/MPL/2.0
2#pragma once
3
4#include <ase/defs.hh>
5
6namespace Ase {
7
11 NONE = 0,
12 FRONT_LEFT = 0x1,
13 FRONT_RIGHT = 0x2,
14 FRONT_CENTER = 0x4,
15 LOW_FREQUENCY = 0x8,
16 BACK_LEFT = 0x10,
17 BACK_RIGHT = 0x20,
18 // WAV reserved = 0xyyy00000,
19 AUX = uint64_t (1) << 63,
21 STEREO = FRONT_LEFT | FRONT_RIGHT,
22 STEREO_21 = STEREO | LOW_FREQUENCY,
23 STEREO_30 = STEREO | FRONT_CENTER,
24 STEREO_31 = STEREO_30 | LOW_FREQUENCY,
25 SURROUND_50 = STEREO_30 | BACK_LEFT | BACK_RIGHT,
26 SURROUND_51 = SURROUND_50 | LOW_FREQUENCY,
27#if 0 // TODO: dynamic multichannel support
28 FRONT_LEFT_OF_CENTER = 0x40,
29 FRONT_RIGHT_OF_CENTER = 0x80,
30 BACK_CENTER = 0x100,
31 SIDE_LEFT = 0x200,
32 SIDE_RIGHT = 0x400,
33 TOP_CENTER = 0x800,
34 TOP_FRONT_LEFT = 0x1000,
35 TOP_FRONT_CENTER = 0x2000,
36 TOP_FRONT_RIGHT = 0x4000,
37 TOP_BACK_LEFT = 0x8000,
38 TOP_BACK_CENTER = 0x10000,
39 TOP_BACK_RIGHT = 0x20000,
40 SIDE_SURROUND_50 = STEREO_30 | SIDE_LEFT | SIDE_RIGHT,
41 SIDE_SURROUND_51 = SIDE_SURROUND_50 | LOW_FREQUENCY,
42#endif
43};
44constexpr SpeakerArrangement speaker_arrangement_channels_mask { ~size_t (SpeakerArrangement::AUX) };
45uint8 speaker_arrangement_count_channels (SpeakerArrangement spa);
46SpeakerArrangement speaker_arrangement_channels (SpeakerArrangement spa);
47bool speaker_arrangement_is_aux (SpeakerArrangement spa);
48const char* speaker_arrangement_bit_name (SpeakerArrangement spa);
49std::string speaker_arrangement_desc (SpeakerArrangement spa);
50
52constexpr const int64 TRANSPORT_PPQN = 4838400; // Ticks per quarter note
53constexpr const int64 SEMIQUAVER_TICKS = TRANSPORT_PPQN / 4; // 1209600 = PPQN * 4 / 16;
54constexpr const int64 MIN_BPM = 10;
55constexpr const int64 MAX_BPM = 1776;
56constexpr const int64 MIN_SAMPLERATE = 8000;
57constexpr const int64 MAX_SAMPLERATE = 192000;
58
61protected:
62 static constexpr const int64 offset_ = 0; // currently unused
65 int32 beat_ticks_ = 0;
66 int32 bar_ticks_ = 0;
68 double bpm_ = 0;
69 int64 ticks_per_minute_ = 0;
70 double ticks_per_second_ = 0;
71 double inv_ticks_per_second_ = 0;
72 double ticks_per_sample_ = 0;
73 double sample_per_ticks_ = 0;
75public:
76 struct Beat {
77 int32 bar = 0;
78 int8 beat = 0;
79 double semiquaver = 0;
80 };
81 struct Time {
83 double seconds = 0;
84 };
85 double samplerate () const { return samplerate_; }
86 double inv_samplerate () const { return inv_samplerate_; }
87 double ticks_per_sample () const { return ticks_per_sample_; }
88 int64 sample_to_tick (int64 sample) const;
89 int64 sample_from_tick (int64 tick) const;
90 double bpm () const { return bpm_; }
91 int32 bar_ticks () const { return bar_ticks_; }
92 int32 beat_ticks () const { return beat_ticks_; }
93 int64 start_offset () const { return offset_; }
94 void set_samplerate (uint samplerate);
95 void set_bpm (double bpm);
96 Time time_from_tick (int64 tick) const;
97 int64 time_to_tick (const Time &time) const;
98 bool set_signature (uint8 beats_per_bar, uint8 beat_unit);
99 const uint8& beats_per_bar () const { return beats_per_bar_; }
100 const uint8& beat_unit () const { return beat_unit_; }
101 int32 bar_from_tick (int64 tick) const;
102 int64 bar_to_tick (int32 bar) const;
103 Beat beat_from_tick (int64 tick) const;
104 int64 beat_to_tick (const Beat &beat) const;
105 /*dflt*/ TickSignature ();
106 /*ctor*/ TickSignature (double bpm, uint8 beats_per_bar, uint8 beat_unit);
107 /*copy*/ TickSignature (const TickSignature &other);
108 TickSignature& operator= (const TickSignature &src);
109};
110
113 static constexpr int64 ppqn = TRANSPORT_PPQN;
115 const uint nyquist;
116 const double isamplerate;
117 const double inyquist;
119 // uint32 gap
120 TickSignature tick_sig;
122 int64 current_tick = 0;
123 __attribute__ ((aligned (64))) // align memory for project telemetry fields
124 double current_tick_d = 0;
128 float current_bpm = 0;
130 double current_seconds = 0;
131 int64 current_bar_tick = 0;
132 int64 next_bar_tick = 0;
133 bool running () const { return current_bpm != 0; }
134 void running (bool r);
135 void tempo (double newbpm, uint8 newnumerator, uint8 newdenominator);
136 void tempo (const TickSignature &ticksignature);
137 void set_tick (int64 newtick);
138 void set_beat (TickSignature::Beat b);
139 void advance (uint nsamples);
140 void update_current ();
141 explicit AudioTransport (SpeakerArrangement speakerarrangement, uint samplerate);
142 int64 sample_to_tick (int64 sample) const { return tick_sig.sample_to_tick (sample); }
143 int64 sample_from_tick (int64 tick) const { return tick_sig.sample_from_tick (tick); }
144};
145
146// == Implementations ==
147inline int64
148TickSignature::sample_to_tick (int64 sample) const
149{
150 return ticks_per_sample_ * sample;
151}
152
153inline int64
154TickSignature::sample_from_tick (int64 tick) const
155{
156 return sample_per_ticks_ * tick;
157}
158
159} // Ase
160
The Anklang C++ API namespace.
Definition api.hh:8
int32_t int32
A 32-bit signed integer.
Definition cxxaux.hh:27
SpeakerArrangement
Flags to indicate channel arrangements of a bus.
Definition transport.hh:10
@ FRONT_LEFT
Stereo Left (FL)
@ FRONT_RIGHT
Stereo Right (FR)
@ AUX
Flag for side chain uses.
@ LOW_FREQUENCY
Low Frequency Effects (LFE)
@ MONO
Single Channel (M)
uint8_t uint8
An 8-bit unsigned integer.
Definition cxxaux.hh:21
int8_t int8
An 8-bit signed integer.
Definition cxxaux.hh:25
int64_t int64
A 64-bit unsigned integer, use PRI*64 in format strings.
Definition cxxaux.hh:28
constexpr const int64 TRANSPORT_PPQN
Maximum number of sample frames to calculate in Processor::render().
Definition transport.hh:52
uint32_t uint
Provide 'uint' as convenience type.
Definition cxxaux.hh:17
T sample(T... args)
typedef uint64_t
Transport information for AudioSignal processing.
Definition transport.hh:112
int32 current_bar
Bar of current_tick position.
Definition transport.hh:125
double current_semiquaver
The sixteenth with fraction within beat.
Definition transport.hh:127
const uint nyquist
Half the samplerate.
Definition transport.hh:115
const uint samplerate
Sample rate (mixing frequency) in Hz used for rendering.
Definition transport.hh:114
const double isamplerate
Precalculated 1.0 / samplerate.
Definition transport.hh:116
double current_seconds
Seconds of current_tick position.
Definition transport.hh:130
int64 current_frame
Number of sample frames processed since playback start.
Definition transport.hh:121
int8 current_beat
Beat within bar of current_tick position.
Definition transport.hh:126
float current_bpm
Running tempo in beats per minute.
Definition transport.hh:128
int32 current_minutes
Minute of current_tick position.
Definition transport.hh:129
const double inyquist
Precalculated 1.0 / nyquist.
Definition transport.hh:117
const SpeakerArrangement speaker_arrangement
Audio output configuration.
Definition transport.hh:118
Musical time signature and tick conversions.
Definition transport.hh:60
double seconds
Seconds with fraction after the minute.
Definition transport.hh:83
Beat beat_from_tick(int64 tick) const
Calculate beat from tick, requires set_signature().
Definition transport.cc:112
int64 bar_to_tick(int32 bar) const
Calculate tick from bar, requires set_signature().
Definition transport.cc:143
double bpm_
Current tempo in beats per minute.
Definition transport.hh:68
void set_samplerate(uint samplerate)
Assign sample rate.
Definition transport.cc:47
uint8 beats_per_bar_
Upper numeral (numerator), how many beats constitute a bar.
Definition transport.hh:63
uint8 beat_unit_
Lower numeral (denominator in [1 2 4 8 16]), note value that represents one beat.
Definition transport.hh:64
double inv_samplerate_
Precalculated 1.0 / samplerate.
Definition transport.hh:74
int32 minutes
Tick position in minutes.
Definition transport.hh:82
int32 samplerate_
Sample rate (mixing frequency) in Hz.
Definition transport.hh:67
int64 time_to_tick(const Time &time) const
Calculate tick from time, requires set_bpm().
Definition transport.cc:85
int32 bar
Bar of tick position.
Definition transport.hh:77
int64 beat_to_tick(const Beat &beat) const
Calculate tick from beat, requires set_signature().
Definition transport.cc:125
double semiquaver
The sixteenth with fraction within beat.
Definition transport.hh:79
Time time_from_tick(int64 tick) const
Calculate time from tick, requires set_bpm().
Definition transport.cc:74
bool set_signature(uint8 beats_per_bar, uint8 beat_unit)
Assign time signature and offset for the signature to take effect.
Definition transport.cc:95
int32 bar_from_tick(int64 tick) const
Calculate bar from tick, requires set_signature().
Definition transport.cc:136
void set_bpm(double bpm)
Assign tempo in beats per minute.
Definition transport.cc:59
int8 beat
Beat within bar of tick position.
Definition transport.hh:78