-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathFileDataSource.h
113 lines (79 loc) · 3.08 KB
/
FileDataSource.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
/*
* Copyright (C) 2018 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef FAST_MIXER_FILEDATASOURCE_H
#define FAST_MIXER_FILEDATASOURCE_H
#include <android/asset_manager.h>
#include "../structs.h"
#include "DataSource.h"
#include "../utils/Utils.h"
using namespace std;
#define AUDIO_CHANNEL_STEREO 2
#define MIN_NUMBER_OF_BYTES_PER_SAMPLE 1
class FileDataSource : public DataSource {
public:
int64_t getMainBufferSize();
int64_t getSize() const override;
AudioProperties getProperties() const override { return mProperties; }
const float* getMainBufferData();
const float* getData() const override;
void setBackupBufferData(float* &&data, int64_t numSamples);
int64_t getSampleSize();
void setPlayHead(int64_t playHead);
int64_t getPlayHead() override;
float getAbsMaxSampleValue() const override;
float getMaxSampleValue() const override;
float getMinSampleValue() const override;
void setSelectionStart(int64_t selectionStart);
void setSelectionEnd(int64_t selectionEnd);
void resetSelectionStart();
void resetSelectionEnd();
int64_t getSelectionStart() override;
int64_t getSelectionEnd() override;
static FileDataSource* newFromCompressedFile(
const char *filename,
int fd,
const AudioProperties targetProperties);
shared_ptr<buffer_data> readData(size_t numSamples);
void applyBackupBufferData();
void resetBackupBufferData();
int64_t shiftBySamples(int64_t position, int64_t numSamples);
int64_t cutToClipboard(int64_t startPosition, int64_t endPosition, vector<float>& clipboard);
void copyToClipboard(int64_t startPosition, int64_t endPosition, vector<float>& clipboard);
void muteAndCopyToClipboard(int64_t startPosition, int64_t endPosition, vector<float>& clipboard);
void pasteFromClipboard(int64_t position, vector<float>& clipboard);
protected:
FileDataSource(unique_ptr<float[]> data, size_t size,
const AudioProperties properties);
private:
void calculateProperties();
unique_ptr<float[]> mBuffer {
nullptr
};
unique_ptr<float[]> mBackupBuffer {
nullptr
};
int64_t mBufferSize;
int64_t mBackupBufferSize = 0;
const AudioProperties mProperties;
int64_t currentPtr = 0;
int64_t mPlayHead = 0;
float mMaxAbsSampleValue = FLT_MIN;
float mMaxSampleValue = FLT_MIN;
float mMinSampleValue = FLT_MAX;
int64_t mSelectionStart = INT64_MIN;
int64_t mSelectionEnd = INT64_MIN;
};
#endif //RHYTHMGAME_AASSETDATASOURCE_H