7#ifndef YARP_SIG_SOUND_H
8#define YARP_SIG_SOUND_H
29 return label == other.
label &&
46 Sound(
size_t bytesPerSample = 2);
85 void overwrite (
const Sound& alt,
size_t offset=0,
size_t len=0);
92 Sound subSound(
size_t first_sample,
size_t len);
104 void resize(
size_t samples,
size_t channels = 1);
106 audio_sample get(
size_t sample,
size_t channel = 0)
const;
108 void set(
audio_sample value,
size_t sample,
size_t channel = 0);
111 if (isSample(sample,channel)) {
112 return get(sample,channel);
117 void setSafe(audio_sample value,
size_t sample,
size_t channel = 0);
125 bool isSample(
size_t sample,
size_t channel = 0)
const;
136 void normalizeChannel(
size_t channel);
148 void amplifyChannel(
size_t channel,
double gain);
154 void amplify(
double gain);
162 void findPeakInChannel(
size_t channelId,
size_t& sampleId, audio_sample& sampleValue)
const;
170 void findPeak(
size_t& channelId,
size_t& sampleId, audio_sample& sampleValue)
const;
177 inline double sample2timestamp(
size_t sampleid)
const {
return static_cast<double>(sampleid / m_frequency);}
184 inline size_t timestamp2sample(
double time)
const {
return static_cast<size_t>(time * m_frequency);}
191 bool zeroChannel(
size_t channel);
197 int getFrequency()
const;
202 void setFrequency(
int freq);
208 size_t getBytesPerSample()
const;
214 size_t getSamples()
const;
220 double getDuration()
const;
226 size_t getChannels()
const;
232 Sound extractChannelAsSound(
size_t channel_id)
const;
234 std::vector<std::reference_wrapper<audio_sample>> getChannel(
size_t channel_id);
242 bool replaceChannel(
size_t id,
Sound channel);
250 std::vector<std::reference_wrapper<audio_sample>> getInterleavedAudioRawData()
const;
258 std::vector<std::reference_wrapper<audio_sample>> getNonInterleavedAudioRawData()
const;
274 void add_marker(
const std::string& marker_label,
size_t sample_id,
int channel=-1);
283 bool get_marker(
const std::string& marker_label,
size_t& sample_id,
int& channel)
const;
289 size_t getMarkersCount()
const;
304 std::vector<yarp::sig::SoundMarker> getMarkers()
const;
310 void remove_marker(
const std::string& marker_label);
315 void remove_all_markers();
324 Sound subSound(std::string marker_start, std::string marker_end);
332 unsigned char *getRawData()
const;
338 size_t getRawDataSize()
const;
340 void delete_implementation();
348 void init(
size_t bytesPerSample);
353 size_t m_bytesPerSample;
356 std::map<std::string,yarp::sig::SoundMarker> m_markers;
bool operator==(const struct v4l2_control &left, const struct v4l2_control &right)
std::string toString(const T &value)
convert an arbitrary type to string.
RandScalar * implementation(void *t)
A mini-server for performing network communication in the background.
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
Vector & operator+=(Vector &a, const double &s)
Addition operator between a scalar and a vector (defined in Math.h).
bool operator==(const SoundMarker &other) const