7#ifndef YARP_SIG_SOUND_H
8#define YARP_SIG_SOUND_H
26 return label == other.
label &&
43 Sound(
size_t bytesPerSample = 2);
82 void overwrite (
const Sound& alt,
size_t offset=0,
size_t len=0);
89 Sound subSound(
size_t first_sample,
size_t len);
101 void resize(
size_t samples,
size_t channels = 1);
103 audio_sample get(
size_t sample,
size_t channel = 0)
const;
105 void set(
audio_sample value,
size_t sample,
size_t channel = 0);
108 if (isSample(sample,channel)) {
109 return get(sample,channel);
114 void setSafe(audio_sample value,
size_t sample,
size_t channel = 0);
122 bool isSample(
size_t sample,
size_t channel = 0)
const;
133 void normalizeChannel(
size_t channel);
145 void amplifyChannel(
size_t channel,
double gain);
151 void amplify(
double gain);
159 void findPeakInChannel(
size_t channelId,
size_t& sampleId, audio_sample& sampleValue)
const;
167 void findPeak(
size_t& channelId,
size_t& sampleId, audio_sample& sampleValue)
const;
174 inline double sample2timestamp(
size_t sampleid)
const {
return static_cast<double>(sampleid / m_frequency);}
181 inline size_t timestamp2sample(
double time)
const {
return static_cast<size_t>(time * m_frequency);}
188 bool zeroChannel(
size_t channel);
194 int getFrequency()
const;
199 void setFrequency(
int freq);
205 size_t getBytesPerSample()
const;
211 size_t getSamples()
const;
217 double getDuration()
const;
223 size_t getChannels()
const;
229 Sound extractChannelAsSound(
size_t channel_id)
const;
231 std::vector<std::reference_wrapper<audio_sample>> getChannel(
size_t channel_id);
239 bool replaceChannel(
size_t id,
Sound channel);
247 std::vector<std::reference_wrapper<audio_sample>> getInterleavedAudioRawData()
const;
255 std::vector<std::reference_wrapper<audio_sample>> getNonInterleavedAudioRawData()
const;
271 void add_marker(
const std::string& marker_label,
size_t sample_id,
int channel=-1);
280 bool get_marker(
const std::string& marker_label,
size_t& sample_id,
int& channel)
const;
286 size_t getMarkersCount()
const;
301 std::vector<yarp::sig::SoundMarker> getMarkers()
const;
307 void remove_marker(
const std::string& marker_label);
312 void remove_all_markers();
321 Sound subSound(std::string marker_start, std::string marker_end);
329 unsigned char *getRawData()
const;
335 size_t getRawDataSize()
const;
337 void delete_implementation();
345 void init(
size_t bytesPerSample);
350 size_t m_bytesPerSample;
353 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