20#if defined (YARP_HAS_SOXR)
32 yCError(SOUNDFILTERS) <<
"invalid frequency value = 0";
35#ifndef MULTICHANS_TESTED
38 yCError(SOUNDFILTERS) <<
"only 1 channel is currently supported";
44 yCError(SOUNDFILTERS) <<
"empty sound received?!";
47 if (
static_cast<unsigned>(snd.
getFrequency()) == frequency)
49 yCWarning(SOUNDFILTERS) <<
"no resampling needed";
53#if !defined (YARP_HAS_SOXR)
54 yCError(SOUNDFILTERS) <<
"libsoxr not available";
59 tit.itype = SOXR_INT16_I;
60 tit.otype = SOXR_INT16_I;
64 double orate = double(frequency);
66#ifdef MULTICHANS_TESTED
71 size_t ilen = ismp*ichans;
75 for (
size_t t = 0;
t < ismp;
t++)
77 for (
size_t c = 0; c < ichans; c++)
83 size_t osmp = (
size_t)(ilen * orate / irate + .5);
84 size_t ochans = ichans;
85 size_t olen = osmp*ochans;
90 soxr_error_t error = soxr_oneshot(irate, orate, ichans,
96 yCError(SOUNDFILTERS) <<
"libsoxr resample failed";
104 for (
size_t t = 0;
t < osmp;
t++)
106 for (
size_t c = 0; c < ochans; c++)
Class for storing sounds See Audio in YARP for additional documentation on YARP audio.
void setSafe(audio_sample value, size_t sample, size_t channel=0)
void setFrequency(int freq)
Set the frequency of the sound (i.e.
size_t getChannels() const
Get the number of channels of the sound.
void resize(size_t samples, size_t channels=1)
Set the sound size.
int getFrequency() const
Get the frequency of the sound (i.e.
size_t getSamples() const
Get the number of samples contained in the sound.
audio_sample getSafe(size_t sample, size_t channel=0) const
#define yCError(component,...)
#define yCWarning(component,...)
#define YARP_LOG_COMPONENT(name,...)
An interface to the operating system, including Port based communication.
bool resample(yarp::sig::Sound &snd, size_t frequency)
Resample a sound.