Audacity 3.2.0
WaveChannelUtilities.h
Go to the documentation of this file.
1/* SPDX-License-Identifier: GPL-2.0-or-later */
2/*!********************************************************************
3
4 Audacity: A Digital Audio Editor
5
6 WaveChannelUtilities.h
7
8 Paul Licameli
9
10 @brief Various operations on WaveChannel, needing only its public interface
11
12**********************************************************************/
13#ifndef __AUDACITY_WAVE_CHANNEL_UTILITIES__
14#define __AUDACITY_WAVE_CHANNEL_UTILITIES__
15
16class Envelope;
17enum class PlaybackDirection;
18enum class sampleFormat : unsigned;
19class WaveChannel;
20class WaveClipChannel;
21
22#include <algorithm>
23#include <functional>
24#include <memory>
25#include <utility>
26#include <vector>
27
29
31using ClipPointer = std::shared_ptr<Clip>;
32using ClipPointers = std::vector<ClipPointer>;
33using ClipConstPointer = std::shared_ptr<const Clip>;
34using ClipConstPointers = std::vector<ClipConstPointer>;
35
36WAVE_TRACK_API
37bool CompareClipsByPlayStartTime(const Clip &x, const Clip &y);
38
40 const ClipConstPointer x, const ClipConstPointer y)
41{
42 return CompareClipsByPlayStartTime(*x, *y);
43}
44
45inline bool IsSortedByPlayStartTime(const ClipPointers &clips)
46{
47 return is_sorted(
48 clips.begin(), clips.end(), CompareClipPointersByPlayStartTime);
49}
50
52{
53 return is_sorted(
54 clips.begin(), clips.end(), CompareClipPointersByPlayStartTime);
55}
56
58WAVE_TRACK_API ClipPointers SortedClipArray(WaveChannel &channel);
59
63WAVE_TRACK_API ClipConstPointers SortedClipArray(const WaveChannel &channel);
64
67WAVE_TRACK_API ClipPointer GetClipAtTime(WaveChannel &channel, double time);
68
72WAVE_TRACK_API
73ClipConstPointer GetClipAtTime(const WaveChannel &channel, double time);
74
75WAVE_TRACK_API Envelope* GetEnvelopeAtTime(WaveChannel &channel, double time);
76
81WAVE_TRACK_API std::pair<float, float> GetMinMax(const WaveChannel &channel,
82 double t0, double t1, bool mayThrow = true);
83
87WAVE_TRACK_API float GetRMS(const WaveChannel &channel,
88 double t0, double t1, bool mayThrow = true);
89
100WAVE_TRACK_API std::pair<size_t, size_t>
102 double t, float* buffer, size_t numSideSamples,
103 bool mayThrow);
104
108WAVE_TRACK_API bool GetFloatAtTime(const WaveChannel &channel,
109 double t, float& value, bool mayThrow);
110
114WAVE_TRACK_API bool GetFloatAtTime(const Clip &clip,
115 double t, float& value, bool mayThrow);
116
123WAVE_TRACK_API void SetFloatsCenteredAroundTime(WaveChannel &channel,
124 double t, const float* buffer, size_t numSideSamples,
125 sampleFormat effectiveFormat);
126
131WAVE_TRACK_API void SetFloatAtTime(WaveChannel &channel,
132 double t, float value, sampleFormat effectiveFormat);
133
141WAVE_TRACK_API void SetFloatsWithinTimeRange(WaveChannel &channel,
142 double t0, double t1,
143 const std::function<float(double sampleTime)>& producer,
144 sampleFormat effectiveFormat);
145
153WAVE_TRACK_API size_t GetFloatsFromTime(const WaveChannel &channel,
154 double t, float* buffer, size_t numSamples,
155 bool mayThrow, PlaybackDirection direction);
156
162WAVE_TRACK_API void SetFloatsFromTime(WaveChannel &channel,
163 double t, const float* buffer, size_t numSamples,
164 sampleFormat effectiveFormat, PlaybackDirection direction);
165
170WAVE_TRACK_API void SetFloatsFromTime(Clip &channel,
171 double t, const float* buffer, size_t numSamples,
172 sampleFormat effectiveFormat, PlaybackDirection direction);
173
179WAVE_TRACK_API
181 const Clip& clip, PlaybackDirection searchDirection);
182
187WAVE_TRACK_API ClipPointer GetAdjacentClip(const ClipPointers &clips,
188 const Clip& clip, PlaybackDirection searchDirection);
189
194WAVE_TRACK_API ClipConstPointer GetNextClip(const ClipConstPointers &clips,
195 const Clip& clip, PlaybackDirection searchDirection);
196
200WAVE_TRACK_API ClipPointer GetNextClip(const ClipPointers &clips,
201 const Clip& clip, PlaybackDirection searchDirection);
202
203WAVE_TRACK_API ClipPointer GetIntervalAtTime(WaveChannel &channel, double t);
204}
205
206#endif
PlaybackDirection
sampleFormat
The ordering of these values with operator < agrees with the order of increasing bit width.
Definition: SampleFormat.h:30
Piecewise linear or piecewise exponential function from double to double.
Definition: Envelope.h:72
bool CompareClipPointersByPlayStartTime(const ClipConstPointer x, const ClipConstPointer y)
WAVE_TRACK_API void SetFloatsCenteredAroundTime(WaveChannel &channel, double t, const float *buffer, size_t numSideSamples, sampleFormat effectiveFormat)
Similar to GetFloatsCenteredAroundTime, but for writing. Sets as many samples as it can according to ...
std::vector< ClipPointer > ClipPointers
WAVE_TRACK_API std::pair< float, float > GetMinMax(const WaveChannel &channel, double t0, double t1, bool mayThrow=true)
bool IsSortedByPlayStartTime(const ClipPointers &clips)
WAVE_TRACK_API ClipPointer GetIntervalAtTime(WaveChannel &channel, double t)
std::shared_ptr< const Clip > ClipConstPointer
std::vector< ClipConstPointer > ClipConstPointers
WAVE_TRACK_API bool CompareClipsByPlayStartTime(const Clip &x, const Clip &y)
WAVE_TRACK_API void SetFloatsWithinTimeRange(WaveChannel &channel, double t0, double t1, const std::function< float(double sampleTime)> &producer, sampleFormat effectiveFormat)
Provides a means of setting clip values as a function of time. Included are closest sample to t0 up t...
WAVE_TRACK_API float GetRMS(const WaveChannel &channel, double t0, double t1, bool mayThrow=true)
std::shared_ptr< Clip > ClipPointer
WAVE_TRACK_API std::pair< size_t, size_t > GetFloatsCenteredAroundTime(const WaveChannel &channel, double t, float *buffer, size_t numSideSamples, bool mayThrow)
Gets as many samples as it can, but no more than 2 * numSideSamples + 1, centered around t....
WAVE_TRACK_API void SetFloatsFromTime(WaveChannel &channel, double t, const float *buffer, size_t numSamples, sampleFormat effectiveFormat, PlaybackDirection direction)
Similar to GetFloatsFromTime, but for writing. Sets as many samples as it can according to the same r...
WAVE_TRACK_API size_t GetFloatsFromTime(const WaveChannel &channel, double t, float *buffer, size_t numSamples, bool mayThrow, PlaybackDirection direction)
Helper for GetFloatsCenteredAroundTime. If direction == PlaybackDirection::Backward,...
WAVE_TRACK_API ClipPointer GetClipAtTime(WaveChannel &channel, double time)
WAVE_TRACK_API ClipConstPointer GetAdjacentClip(const ClipConstPointers &clips, const Clip &clip, PlaybackDirection searchDirection)
Similar to GetNextClip, but returns nullptr if the neighbour clip is not adjacent.
WAVE_TRACK_API bool GetFloatAtTime(const WaveChannel &channel, double t, float &value, bool mayThrow)
WAVE_TRACK_API Envelope * GetEnvelopeAtTime(WaveChannel &channel, double time)
WAVE_TRACK_API void SetFloatAtTime(WaveChannel &channel, double t, float value, sampleFormat effectiveFormat)
Sets sample nearest to t to value. Silently fails if GetClipAtTime(t) == nullptr.
WAVE_TRACK_API ClipPointers SortedClipArray(WaveChannel &channel)
Get clips sorted by play start time.
WAVE_TRACK_API ClipConstPointer GetNextClip(const ClipConstPointers &clips, const Clip &clip, PlaybackDirection searchDirection)
Returns clips next to clip in the given direction, or nullptr if there is none.