Skip to content

Commit

Permalink
AudioContentBlockSpec Tune-up
Browse files Browse the repository at this point in the history
Summary:
This change improves AudioContentBlockSpec in the following ways:
- update the terminology to use "audio frame" as used in the audio industry, to designate a group of audio samples recorded at the same time, one sample by audio channel. With stereo audio, each audio frame has two audio samples, one per channel. We previously used "audio block", which is non-standard and easy to confuse with the audio content block.
- update constructors to require an AudioFormat, which allows use to...
- reorder parameters in AudioContentBlockSpec, so that all the parameters defining the format of the audio format comes first, followed by the frame spec (sample format, channel count, frame stride), then the sample frame rate, then the sample frame count, which is the most variable part of the definition, since in the same file you could easily have audio content blocks with different audio frame counts.

Reviewed By: perdoch

Differential Revision: D53338818

fbshipit-source-id: 6da17f9c3f91fee474b1404b78063bb273f2880b
  • Loading branch information
Georges Berenger authored and facebook-github-bot committed Feb 2, 2024
1 parent 8050704 commit 841a2b6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
13 changes: 9 additions & 4 deletions csrc/utils/PyBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ const constexpr char* kImageSpecKeyFrameIndexKey = "key_frame_index";

const constexpr char* kAudioSpecSampleCountKey = "sample_count";
const constexpr char* kAudioSpecSampleFormatKey = "sample_format";
const constexpr char* kAudioSpecSampleBlockStrideKey = "sample_block_stride";
const constexpr char* kAudioSpecSampleBlockStrideKey = "sample_block_stride"; // deprecated
const constexpr char* kAudioSpecSampleFrameStrideKey = "sample_frame_stride";
const constexpr char* kAudioSpecChannelCountKey = "channel_count";
const constexpr char* kAudioSpecSampleRateKey = "sample_rate";
const constexpr char* kAudioSpecBufferSizeKey = "buffer_size";
Expand Down Expand Up @@ -137,7 +138,8 @@ void PyAudioContentBlockSpec::initAttributesMap() {
if (attributesMap.empty()) {
attributesMap[kAudioSpecSampleCountKey] = PYWRAP(getSampleCount());
attributesMap[kAudioSpecSampleFormatKey] = PYWRAP(getSampleFormatAsString());
attributesMap[kAudioSpecSampleBlockStrideKey] = PYWRAP(getSampleBlockStride());
attributesMap[kAudioSpecSampleBlockStrideKey] = PYWRAP(getSampleFrameStride()); // deprecated
attributesMap[kAudioSpecSampleFrameStrideKey] = PYWRAP(getSampleFrameStride());
attributesMap[kAudioSpecChannelCountKey] = PYWRAP(getChannelCount());
attributesMap[kAudioSpecSampleRateKey] = PYWRAP(getSampleRate());
attributesMap[kAudioSpecBufferSizeKey] = PYWRAP(getBlockSize());
Expand Down Expand Up @@ -284,7 +286,7 @@ py::buffer_info convertContentBlockBuffer(ContentBlockBuffer& block) {
if (block.structuredArray && block.spec.getContentType() == vrs::ContentType::AUDIO) {
const vrs::AudioContentBlockSpec& audioSpec = block.spec.audio();
std::string sampleFormat;
uint32_t audioSampleStride = audioSpec.getSampleBlockStride();
uint32_t audioSampleStride = audioSpec.getSampleFrameStride();
uint32_t audioSampleCount = audioSpec.getSampleCount();
uint32_t channelCount = audioSpec.getChannelCount();
uint32_t audioSampleByteSize = audioSpec.getBytesPerSample();
Expand Down Expand Up @@ -571,7 +573,10 @@ void pybind_buffer(py::module& m) {
.def_property_readonly(
kAudioSpecSampleFormatKey, &PyAudioContentBlockSpec::getSampleFormat)
.def_property_readonly(
kAudioSpecSampleBlockStrideKey, &PyAudioContentBlockSpec::getSampleBlockStride)
kAudioSpecSampleBlockStrideKey,
&PyAudioContentBlockSpec::getSampleFrameStride) // deprecated
.def_property_readonly(
kAudioSpecSampleFrameStrideKey, &PyAudioContentBlockSpec::getSampleFrameStride)
.def_property_readonly(
kAudioSpecChannelCountKey, &PyAudioContentBlockSpec::getChannelCount)
.def_property_readonly(kAudioSpecSampleRateKey, &PyAudioContentBlockSpec::getSampleRate)
Expand Down
4 changes: 2 additions & 2 deletions csrc/utils/PyBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ class PyAudioContentBlockSpec {
return spec_.getSampleFormatAsString();
}

uint8_t getSampleBlockStride() const {
return spec_.getSampleBlockStride();
uint8_t getSampleFrameStride() const {
return spec_.getSampleFrameStride();
}

uint8_t getChannelCount() const {
Expand Down

0 comments on commit 841a2b6

Please sign in to comment.