• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2019 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 OBOE_SAMPLE_RATE_CONVERTER_H
18 #define OBOE_SAMPLE_RATE_CONVERTER_H
19 
20 #include <unistd.h>
21 #include <sys/types.h>
22 
23 #include "FlowGraphNode.h"
24 #include "resampler/MultiChannelResampler.h"
25 
26 namespace FLOWGRAPH_OUTER_NAMESPACE {
27 namespace flowgraph {
28 
29 class SampleRateConverter : public FlowGraphFilter {
30 public:
31     explicit SampleRateConverter(int32_t channelCount, resampler::MultiChannelResampler &mResampler);
32 
33     virtual ~SampleRateConverter() = default;
34 
35     int32_t onProcess(int32_t numFrames) override;
36 
getName()37     const char *getName() override {
38         return "SampleRateConverter";
39     }
40 
41     void reset() override;
42 
43 private:
44 
45     // Return true if there is a sample available.
46     bool isInputAvailable();
47 
48     // This assumes data is available. Only call after calling isInputAvailable().
49     const float *getNextInputFrame();
50 
51     resampler::MultiChannelResampler &mResampler;
52 
53     int32_t mInputCursor = 0;         // offset into the input port buffer
54     int32_t mNumValidInputFrames = 0; // number of valid frames currently in the input port buffer
55     // We need our own callCount for upstream calls because calls occur at a different rate.
56     // This means we cannot have cyclic graphs or merges that contain an SRC.
57     int64_t mInputCallCount = 0;
58 
59 };
60 
61 } /* namespace flowgraph */
62 } /* namespace FLOWGRAPH_OUTER_NAMESPACE */
63 
64 #endif //OBOE_SAMPLE_RATE_CONVERTER_H
65