-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathMixingIO.cpp
107 lines (86 loc) · 2.72 KB
/
MixingIO.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
//
// Created by asalehin on 9/9/20.
//
#include "MixingIO.h"
#include "../utils/Utils.h"
MixingIO::MixingIO() {
Player* player = new Player();
mPlayer.reset(move(player));
}
shared_ptr<FileDataSource> MixingIO::readFile(string filename, int fd) {
AudioProperties targetProperties{
.channelCount = MixingStreamConstants::mChannelCount,
.sampleRate = MixingStreamConstants::mSampleRate
};
return shared_ptr<FileDataSource> {
FileDataSource::newFromCompressedFile(filename.c_str(), fd, targetProperties),
[](FileDataSource *source) {
delete source;
}
};
}
shared_ptr<BufferedDataSource> MixingIO::createClipboardDataSource(vector<float>& clipboard) {
AudioProperties targetProperties{
.channelCount = MixingStreamConstants::mChannelCount,
.sampleRate = MixingStreamConstants::mSampleRate
};
return shared_ptr<BufferedDataSource> {
BufferedDataSource::newFromClipboard(clipboard, targetProperties),
[](BufferedDataSource *source) {
delete source;
}
};
}
void MixingIO::setPlaying(bool isPlaying) {
mPlayer->setPlaying(isPlaying);
}
void MixingIO::clearPlayerSources() {
mPlayer->resetPlayHead();
mPlayer->clearSources();
}
void MixingIO::addSource(string key, shared_ptr<DataSource> source) {
mPlayer->addSource(key, source);
syncPlayHeads();
}
void MixingIO::addSourceMap(map<string, shared_ptr<DataSource>> playMap) {
mPlayer->addSourceMap(playMap);
syncPlayHeads();
}
bool MixingIO::writeSourcesToFile(map<string, shared_ptr<DataSource>> playMap, int fd) {
MixedAudioWriter mixedAudioWriter(playMap);
return mixedAudioWriter.writeToFile(fd);
}
void MixingIO::syncPlayHeads() {
mPlayer->syncPlayHeads();
}
void MixingIO::read_playback(float *targetData, int32_t numSamples) {
mPlayer->renderAudio(targetData, numSamples);
}
void MixingIO::setStopPlaybackCallback(function<void()> stopPlaybackCallback) {
mStopPlaybackCallback = stopPlaybackCallback;
mPlayer->setPlaybackCallback(stopPlaybackCallback);
}
int MixingIO::getTotalSampleFrames() {
if (mPlayer) {
return mPlayer->getTotalSampleFrames();
}
return 0;
}
int MixingIO::getCurrentPlaybackProgress() {
return mPlayer->getPlayHead();
}
void MixingIO::setPlayHead(int position) {
mPlayer->setPlayHead(position);
}
void MixingIO::setPlayerBoundStart(int64_t boundStart) {
mPlayer->setPlayerBoundStart(boundStart);
}
void MixingIO::setPlayerBoundEnd(int64_t boundEnd) {
mPlayer->setPlayerBoundEnd(boundEnd);
}
void MixingIO::resetPlayerBoundStart() {
mPlayer->resetPlayerBoundStart();
}
void MixingIO::resetPlayerBoundEnd() {
mPlayer->resetPlayerBoundEnd();
}