-
Notifications
You must be signed in to change notification settings - Fork 2
/
audio_engine.cpp
91 lines (74 loc) · 2.1 KB
/
audio_engine.cpp
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
89
90
91
/*
==============================================================================
AudioEngine.cpp
Created: 1 Sep 2021 6:24:22pm
Author: Thomas Hézard
==============================================================================
*/
#include "audio_engine.h"
#include <cassert>
#include <cstring>
AudioEngine::~AudioEngine()
{
destroy_audio_processor(audio_processor_);
audio_processor_ = nullptr;
}
AudioEngine::AudioEngine() : audio_processor_{nullptr}, parameter_a_{0.0f}, parameter_b_{0.0f}
{
audio_processor_ = new_audio_processor();
player_.didPlay = [&]() {
if (didPlay != nullptr)
didPlay();
};
player_.didStop = [&]() {
if (didStop != nullptr)
didStop();
};
}
void AudioEngine::prepareResources(int maxSamplesPerBlock, double sampleRate)
{
player_.prepareResources(maxSamplesPerBlock, sampleRate);
prepare_audio_processor(audio_processor_);
}
void AudioEngine::releaseResources()
{
player_.releaseResources();
}
void AudioEngine::generateAudioData(float *const*outputAudioData, int outputNumChannels, int numSamples)
{
assert(outputNumChannels == 2);
player_.generateAudioData(outputAudioData, outputNumChannels, numSamples);
for (int i = 0; i<numSamples; ++i) {
outputAudioData[0][i] = sqrtf(2.0f) / 2.0f * (outputAudioData[0][i] + outputAudioData[1][i]);
}
ap_process(audio_processor_, outputAudioData[0], outputAudioData[0], numSamples);
memcpy(outputAudioData[1], outputAudioData[0], numSamples*sizeof(float));
}
void AudioEngine::Load(const juce::File &file)
{
player_.Load(file);
}
void AudioEngine::Play()
{
player_.Play();
}
void AudioEngine::Stop()
{
player_.Stop();
}
void AudioEngine::setParameterA(float parameter)
{
parameter_a_ = parameter;
}
float AudioEngine::getParameterA() const
{
return parameter_a_;
}
void AudioEngine::setParameterB(float parameter)
{
parameter_b_ = parameter;
}
float AudioEngine::getParameterB() const
{
return parameter_b_;
}