Skip to content

Commit

Permalink
roc-streaminggh-608: Support custom PCM formats in sndfile backend
Browse files Browse the repository at this point in the history
  • Loading branch information
gavv committed Aug 7, 2024
1 parent dd1151f commit f812c70
Show file tree
Hide file tree
Showing 8 changed files with 219 additions and 98 deletions.
4 changes: 4 additions & 0 deletions src/internal_modules/roc_audio/sample_spec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,10 @@ bool SampleSpec::is_empty() const {
&& sample_rate_ == 0 && channel_set_.num_channels() == 0;
}

bool SampleSpec::is_pcm() const {
return sample_fmt_ == SampleFormat_Pcm && pcm_fmt_ != PcmFormat_Invalid;
}

bool SampleSpec::is_raw() const {
return sample_fmt_ == SampleFormat_Pcm
&& get_pcm_portable_format(pcm_fmt_) == get_pcm_portable_format(Sample_RawFormat);
Expand Down
6 changes: 6 additions & 0 deletions src/internal_modules/roc_audio/sample_spec.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ class SampleSpec {
//! Check if sample spec has a zero rate, empty channel set, and invalid_format.
bool is_empty() const;

//! Check if samples are in PCM format.
//! @returns
//! true if sample_format() is SampleFormat_Pcm and pcm_format()
//! is anything except PcmFormat_Invalid.
bool is_pcm() const;

//! Check if samples are in raw format.
//! @returns
//! true if sample_format() is SampleFormat_Pcm and pcm_format()
Expand Down
30 changes: 18 additions & 12 deletions src/internal_modules/roc_sndio/backend_dispatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,10 +225,12 @@ status::StatusCode BackendDispatcher::open_default_device_(DeviceType device_typ
return code;
}

roc_log(LogDebug,
"backend dispatcher: got error from driver:"
" driver=%s status=%s",
driver_info.name, status::code_to_str(code));
if (code != status::StatusNoDriver) {
roc_log(LogDebug,
"backend dispatcher: got error from driver:"
" driver=%s status=%s",
driver_info.name, status::code_to_str(code));
}
}

roc_log(LogError, "backend dispatcher: failed to open default %s: status=%s",
Expand Down Expand Up @@ -265,10 +267,12 @@ status::StatusCode BackendDispatcher::open_device_(DeviceType device_type,
return code;
}

roc_log(LogDebug,
"backend dispatcher: got error from driver:"
" driver=%s status=%s",
driver_info.name, status::code_to_str(code));
if (code != status::StatusNoDriver) {
roc_log(LogDebug,
"backend dispatcher: got error from driver:"
" driver=%s status=%s",
driver_info.name, status::code_to_str(code));
}
}
} else {
for (size_t n = 0; n < BackendMap::instance().num_backends(); n++) {
Expand All @@ -281,10 +285,12 @@ status::StatusCode BackendDispatcher::open_device_(DeviceType device_type,
return code;
}

roc_log(LogDebug,
"backend dispatcher: got error from backend:"
" backend=%s status=%s",
backend.name(), status::code_to_str(code));
if (code != status::StatusNoDriver) {
roc_log(LogDebug,
"backend dispatcher: got error from backend:"
" backend=%s status=%s",
backend.name(), status::code_to_str(code));
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,15 @@ namespace roc {
namespace sndio {

FileMap file_type_map[ROC_ARRAY_SIZE(file_type_map)] = {
{ SF_FORMAT_MAT4, "mat4", NULL }, //
{ SF_FORMAT_MAT5, "mat5", NULL }, //
{ SF_FORMAT_WAV, "wav", "wav" }, //
{ SF_FORMAT_NIST, "nist", NULL }, //
{ SF_FORMAT_WAVEX, "wavex", NULL }, //
{ SF_FORMAT_OGG, "ogg", "ogg" },
{ SF_FORMAT_MPEG | SF_FORMAT_MPEG_LAYER_I, "mp1", "mp1" },
{ SF_FORMAT_MPEG | SF_FORMAT_MPEG_LAYER_II, "mp2", "mp2" },
{ SF_FORMAT_MPEG | SF_FORMAT_MPEG_LAYER_III, "mp3", "mp3" },
{ SF_FORMAT_MAT4, "mat4", NULL },
{ SF_FORMAT_MAT5, "mat5", NULL },
{ SF_FORMAT_WAV, "wav", "wav" },
{ SF_FORMAT_NIST, "nist", NULL },
{ SF_FORMAT_WAVEX, "wavex", NULL },
};

} // namespace sndio
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ struct FileMap {
};

//! Declare the file_type_map as extern
extern FileMap file_type_map[5];
extern FileMap file_type_map[9];

} // namespace sndio
} // namespace roc
Expand Down
Loading

0 comments on commit f812c70

Please sign in to comment.