-
Notifications
You must be signed in to change notification settings - Fork 571
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for 24 and 32-bit sample formats (#1255)
* OboeTester: test 24 and 32-bit PCM * oboe: add 24 and 32-bit support * OboeTester: add FormatConverterBox It uses flowgraph modules to convert between the various data formats. * Bump OboeTester version to 1.6.4
- Loading branch information
Showing
38 changed files
with
837 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/* | ||
* Copyright 2021 The Android Open Source Project | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#include "FormatConverterBox.h" | ||
|
||
FormatConverterBox::FormatConverterBox(int32_t numSamples, | ||
oboe::AudioFormat inputFormat, | ||
oboe::AudioFormat outputFormat) { | ||
mInputFormat = inputFormat; | ||
mOutputFormat = outputFormat; | ||
|
||
mInputBuffer = std::make_unique<uint8_t[]>(numSamples * sizeof(int32_t)); | ||
mOutputBuffer = std::make_unique<uint8_t[]>(numSamples * sizeof(int32_t)); | ||
|
||
mSource.reset(); | ||
switch (mInputFormat) { | ||
case oboe::AudioFormat::I16: | ||
mSource = std::make_unique<oboe::flowgraph::SourceI16>(1); | ||
break; | ||
case oboe::AudioFormat::I24: | ||
mSource = std::make_unique<oboe::flowgraph::SourceI24>(1); | ||
break; | ||
case oboe::AudioFormat::I32: | ||
mSource = std::make_unique<oboe::flowgraph::SourceI32>(1); | ||
break; | ||
case oboe::AudioFormat::Float: | ||
case oboe::AudioFormat::Invalid: | ||
case oboe::AudioFormat::Unspecified: | ||
mSource = std::make_unique<oboe::flowgraph::SourceFloat>(1); | ||
break; | ||
} | ||
|
||
mSink.reset(); | ||
switch (mOutputFormat) { | ||
case oboe::AudioFormat::I16: | ||
mSink = std::make_unique<oboe::flowgraph::SinkI16>(1); | ||
break; | ||
case oboe::AudioFormat::I24: | ||
mSink = std::make_unique<oboe::flowgraph::SinkI24>(1); | ||
break; | ||
case oboe::AudioFormat::I32: | ||
mSink = std::make_unique<oboe::flowgraph::SinkI32>(1); | ||
break; | ||
case oboe::AudioFormat::Float: | ||
case oboe::AudioFormat::Invalid: | ||
case oboe::AudioFormat::Unspecified: | ||
mSink = std::make_unique<oboe::flowgraph::SinkFloat>(1); | ||
break; | ||
} | ||
|
||
if (mSource && mSink) { | ||
mSource->output.connect(&mSink->input); | ||
mSink->pullReset(); | ||
} | ||
} | ||
|
||
int32_t FormatConverterBox::convertInternalBuffers(int32_t numSamples) { | ||
return convert(getOutputBuffer(), numSamples, getInputBuffer()); | ||
} | ||
|
||
int32_t FormatConverterBox::convertToInternalOutput(int32_t numSamples, const void *inputBuffer) { | ||
return convert(getOutputBuffer(), numSamples, inputBuffer); | ||
} | ||
|
||
int32_t FormatConverterBox::convertFromInternalInput(void *outputBuffer, int32_t numSamples) { | ||
return convert(outputBuffer, numSamples, getInputBuffer()); | ||
} | ||
|
||
int32_t FormatConverterBox::convert(void *outputBuffer, int32_t numSamples, const void *inputBuffer) { | ||
mSource->setData(inputBuffer, numSamples); | ||
return mSink->read(outputBuffer, numSamples); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
/* | ||
* Copyright 2021 The Android Open Source Project | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#ifndef OBOETESTER_FORMAT_CONVERTER_BOX_H | ||
#define OBOETESTER_FORMAT_CONVERTER_BOX_H | ||
|
||
#include <unistd.h> | ||
#include <sys/types.h> | ||
|
||
#include "oboe/Oboe.h" | ||
#include "flowgraph/SinkFloat.h" | ||
#include "flowgraph/SinkI16.h" | ||
#include "flowgraph/SinkI24.h" | ||
#include "flowgraph/SinkI32.h" | ||
#include "flowgraph/SourceFloat.h" | ||
#include "flowgraph/SourceI16.h" | ||
#include "flowgraph/SourceI24.h" | ||
#include "flowgraph/SourceI32.h" | ||
|
||
/** | ||
* Use flowgraph modules to convert between the various data formats. | ||
* | ||
* Note that this does not do channel conversions. | ||
*/ | ||
|
||
class FormatConverterBox { | ||
public: | ||
FormatConverterBox(int32_t numSamples, | ||
oboe::AudioFormat inputFormat, | ||
oboe::AudioFormat outputFormat); | ||
|
||
/** | ||
* @return internal buffer used to store input data | ||
*/ | ||
void *getOutputBuffer() { | ||
return (void *) mOutputBuffer.get(); | ||
}; | ||
/** | ||
* @return internal buffer used to store output data | ||
*/ | ||
void *getInputBuffer() { | ||
return (void *) mInputBuffer.get(); | ||
}; | ||
|
||
/** Convert the data from inputFormat to outputFormat | ||
* using both internal buffers. | ||
*/ | ||
int32_t convertInternalBuffers(int32_t numSamples); | ||
|
||
/** | ||
* Convert data from external buffer into internal output buffer. | ||
* @param numSamples | ||
* @param inputBuffer | ||
* @return | ||
*/ | ||
int32_t convertToInternalOutput(int32_t numSamples, const void *inputBuffer); | ||
|
||
/** | ||
* | ||
* Convert data from internal input buffer into external output buffer. | ||
* @param outputBuffer | ||
* @param numSamples | ||
* @return | ||
*/ | ||
int32_t convertFromInternalInput(void *outputBuffer, int32_t numSamples); | ||
|
||
/** | ||
* Convert data formats between the specified external buffers. | ||
* @param outputBuffer | ||
* @param numSamples | ||
* @param inputBuffer | ||
* @return | ||
*/ | ||
int32_t convert(void *outputBuffer, int32_t numSamples, const void *inputBuffer); | ||
|
||
private: | ||
oboe::AudioFormat mInputFormat{oboe::AudioFormat::Invalid}; | ||
oboe::AudioFormat mOutputFormat{oboe::AudioFormat::Invalid}; | ||
|
||
std::unique_ptr<uint8_t[]> mInputBuffer; | ||
std::unique_ptr<uint8_t[]> mOutputBuffer; | ||
|
||
std::unique_ptr<oboe::flowgraph::FlowGraphSourceBuffered> mSource; | ||
std::unique_ptr<oboe::flowgraph::FlowGraphSink> mSink; | ||
}; | ||
|
||
|
||
#endif //OBOETESTER_FORMAT_CONVERTER_BOX_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.