Audacity 3.2.0
ClipMirAudioReader.cpp
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 ClipMirAudioReader.h
7
8 Matthieu Hodgkinson
9
10**********************************************************************/
11#include "ClipMirAudioReader.h"
12#include "ClipInterface.h"
13#include "WaveClip.h"
14
15#include <cassert>
16
18 std::optional<LibFileFormats::AcidizerTags> tags, std::string filename,
19 WaveTrack& singleClipWaveTrack)
20 : tags { std::move(tags) }
21 , filename { std::move(filename) }
22 , clip(*singleClipWaveTrack.Intervals().begin())
23 , mClip(singleClipWaveTrack.GetClipInterfaces()[0])
24{
25}
26
28{
29 return mClip->GetRate();
30}
31
33{
34 return mClip->GetVisibleSampleCount().as_long_long();
35}
36
38 float* buffer, long long where, size_t numFrames) const
39{
40 std::fill(buffer, buffer + numFrames, 0.f);
41 AddChannel(0, buffer, where, numFrames);
42 if (mClip->NChannels() == 1)
43 return;
44 AddChannel(1, buffer, where, numFrames);
45 std::transform(
46 buffer, buffer + numFrames, buffer, [](float f) { return f / 2; });
47}
48
50 size_t iChannel, float* buffer, sampleCount start, size_t len) const
51{
52 constexpr auto mayThrow = false;
53 const auto iCache = mUseFirst[iChannel] ? 0 : 1;
54 auto& cache = mCache[iChannel][iCache];
55 auto view = mClip->GetSampleView(iChannel, start, len, mayThrow);
56 cache.emplace(std::move(view));
57 cache->AddTo(buffer, len);
59}
double GetSampleRate() const override
const std::shared_ptr< const ClipInterface > mClip
void AddChannel(size_t iChannel, float *buffer, sampleCount start, size_t len) const
ClipMirAudioReader(std::optional< LibFileFormats::AcidizerTags > tags, std::string filename, WaveTrack &singleClipWaveTrack)
long long GetNumSamples() const override
std::array< bool, 2 > mUseFirst
std::array< ChannelCache, 2 > mCache
void ReadFloats(float *buffer, long long where, size_t numFrames) const override
A Track that contains audio waveform data.
Definition: WaveTrack.h:203
Positions or offsets within audio files need a wide type.
Definition: SampleCount.h:19
const char * begin(const char *str) noexcept
Definition: StringUtils.h:101
STL namespace.