1 /*
2  * Copyright (c) 2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef PCM_ITERATOR_H
17 #define PCM_ITERATOR_H
18 
19 #include "ai_datatype.h"
20 
21 namespace OHOS {
22 namespace AI {
23 class PCMIterator {
24 public:
25     PCMIterator();
26     virtual ~PCMIterator();
27     int32_t Init(size_t stepSize, size_t windowSize);
28     void Release();
29     int32_t SetInput(const Array<int16_t> &pcmData);
30     void Reset();
31     bool HasNext();
32     Array<int16_t> Next();
33 
34 private:
35     int32_t MoveDataToCache(const Array<int16_t> &input);
36     int32_t Prepare(const Array<int16_t> &input);
37     size_t stepSize_;
38     size_t windowSize_;
39     size_t numCopy_;
40     size_t numRealCopy_;
41     size_t nextCachePos_;
42     int32_t maxCacheSize_;
43     bool isInitialized_;
44     bool hasNext_;
45     Array<int16_t> pcmCache_ = {0};
46     Array<int16_t> pcmData_ = {0};
47 };
48 } // namespace AI
49 } // namespace OHOS
50 #endif // PCM_ITERATOR_H