-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGrainPlayer.hpp
63 lines (51 loc) · 1.52 KB
/
GrainPlayer.hpp
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
#pragma once
#include <stdint.h>
#include <stdlib.h>
#include <boost/intrusive/list.hpp>
#include "Grain.hpp"
#include "fabricMaths.hpp"
#include "LinearSmoother.h"
#define MAX_GRAINS 128
struct GrainPlayerControl
{
float scanSpeed = 1.f;
float spray = 0.01f;
float density = 0.01f;
float length = 0.01f;
float gainSpray = 0.f;
float direction = 1.0f;
float pitch = 1.f;
float pitchSpray = 0.f;
float stereoWidth = 1.f;
float panSpray = 1.f;
float sides = 0.5f;
float tilt = 0.f;
float playHeadPos = 0.f;
float sampleRate = 44100.f;
};
class GrainPlayer
{
public:
using GrainList = boost::intrusive::list<Grain>;
Grain grainArray[MAX_GRAINS];
GrainList grains_used;
GrainList grains_free;
GrainPlayer();
virtual ~GrainPlayer();
void generate(float** outputs, float** st_audioBuffer, int bufferSize, uint32_t frames);
GrainPlayerControl controls;
private:
uint32_t _frames;
int _nextGrainTime = {0};
int _bufferSize = {0};
bool addGrain(int currentFrame);
void generateSubdivision(float** outputs, float** st_audioBuffer, int bufferSize, uint32_t subdivStart, uint32_t subdivFrames);
void processSmoothers(uint32_t frames);
fabricMaths::fast_rand m_seed;
fabricMaths::fast_real_distribution<float> m_fRandomNormalized;
fabricMaths::fast_real_distribution<float> m_fRandomBiPolNormalized;
LinearSmoother m_pitchSmooth;
float * m_pitchSmoothData;
LinearSmoother m_lengthSmooth;
float * m_lengthSmoothData;
};