DaisySP
Loading...
Searching...
No Matches
granularplayer.h
1/*
2Copyright (c) 2020 Electrosmith, Corp, Vinícius Fernandes
3
4Use of this source code is governed by an MIT-style
5license that can be found in the LICENSE file or at
6https://opensource.org/licenses/MIT.
7*/
8
9#pragma once
10#ifndef DSY_GRANULARPLAYER_H
11#define DSY_GRANULARPLAYER_H
12
13#include <stdint.h>
14#include <cmath>
15#include "Control/phasor.h"
16#ifdef __cplusplus
17#ifndef M_PI
18#define M_PI 3.14159265358979323846 /* pi */
19#endif
20
21namespace daisysp
22{
35{
36 public:
39
45 void Init(float* sample, int size, float sample_rate);
46
52 float Process(float speed, float transposition, float grain_size);
53
54 private:
55 //Wraps an index to the size of the sample array
56 uint32_t WrapIdx(uint32_t idx, uint32_t size);
57
58 //Converts cents(1/100th of a semitone) to a ratio
59 float CentsToRatio(float cents);
60
61 //Converts milliseconds to number of samples
62 float MsToSamps(float ms, float samplerate);
63
64 //Inverts the phase of the phasor if the frequency is negative, mimicking pure data's phasor~ object
65 float NegativeInvert(Phasor* phs, float frequency);
66
67
68 float* sample_; //pointer to the sample to be played
69 float sample_rate_; //audio engine sample rate
70 int size_; //number of elements in the sample array
71 float grain_size_; //grain size in milliseconds
72 float speed_; //processed playback speed.
73 float transposition_; //processed transpotion.
74 float sample_frequency_;
75 float cosEnv_[256] = {0}; //cosine envelope for crossfading between grains
76 float
77 idxTransp_; // Adjusted Transposition value contribution to idx of first grain
78 float
79 idxTransp2_; // Adjusted Transposition value contribution to idx of second grain
80 float idxSpeed_; // Adjusted Speed value contribution to idx of first grain
81 float
82 idxSpeed2_; // Adjusted Speed value contribution to idx of second grain
83 float sig_; // Output of first grain
84 float sig2_; // Output of second grain
85
86 uint32_t idx_; // Index of first grain
87 uint32_t idx2_; // Index of second grain
88
89 Phasor phs_; // Phasor for speed
90 Phasor phsImp_; // Phasor for transposition
91 Phasor phs2_; // Phasor for speed
92 Phasor phsImp2_; // Phasor for transposition
93};
94} // namespace daisysp
95#endif
96#endif
Definition granularplayer.h:35
void Init(float *sample, int size, float sample_rate)
Definition granularplayer.cpp:5
float Process(float speed, float transposition, float grain_size)
Definition granularplayer.cpp:56
Definition phasor.h:23
FIR Filter implementation, generic and ARM CMSIS DSP based.
Definition adenv.h:16