UltraGrid
UltraGrid Low-Latency High-Resolution Transmission System
Loading...
Searching...
No Matches
audio_frame2_resampler Class Reference

#include <resampler.hpp>

Collaboration diagram for audio_frame2_resampler:
Collaboration graph

Classes

class  impl
 

Public Member Functions

 audio_frame2_resampler ()
 
 audio_frame2_resampler (audio_frame2_resampler &&)
 
 ~audio_frame2_resampler ()
 
int align_bps (int orig)
 
audio_frame2_resampler & operator= (audio_frame2_resampler &&)
 
std::tuple< bool, audio_frame2 > resample (audio_frame2 &a, std::vector< audio_frame2::channel > &out, int new_sample_rate_num, int new_sample_rate_den)
 

Private Attributes

std::unique_ptr< impl > m_impl
 

Detailed Description

Definition at line 47 of file resampler.hpp.

Constructor & Destructor Documentation

◆ audio_frame2_resampler() [1/2]

audio_frame2_resampler::audio_frame2_resampler ( )

Definition at line 355 of file resampler.cpp.

356{
357 enum { RESAMPLER_DEFAULT, RESAMPLER_SPEEX, RESAMPLER_SOXR } resampler_type = RESAMPLER_DEFAULT;
358 const char *cfg_c = get_commandline_param("resampler");
359 std::string_view sv = cfg_c ? cfg_c : "";
360 int quality = DEFAULT_SPEEX_RESAMPLE_QUALITY;
361 while (!sv.empty()) {
362 const auto &tok = tokenize(sv, ':');
363 if (tok == "speex") {
364 resampler_type = RESAMPLER_SPEEX;
365 } else if (tok == "soxr") {
366 resampler_type = RESAMPLER_SOXR;
367 } else if (tok.compare(0, "quality="sv.length(), "quality=") == 0) {
368 quality = stoi(string(tok.substr("quality="sv.length())));
369 if (quality < 0 || quality > 10) {
370 throw ug_runtime_error("Quality " + to_string(quality) + " out of range 0-10"s);
371 }
372 } else {
373 throw ug_runtime_error("Unknown resampler option: "s + string(tok));
374 }
375 }
376 switch (resampler_type) {
377 case RESAMPLER_DEFAULT:
378#ifdef HAVE_SPEEXDSP
379 m_impl = unique_ptr<audio_frame2_resampler::impl>(new speex_resampler(quality));
380#elif defined HAVE_SOXR
381 m_impl = unique_ptr<audio_frame2_resampler::impl>(new soxr_resampler());
382#endif
383 break;
384 case RESAMPLER_SPEEX:
385#ifdef HAVE_SPEEXDSP
386 m_impl = unique_ptr<audio_frame2_resampler::impl>(new speex_resampler(quality));
387#else
388 throw ug_runtime_error("SpeexDSP not compiled in!");
389#endif
390 break;
391 case RESAMPLER_SOXR:
392#if defined HAVE_SOXR
393 m_impl = unique_ptr<audio_frame2_resampler::impl>(new soxr_resampler());
394 break;
395#else
396 throw ug_runtime_error("Soxr not compiled in!");
397#endif
398 }
399}
std::unique_ptr< impl > m_impl
Definition resampler.hpp:59
const char * get_commandline_param(const char *key)
Definition host.cpp:894
#define DEFAULT_SPEEX_RESAMPLE_QUALITY
Definition resampler.cpp:63
std::string_view tokenize(std::string_view &str, char delim, char quot)
Tokenizer for string_view.

References DEFAULT_SPEEX_RESAMPLE_QUALITY, get_commandline_param(), m_impl, and tokenize().

Here is the call graph for this function:

◆ ~audio_frame2_resampler()

audio_frame2_resampler::~audio_frame2_resampler ( )
default

◆ audio_frame2_resampler() [2/2]

audio_frame2_resampler::audio_frame2_resampler ( audio_frame2_resampler && )
default

Member Function Documentation

◆ align_bps()

int audio_frame2_resampler::align_bps ( int orig)
Returns
the orig (if supported) or nearest higher of resampler supported BPS (highest if orig is higher)

Definition at line 404 of file resampler.cpp.

404 {
405 if (!m_impl) {
406 LOG(LOG_LEVEL_ERROR) << "Audio frame resampler: cannot resample, Soxr/SpeexDSP was not compiled in!\n";
407 return 0;
408 }
409 const int *sup = m_impl->get_supported_bps();
410 int last = 0;
411 while (*sup != 0) {
412 if (orig <= *sup) {
413 return *sup;
414 }
415 last = *sup++;
416 }
417 return last;
418}
#define LOG_LEVEL_ERROR
general errors
Definition debug.h:59
#define LOG(level)
Definition debug.h:313

References LOG, LOG_LEVEL_ERROR, and m_impl.

Referenced by decode_audio_frame().

◆ operator=()

audio_frame2_resampler & audio_frame2_resampler::operator= ( audio_frame2_resampler && )
default

◆ resample()

tuple< bool, audio_frame2 > audio_frame2_resampler::resample ( audio_frame2 & a,
std::vector< audio_frame2::channel > & out,
int new_sample_rate_num,
int new_sample_rate_den )

Definition at line 76 of file resampler.cpp.

77{
78 if (!m_impl) {
79 LOG(LOG_LEVEL_ERROR) << "Audio frame resampler: cannot resample, Soxr/SpeexDSP was not compiled in!\n";
80 return { false, audio_frame2{} };
81 }
82 return m_impl->resample(a, out, new_sample_rate_num, new_sample_rate_den);
83}

References LOG, LOG_LEVEL_ERROR, and m_impl.

Referenced by audio_frame2::resample_fake().

Member Data Documentation

◆ m_impl

std::unique_ptr<impl> audio_frame2_resampler::m_impl
private

Definition at line 59 of file resampler.hpp.

Referenced by audio_frame2_resampler(), align_bps(), and resample().


The documentation for this class was generated from the following files: