-
Notifications
You must be signed in to change notification settings - Fork 0
/
DJAudioPlayer.h
117 lines (90 loc) · 3.88 KB
/
DJAudioPlayer.h
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/*
* DJAudioPlayer class
*
* handles playback of audio files
*
*/
#pragma once
#include <JuceHeader.h>
class DJAudioPlayer : public AudioSource {
public:
/** Consttructor for DJAudioPlayer
* @param _formatManager - the format manager to use */
DJAudioPlayer(AudioFormatManager& _formatManager);
/** Destructor for DJAudioPlayer */
~DJAudioPlayer();
/** Tells the source to prepare for playing
* @param samplesPerBlockExpected - number of samples expected each time getNextAudioBlock() called
* @param sampleRate - the sample rate */
void prepareToPlay (int samplesPerBlockExpected, double sampleRate) override;
/** Called repeatedly to fetch subsequent blocks of audio data
* @param bufferToFill */
void getNextAudioBlock (const juce::AudioSourceChannelInfo& bufferToFill) override;
/** Allows the source to release anything it no longer needs after playback has stopped */
void releaseResources() override;
/** loads a given audio URL
* @param audioURL - an audio file URL*/
void loadURL(URL audioURL);
/** sets the gain for the player
* @param gain - gain as double */
void setGain(double gain);
/** sets the speed for the player
* @param ratio - speed ratio as double */
void setSpeed(double ratio);
/** sets the position
* @param posInSecs -double position in seconds*/
void setPosition(double posInSecs);
/** sets the relative position
* @param pos - double relative position*/
void setPositionRelative(double pos);
/** start the transport source */
void start();
/** stop the transport source */
void stop();
/** Get the relative position of the playhead
* @return double - relative position */
double getPositionRelative();
/** get the current track title
* @return String - current track title */
std::string getCurrentTrack();
/** set the current track title
* @param String - current track title */
void setCurrentTrack(std::string title);
/** get the current track sample rate
* @return int - current sample rate */
int getCurrentSampleRate();
/** set the current track sample rate
* @param int - sample rate */
void setCurrentSampleRate(int sampleRate);
/** toggles looping playback */
void toggleLoop();
/** checks if the transport source is playing
* @return bool */
bool isPlaying();
/** checks if the transport source is looping
* @return bool */
bool isLooping();
/** checks if the transport source has finished
* @return bool */
bool playbackFinished();
/** sets coefficients for the HighPass filter
* @param coefficients - IIRCoefficients object */
void setHighPassCoefficients(IIRCoefficients coefficients);
/** sets coefficients for the LowPass filter
* @param coefficients - IIRCoefficients object */
void setLowPassCoefficients(IIRCoefficients coefficients);
/** deactivates given filter
* @param filter - filter name as string */
void deactivateFilter(std::string filter);
private:
AudioFormatManager& formatManager;
std::unique_ptr<AudioFormatReaderSource> readerSource;
AudioTransportSource transportSource;
ResamplingAudioSource resampleSource{&transportSource, false, 2};
// Filters
IIRFilterAudioSource filter1{&resampleSource, false};
IIRFilterAudioSource filter2{&filter1, false};
std::string currentTrack;
int currentSampleRate;
bool looping = false;
};