100 ret =
fread(&
pcm.pcmFormatTag,
sizeof(
pcm.pcmFormatTag), 1,
fp);
106 ret =
fread(&
pcm.pcmChannels,
sizeof(
pcm.pcmChannels), 1,
fp);
111 if (
pcm.pcmChannels <= 0)
117 ret =
fread(&
pcm.pcmSamplesPerSecond,
sizeof(
pcm.pcmSamplesPerSecond), 1,
fp);
122 if (
pcm.pcmSamplesPerSecond <= 0)
128 ret =
fread(&
pcm.pcmBytesPerSecond,
sizeof(
pcm.pcmBytesPerSecond), 1,
fp);
133 if (
pcm.pcmBytesPerSecond <= 0)
139 ret =
fread(&
pcm.pcmBlockAlign,
sizeof(
pcm.pcmBlockAlign), 1,
fp);
145 ret =
fread(&
pcm.pcmBitsPerSample,
sizeof(
pcm.pcmBitsPerSample), 1,
fp);
150 if (
pcm.pcmBitsPerSample != 16)
209 int bitsPerSample = 16;
212 int align = channels*((bitsPerSample+7)/8);
220 pcm.pcmFormatTag = 1;
221 pcm.pcmChannels = channels;
223 pcm.pcmBytesPerSecond = align*
pcm.pcmSamplesPerSecond;
224 pcm.pcmBlockAlign = align;
225 pcm.pcmBitsPerSample = bitsPerSample;
240 fwrite(&
pcm.pcmSamplesPerSecond,
sizeof(
pcm.pcmSamplesPerSecond),1,
fp);
241 fwrite(&
pcm.pcmBytesPerSecond,
sizeof(
pcm.pcmBytesPerSecond),1,
fp);
252 int bitsPerSample = 16;
255 int align = channels*((bitsPerSample+7)/8);
287 pcm.pcmFormatTag = 1;
288 pcm.pcmChannels = channels;
290 pcm.pcmBytesPerSecond = align*
pcm.pcmSamplesPerSecond;
291 pcm.pcmBlockAlign = align;
292 pcm.pcmBitsPerSample = bitsPerSample;
308 fwrite(&
pcm.pcmSamplesPerSecond,
sizeof(
pcm.pcmSamplesPerSecond),1,
fp);
309 fwrite(&
pcm.pcmBytesPerSecond,
sizeof(
pcm.pcmBytesPerSecond),1,
fp);
334 fwrite(&cuePointId,
sizeof(cuePointId), 1,
fp);
336 fwrite(&dataChunkId,
sizeof(dataChunkId), 1,
fp);
337 fwrite(&chunkStart,
sizeof(chunkStart), 1,
fp);
338 fwrite(&blockStart,
sizeof(blockStart), 1,
fp);
339 fwrite(&sampleOffset,
sizeof(sampleOffset), 1,
fp);
360 std::string label =
marker.label;
369 fwrite(&cuePointId,
sizeof(cuePointId), 1,
fp);
370 fwrite(label.c_str(), label.length() + 1, 1,
fp);
403 int freq = header.
pcm.pcmSamplesPerSecond;
404 int channels = header.
pcm.pcmChannels;
405 int bits = header.
pcm.pcmBitsPerSample;
407 sound_data.
resize(samples,channels);
416 auto* data =
reinterpret_cast<NetInt16*
>(bytes.
get());
418 for (
int i=0; i<samples; i++) {
419 for (
int j=0; j<channels; j++) {
420 sound_data.
set(data[ct],i,j);
460 auto* data =
reinterpret_cast<NetInt16*
>(bytes.
get());
464 for (
size_t i=0; i<samples; i++) {
465 for (
size_t j=0; j<channels; j++) {
466 int v = sound_data.
get(i,j);
480 if (
dot_pos != std::string::npos)
A mini-server for performing network communication in the background.
An abstraction for a block of bytes, with optional responsibility for allocating/destroying that bloc...
void clear()
Disassociate object with any data block (deleting block if appropriate).
void allocate(size_t len)
Makes a data block of the specified length that will be deleted if this object is destroyed.
Class for storing sounds See Audio in YARP for additional documentation on YARP audio.
size_t getMarkersCount() const
Gets the number of markers contained in the sound.
void setFrequency(int freq)
Set the frequency of the sound (i.e.
yarp::sig::SoundMarker getMarker(size_t index) const
Get the marker at the specified index.
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.
audio_sample get(size_t sample, size_t channel=0) const
void set(audio_sample value, size_t sample, size_t channel=0)
size_t getSamples() const
Get the number of samples contained in the sound.
#define yCInfo(component,...)
#define yCError(component,...)
#define yCTrace(component,...)
#define yCWarning(component,...)
#define yCDebug(component,...)
#define YARP_LOG_COMPONENT(name,...)
An interface to the operating system, including Port based communication.
std::int16_t NetInt16
Definition of the NetInt16 type.
std::int32_t NetInt32
Definition of the NetInt32 type.
constexpr yarp::conf::vocab32_t createVocab32(char a, char b=0, char c=0, char d=0)
Create a vocab from chars.
bool read_wav_file(Sound &data, const char *filename)
Read a sound from a .wav audio file.
bool read_wav_bytestream(Sound &data, const char *bytestream, size_t streamsize)
Read a sound from a byte array.
bool write_wav_bytestream(const Sound &data, char *bytestream, size_t &streamsize)
Write a sound to a byte array.
bool write_wav_file(const Sound &data, const char *filename)
Write a sound to a .wav file.
#define YARP_END_PACK
Ends 1 byte packing for structs/classes.
#define YARP_BEGIN_PACK
Starts 1 byte packing for structs/classes.