7 #ifndef YARP_SIG_SOUND_H
8 #define YARP_SIG_SOUND_H
30 Sound(
size_t bytesPerSample = 2);
53 bool operator==(
const Sound& alt)
const;
67 Sound subSound(
size_t first_sample,
size_t last_sample);
74 void resize(
size_t samples,
size_t channels = 1);
76 audio_sample get(
size_t sample,
size_t channel = 0)
const;
78 void set(
audio_sample value,
size_t sample,
size_t channel = 0);
81 if (isSample(sample,channel)) {
82 return get(sample,channel);
87 void setSafe(audio_sample value,
size_t sample,
size_t channel = 0);
95 bool isSample(
size_t sample,
size_t channel = 0)
const;
106 void normalizeChannel(
size_t channel);
118 void amplifyChannel(
size_t channel,
double gain);
124 void amplify(
double gain);
132 void findPeakInChannel(
size_t channelId,
size_t& sampleId, audio_sample& sampleValue)
const;
140 void findPeak(
size_t& channelId,
size_t& sampleId, audio_sample& sampleValue)
const;
147 inline double sample2timestamp(
size_t sampleid)
const {
return static_cast<double>(sampleid / m_frequency);}
154 inline size_t timestamp2sample(
double time)
const {
return static_cast<size_t>(time * m_frequency);}
161 bool clearChannel(
size_t channel);
167 int getFrequency()
const;
172 void setFrequency(
int freq);
178 size_t getBytesPerSample()
const;
184 size_t getSamples()
const;
190 double getDuration()
const;
196 size_t getChannels()
const;
202 Sound extractChannelAsSound(
size_t channel_id)
const;
204 std::vector<std::reference_wrapper<audio_sample>> getChannel(
size_t channel_id);
212 bool replaceChannel(
size_t id,
Sound channel);
220 std::vector<std::reference_wrapper<audio_sample>> getInterleavedAudioRawData()
const;
228 std::vector<std::reference_wrapper<audio_sample>> getNonInterleavedAudioRawData()
const;
243 unsigned char *getRawData()
const;
249 size_t getRawDataSize()
const;
257 void init(
size_t bytesPerSample);
263 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)
The main, catch-all namespace for YARP.