Skip to content

Commit

Permalink
gh-547 Add sample_format() and pcm_format() to SampleSpec
Browse files Browse the repository at this point in the history
Preparations for supporting frames of different formats in
different parts of pipeline.

For now new fields are not actually used.

This commit introduces small breaking change in C API:
when we search for packet_encoding compatible with
frame_encoding, we now take into account format too.

It means that if you use ROC_FORMAT_PCM_FLOAT32 in frame_encoding,
ROC_PACKET_ENCODING_AVP_L16_STEREO will not be selected automatically
anymore, and you need to specify it manually via packet_encoding.
  • Loading branch information
gavv committed Dec 28, 2023
1 parent e252b2b commit 03d29eb
Show file tree
Hide file tree
Showing 57 changed files with 545 additions and 237 deletions.
4 changes: 2 additions & 2 deletions src/internal_modules/roc_audio/channel_mapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ void ChannelMapper::map_surround_surround_(const sample_t* in_samples,
out_s += in_samples[in_ch] * map_matrix_.coeff(out_ch, in_ch);
}

out_s = std::min(out_s, SampleMax);
out_s = std::max(out_s, SampleMin);
out_s = std::min(out_s, Sample_Max);
out_s = std::max(out_s, Sample_Min);

*out_samples++ = out_s;
}
Expand Down
4 changes: 2 additions & 2 deletions src/internal_modules/roc_audio/mixer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ void Mixer::read_(sample_t* out_data,
out_data[n] += temp_data[n];

// Saturate on overflow.
out_data[n] = std::min(out_data[n], SampleMax);
out_data[n] = std::max(out_data[n], SampleMin);
out_data[n] = std::min(out_data[n], Sample_Max);
out_data[n] = std::max(out_data[n], Sample_Min);
}

// Accumulate flags from all mixed frames.
Expand Down
3 changes: 2 additions & 1 deletion src/internal_modules/roc_audio/pcm_decoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/

#include "roc_audio/pcm_decoder.h"
#include "roc_audio/sample.h"
#include "roc_core/panic.h"

namespace roc {
Expand All @@ -19,7 +20,7 @@ IFrameDecoder* PcmDecoder::construct(core::IArena& arena,
}

PcmDecoder::PcmDecoder(PcmFormat pcm_format, const SampleSpec& sample_spec)
: pcm_mapper_(pcm_format, SampleFmt)
: pcm_mapper_(pcm_format, Sample_RawFormat)
, n_chans_(sample_spec.num_channels())
, stream_pos_(0)
, stream_avail_(0)
Expand Down
2 changes: 1 addition & 1 deletion src/internal_modules/roc_audio/pcm_encoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ IFrameEncoder* PcmEncoder::construct(core::IArena& arena,
}

PcmEncoder::PcmEncoder(PcmFormat pcm_format, const SampleSpec& sample_spec)
: pcm_mapper_(SampleFmt, pcm_format)
: pcm_mapper_(Sample_RawFormat, pcm_format)
, n_chans_(sample_spec.num_channels())
, frame_data_(NULL)
, frame_byte_size_(0)
Expand Down
22 changes: 6 additions & 16 deletions src/internal_modules/roc_audio/pcm_format.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14079,7 +14079,7 @@ PcmTraits pcm_format_traits(PcmFormat format) {
#else
traits.is_little = true;
#endif
traits.bit_depth = 32;
traits.bit_depth = 25;
traits.bit_width = 32;
break;

Expand All @@ -14088,7 +14088,7 @@ PcmTraits pcm_format_traits(PcmFormat format) {
traits.is_integer = false;
traits.is_signed = true;
traits.is_little = false;
traits.bit_depth = 32;
traits.bit_depth = 25;
traits.bit_width = 32;
break;

Expand All @@ -14097,7 +14097,7 @@ PcmTraits pcm_format_traits(PcmFormat format) {
traits.is_integer = false;
traits.is_signed = true;
traits.is_little = true;
traits.bit_depth = 32;
traits.bit_depth = 25;
traits.bit_width = 32;
break;

Expand All @@ -14110,7 +14110,7 @@ PcmTraits pcm_format_traits(PcmFormat format) {
#else
traits.is_little = true;
#endif
traits.bit_depth = 64;
traits.bit_depth = 53;
traits.bit_width = 64;
break;

Expand All @@ -14119,7 +14119,7 @@ PcmTraits pcm_format_traits(PcmFormat format) {
traits.is_integer = false;
traits.is_signed = true;
traits.is_little = false;
traits.bit_depth = 64;
traits.bit_depth = 53;
traits.bit_width = 64;
break;

Expand All @@ -14128,7 +14128,7 @@ PcmTraits pcm_format_traits(PcmFormat format) {
traits.is_integer = false;
traits.is_signed = true;
traits.is_little = true;
traits.bit_depth = 64;
traits.bit_depth = 53;
traits.bit_width = 64;
break;

Expand Down Expand Up @@ -14364,7 +14364,6 @@ PcmFormat pcm_format_from_str(const char* str) {
if (strcmp(str, "s18_le") == 0) {
return PcmFormat_SInt18_Le;
}
return PcmFormat_Invalid;
if (strcmp(str, "s18_3") == 0) {
return PcmFormat_SInt18_3;
}
Expand All @@ -14374,7 +14373,6 @@ PcmFormat pcm_format_from_str(const char* str) {
if (strcmp(str, "s18_3le") == 0) {
return PcmFormat_SInt18_3_Le;
}
return PcmFormat_Invalid;
if (strcmp(str, "s18_4") == 0) {
return PcmFormat_SInt18_4;
}
Expand All @@ -14399,7 +14397,6 @@ PcmFormat pcm_format_from_str(const char* str) {
if (strcmp(str, "s20_le") == 0) {
return PcmFormat_SInt20_Le;
}
return PcmFormat_Invalid;
if (strcmp(str, "s20_3") == 0) {
return PcmFormat_SInt20_3;
}
Expand All @@ -14409,7 +14406,6 @@ PcmFormat pcm_format_from_str(const char* str) {
if (strcmp(str, "s20_3le") == 0) {
return PcmFormat_SInt20_3_Le;
}
return PcmFormat_Invalid;
if (strcmp(str, "s20_4") == 0) {
return PcmFormat_SInt20_4;
}
Expand All @@ -14431,7 +14427,6 @@ PcmFormat pcm_format_from_str(const char* str) {
if (strcmp(str, "s24_le") == 0) {
return PcmFormat_SInt24_Le;
}
return PcmFormat_Invalid;
if (strcmp(str, "s24_4") == 0) {
return PcmFormat_SInt24_4;
}
Expand Down Expand Up @@ -14513,7 +14508,6 @@ PcmFormat pcm_format_from_str(const char* str) {
if (strcmp(str, "u18_le") == 0) {
return PcmFormat_UInt18_Le;
}
return PcmFormat_Invalid;
if (strcmp(str, "u18_3") == 0) {
return PcmFormat_UInt18_3;
}
Expand All @@ -14523,7 +14517,6 @@ PcmFormat pcm_format_from_str(const char* str) {
if (strcmp(str, "u18_3le") == 0) {
return PcmFormat_UInt18_3_Le;
}
return PcmFormat_Invalid;
if (strcmp(str, "u18_4") == 0) {
return PcmFormat_UInt18_4;
}
Expand All @@ -14548,7 +14541,6 @@ PcmFormat pcm_format_from_str(const char* str) {
if (strcmp(str, "u20_le") == 0) {
return PcmFormat_UInt20_Le;
}
return PcmFormat_Invalid;
if (strcmp(str, "u20_3") == 0) {
return PcmFormat_UInt20_3;
}
Expand All @@ -14558,7 +14550,6 @@ PcmFormat pcm_format_from_str(const char* str) {
if (strcmp(str, "u20_3le") == 0) {
return PcmFormat_UInt20_3_Le;
}
return PcmFormat_Invalid;
if (strcmp(str, "u20_4") == 0) {
return PcmFormat_UInt20_4;
}
Expand All @@ -14580,7 +14571,6 @@ PcmFormat pcm_format_from_str(const char* str) {
if (strcmp(str, "u24_le") == 0) {
return PcmFormat_UInt24_Le;
}
return PcmFormat_Invalid;
if (strcmp(str, "u24_4") == 0) {
return PcmFormat_UInt24_4;
}
Expand Down
2 changes: 1 addition & 1 deletion src/internal_modules/roc_audio/pcm_format.h
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ struct PcmTraits {
//! Number of significant bits per sample.
size_t bit_depth;

//! Number of total bits per sample in packed form.
//! Number of stored bits per sample in packed form.
size_t bit_width;

PcmTraits()
Expand Down
Loading

0 comments on commit 03d29eb

Please sign in to comment.