-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Expand file tree
/
Copy pathenginebufferscalerubberband.h
More file actions
88 lines (67 loc) · 3.13 KB
/
enginebufferscalerubberband.h
File metadata and controls
88 lines (67 loc) · 3.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#pragma once
#include <rubberband/RubberBandStretcher.h>
#include <array>
#include <memory>
#include "engine/bufferscalers/enginebufferscale.h"
#include "engine/bufferscalers/rubberbandwrapper.h"
#include "util/samplebuffer.h"
class ReadAheadManager;
// Uses librubberband to scale audio. This class is not thread safe.
class EngineBufferScaleRubberBand final : public EngineBufferScale {
Q_OBJECT
public:
explicit EngineBufferScaleRubberBand(
ReadAheadManager* pReadAheadManager);
EngineBufferScaleRubberBand(const EngineBufferScaleRubberBand&) = delete;
EngineBufferScaleRubberBand& operator=(const EngineBufferScaleRubberBand&) = delete;
EngineBufferScaleRubberBand(EngineBufferScaleRubberBand&&) = delete;
EngineBufferScaleRubberBand& operator=(EngineBufferScaleRubberBand&&) = delete;
// Let EngineBuffer know if engine v3 is available
static bool isEngineFinerAvailable();
// Enable engine v3 if available
void useEngineFiner(bool enable);
void setScaleParameters(double base_rate,
double* pTempoRatio,
double* pPitchRatio) override;
double scaleBuffer(
CSAMPLE* pOutputBuffer,
SINT iOutputBufferSize) override;
// Flush buffer.
void clear() override;
private:
// Reset RubberBand library with new audio signal
void onSignalChanged() override;
/// Calls `m_pRubberBand->getPreferredStartPad()`, with backwards
/// compatibility for older librubberband versions.
size_t getPreferredStartPad() const;
/// Calls `m_pRubberBand->getStartDelay()`, with backwards compatibility for
/// older librubberband versions.
size_t getStartDelay() const;
int runningEngineVersion();
/// Reset the rubberband instance and run the prerequisite amount of padding
/// through it. This should be used instead of calling
/// `m_pRubberBand->reset()` directly.
void reset();
void deinterleaveAndProcess(const CSAMPLE* pBuffer, SINT frames);
SINT retrieveAndDeinterleave(CSAMPLE* pBuffer, SINT frames);
// The read-ahead manager that we use to fetch samples
ReadAheadManager* m_pReadAheadManager;
RubberBandWrapper m_rubberBand;
/// The audio buffers samples used to send audio to Rubber Band and to
/// receive processed audio from Rubber Band. This is needed because Mixxx
/// uses interleaved buffers in most other places.
std::vector<mixxx::SampleBuffer> m_buffers;
/// These point to the buffers in `m_buffers`. They can be defined here
/// since this object cannot be moved or copied.
std::vector<float*> m_bufferPtrs;
/// Contains interleaved samples read from `m_pReadAheadManager`. These need
/// to be deinterleaved before they can be passed to Rubber Band.
mixxx::SampleBuffer m_interleavedReadBuffer;
// Holds the playback direction
bool m_bBackwards;
/// The amount of silence padding that still needs to be dropped from the
/// retrieve samples in `retrieveAndDeinterleave()`. See the `reset()`
/// function for an explanation.
SINT m_remainingPaddingInOutput = 0;
bool m_useEngineFiner;
};