1 /*
2  * Copyright (C) 2018 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef RHYTHMGAME_AASSETDATASOURCE_H
18 #define RHYTHMGAME_AASSETDATASOURCE_H
19 
20 #include <android/asset_manager.h>
21 #include <GameConstants.h>
22 #include "DataSource.h"
23 
24 class AAssetDataSource : public DataSource {
25 
26 public:
getSize()27     int64_t getSize() const override { return mBufferSize; }
getProperties()28     AudioProperties getProperties() const override { return mProperties; }
getData()29     const float* getData() const override { return mBuffer.get(); }
30 
31     static AAssetDataSource* newFromCompressedAsset(
32             AAssetManager &assetManager,
33             const char *filename,
34             AudioProperties targetProperties);
35 
36 private:
37 
AAssetDataSource(std::unique_ptr<float[]> data,size_t size,const AudioProperties properties)38     AAssetDataSource(std::unique_ptr<float[]> data, size_t size,
39                      const AudioProperties properties)
40             : mBuffer(std::move(data))
41             , mBufferSize(size)
42             , mProperties(properties) {
43     }
44 
45     const std::unique_ptr<float[]> mBuffer;
46     const int64_t mBufferSize;
47     const AudioProperties mProperties;
48 
49 };
50 #endif //RHYTHMGAME_AASSETDATASOURCE_H
51