7 #ifndef YARP_SIG_SOUND_H
8 #define YARP_SIG_SOUND_H
29 Sound(
size_t bytesPerSample = 2);
52 bool operator==(
const Sound& alt)
const;
66 Sound subSound(
size_t first_sample,
size_t last_sample);
73 void resize(
size_t samples,
size_t channels = 1);
75 audio_sample get(
size_t sample,
size_t channel = 0)
const;
77 void set(
audio_sample value,
size_t sample,
size_t channel = 0);
80 if (isSample(sample,channel)) {
81 return get(sample,channel);
86 void setSafe(audio_sample value,
size_t sample,
size_t channel = 0);
94 bool isSample(
size_t sample,
size_t channel = 0)
const;
105 void normalizeChannel(
size_t channel);
117 void amplifyChannel(
size_t channel,
double gain);
123 void amplify(
double gain);
131 void findPeakInChannel(
size_t channelId,
size_t& sampleId, audio_sample& sampleValue)
const;
139 void findPeak(
size_t& channelId,
size_t& sampleId, audio_sample& sampleValue)
const;
146 inline double sample2timestamp(
size_t sampleid)
const {
return static_cast<double>(sampleid / m_frequency);}
153 inline size_t timestamp2sample(
double time)
const {
return static_cast<size_t>(time * m_frequency);}
160 bool clearChannel(
size_t channel);
166 int getFrequency()
const;
171 void setFrequency(
int freq);
177 size_t getBytesPerSample()
const;
183 size_t getSamples()
const;
189 double getDuration()
const;
195 size_t getChannels()
const;
201 Sound extractChannelAsSound(
size_t channel_id)
const;
203 std::vector<std::reference_wrapper<audio_sample>> getChannel(
size_t channel_id);
211 bool replaceChannel(
size_t id,
Sound channel);
219 std::vector<std::reference_wrapper<audio_sample>> getInterleavedAudioRawData()
const;
227 std::vector<std::reference_wrapper<audio_sample>> getNonInterleavedAudioRawData()
const;
242 unsigned char *getRawData()
const;
248 size_t getRawDataSize()
const;
256 void init(
size_t bytesPerSample);
262 size_t m_bytesPerSample;
RandScalar * implementation(void *t)
An interface for reading from a network connection.
An interface for writing to a network connection.
This is a base class for objects that can be both read from and be written to the YARP network.
Class for storing sounds See Audio in YARP for additional documentation on YARP audio.
double sample2timestamp(size_t sampleid) const
Utility function: return the timestamp (in seconds) given the sample id.
size_t timestamp2sample(double time) const
Utility function: return the sample id given the timestamp (in seconds)
audio_sample getSafe(size_t sample, size_t channel=0) const
std::string toString(const T &value)
convert an arbitrary type to string.
Vector & operator+=(Vector &a, const double &s)
Addition operator between a scalar and a vector (defined in Math.h).
bool read(ImageOf< PixelRgb > &dest, const std::string &src, image_fileformat format=FORMAT_ANY)
bool write(const ImageOf< PixelRgb > &src, const std::string &dest, image_fileformat format=FORMAT_PPM)