aaudio: use new flowgraph to simplify processing
Construct a flowgraph based on the source and destination
format and channelCount. This is groundwork for supporting 24-bit
PCM formats.
Also cleaned up handling of device related format.
This CL removes more code than it adds.
Bug: 65067568
Test: write_sine_callback.cpp -pl
Test: write_sine_callback.cpp -pl -x
Test: input_monitor -pl
Test: input_monitor -pl -x
Change-Id: Ia155bff0164912011d09b61b54f983ccf4490bd1
diff --git a/media/libaaudio/src/client/AudioStreamInternalPlay.cpp b/media/libaaudio/src/client/AudioStreamInternalPlay.cpp
index 795ba2c..2ae37a5 100644
--- a/media/libaaudio/src/client/AudioStreamInternalPlay.cpp
+++ b/media/libaaudio/src/client/AudioStreamInternalPlay.cpp
@@ -43,9 +43,17 @@
aaudio_result_t AudioStreamInternalPlay::open(const AudioStreamBuilder &builder) {
aaudio_result_t result = AudioStreamInternal::open(builder);
if (result == AAUDIO_OK) {
+ result = mFlowGraph.configure(getFormat(),
+ getSamplesPerFrame(),
+ getDeviceFormat(),
+ getDeviceChannelCount());
+
+ if (result != AAUDIO_OK) {
+ close();
+ }
// Sample rate is constrained to common values by now and should not overflow.
int32_t numFrames = kRampMSec * getSampleRate() / AAUDIO_MILLIS_PER_SECOND;
- mVolumeRamp.setLengthInFrames(numFrames);
+ mFlowGraph.setRampLengthInFrames(numFrames);
}
return result;
}
@@ -216,22 +224,10 @@
}
int32_t numBytes = getBytesPerFrame() * framesToWrite;
- // Data conversion.
- float levelFrom;
- float levelTo;
- mVolumeRamp.nextSegment(framesToWrite, &levelFrom, &levelTo);
- AAudioDataConverter::FormattedData source(
- (void *)byteBuffer,
- getFormat(),
- getSamplesPerFrame());
- AAudioDataConverter::FormattedData destination(
- wrappingBuffer.data[partIndex],
- getDeviceFormat(),
- getDeviceChannelCount());
-
- AAudioDataConverter::convert(source, destination, framesToWrite,
- levelFrom, levelTo);
+ mFlowGraph.process((void *)byteBuffer,
+ wrappingBuffer.data[partIndex],
+ framesToWrite);
byteBuffer += numBytes;
framesLeft -= framesToWrite;
@@ -313,6 +309,6 @@
float combinedVolume = mStreamVolume * getDuckAndMuteVolume();
ALOGD("%s() mStreamVolume * duckAndMuteVolume = %f * %f = %f",
__func__, mStreamVolume, getDuckAndMuteVolume(), combinedVolume);
- mVolumeRamp.setTarget(combinedVolume);
+ mFlowGraph.setTargetVolume(combinedVolume);
return android::NO_ERROR;
}