Skip to content

Commit 457cd3e

Browse files
committed
internal/oboe: bug fix: add missing files
1 parent f11a3b4 commit 457cd3e

4 files changed

+191
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Copyright 2023 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+
#include "oboe_flowgraph_FlowGraphNode_android.h"
18+
#include "oboe_flowgraph_FlowgraphUtilities_android.h"
19+
#include "oboe_flowgraph_SinkI8_24_android.h"
20+
21+
#if FLOWGRAPH_ANDROID_INTERNAL
22+
#include <audio_utils/primitives.h>
23+
#endif
24+
25+
using namespace FLOWGRAPH_OUTER_NAMESPACE::flowgraph;
26+
27+
SinkI8_24::SinkI8_24(int32_t channelCount)
28+
: FlowGraphSink(channelCount) {}
29+
30+
int32_t SinkI8_24::read(void *data, int32_t numFrames) {
31+
int32_t *intData = (int32_t *) data;
32+
const int32_t channelCount = input.getSamplesPerFrame();
33+
34+
int32_t framesLeft = numFrames;
35+
while (framesLeft > 0) {
36+
// Run the graph and pull data through the input port.
37+
int32_t framesRead = pullData(framesLeft);
38+
if (framesRead <= 0) {
39+
break;
40+
}
41+
const float *signal = input.getBuffer();
42+
int32_t numSamples = framesRead * channelCount;
43+
#if FLOWGRAPH_ANDROID_INTERNAL
44+
memcpy_to_q8_23_from_float_with_clamp(intData, signal, numSamples);
45+
intData += numSamples;
46+
signal += numSamples;
47+
#else
48+
for (int i = 0; i < numSamples; i++) {
49+
*intData++ = FlowgraphUtilities::clamp24FromFloat(*signal++);
50+
}
51+
#endif
52+
framesLeft -= framesRead;
53+
}
54+
return numFrames - framesLeft;
55+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Copyright 2023 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 FLOWGRAPH_SINK_I8_24_H
18+
#define FLOWGRAPH_SINK_I8_24_H
19+
20+
#include <stdint.h>
21+
22+
#include "oboe_flowgraph_FlowGraphNode_android.h"
23+
24+
namespace FLOWGRAPH_OUTER_NAMESPACE::flowgraph {
25+
26+
class SinkI8_24 : public FlowGraphSink {
27+
public:
28+
explicit SinkI8_24(int32_t channelCount);
29+
~SinkI8_24() override = default;
30+
31+
int32_t read(void *data, int32_t numFrames) override;
32+
33+
const char *getName() override {
34+
return "SinkI8_24";
35+
}
36+
};
37+
38+
} /* namespace FLOWGRAPH_OUTER_NAMESPACE::flowgraph */
39+
40+
#endif //FLOWGRAPH_SINK_I8_24_H
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* Copyright 2023 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+
#include <algorithm>
18+
#include <unistd.h>
19+
20+
#include "oboe_flowgraph_FlowGraphNode_android.h"
21+
#include "oboe_flowgraph_SourceI8_24_android.h"
22+
23+
#if FLOWGRAPH_ANDROID_INTERNAL
24+
#include <audio_utils/primitives.h>
25+
#endif
26+
27+
using namespace FLOWGRAPH_OUTER_NAMESPACE::flowgraph;
28+
29+
SourceI8_24::SourceI8_24(int32_t channelCount)
30+
: FlowGraphSourceBuffered(channelCount) {
31+
}
32+
33+
int32_t SourceI8_24::onProcess(int32_t numFrames) {
34+
float *floatData = output.getBuffer();
35+
const int32_t channelCount = output.getSamplesPerFrame();
36+
37+
const int32_t framesLeft = mSizeInFrames - mFrameIndex;
38+
const int32_t framesToProcess = std::min(numFrames, framesLeft);
39+
const int32_t numSamples = framesToProcess * channelCount;
40+
41+
const int32_t *intBase = static_cast<const int32_t *>(mData);
42+
const int32_t *intData = &intBase[mFrameIndex * channelCount];
43+
44+
#if FLOWGRAPH_ANDROID_INTERNAL
45+
memcpy_to_float_from_q8_23(floatData, intData, numSamples);
46+
#else
47+
for (int i = 0; i < numSamples; i++) {
48+
*floatData++ = *intData++ * kScale;
49+
}
50+
#endif
51+
52+
mFrameIndex += framesToProcess;
53+
return framesToProcess;
54+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Copyright 2023 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 FLOWGRAPH_SOURCE_I8_24_H
18+
#define FLOWGRAPH_SOURCE_I8_24_H
19+
20+
#include <stdint.h>
21+
22+
#include "oboe_flowgraph_FlowGraphNode_android.h"
23+
24+
namespace FLOWGRAPH_OUTER_NAMESPACE::flowgraph {
25+
26+
class SourceI8_24 : public FlowGraphSourceBuffered {
27+
public:
28+
explicit SourceI8_24(int32_t channelCount);
29+
~SourceI8_24() override = default;
30+
31+
int32_t onProcess(int32_t numFrames) override;
32+
33+
const char *getName() override {
34+
return "SourceI8_24";
35+
}
36+
private:
37+
static constexpr float kScale = 1.0 / (1UL << 23);
38+
};
39+
40+
} /* namespace FLOWGRAPH_OUTER_NAMESPACE::flowgraph */
41+
42+
#endif //FLOWGRAPH_SOURCE_I8_24_H

0 commit comments

Comments
 (0)