110 if (
pcm.pcmChannels <= 0)
116 ret =
fread(&
pcm.pcmSamplesPerSecond,
sizeof(
pcm.pcmSamplesPerSecond), 1,
fp);
121 if (
pcm.pcmSamplesPerSecond <= 0)
132 if (
pcm.pcmBytesPerSecond <= 0)
149 if (
pcm.pcmBitsPerSample != 16)
219 pcm.pcmFormatTag = 1;
220 pcm.pcmChannels = channels;
222 pcm.pcmBytesPerSecond = align*
pcm.pcmSamplesPerSecond;
223 pcm.pcmBlockAlign = align;
239 fwrite(&
pcm.pcmSamplesPerSecond,
sizeof(
pcm.pcmSamplesPerSecond),1,
fp);
240 fwrite(&
pcm.pcmBytesPerSecond,
sizeof(
pcm.pcmBytesPerSecond),1,
fp);
268 int freq = header.
pcm.pcmSamplesPerSecond;
269 int channels = header.
pcm.pcmChannels;
270 int bits = header.
pcm.pcmBitsPerSample;
272 sound_data.
resize(samples,channels);
281 auto* data =
reinterpret_cast<NetInt16*
>(bytes.
get());
283 for (
int i=0; i<samples; i++) {
284 for (
int j=0;
j<channels;
j++) {
285 sound_data.
set(data[ct],i,
j);
312 auto* data =
reinterpret_cast<NetInt16*
>(bytes.
get());
316 for (
size_t i=0; i<samples; i++) {
317 for (
size_t j=0;
j<channels;
j++) {
318 int v = sound_data.
get(i,
j);
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.
void setFrequency(int freq)
Set the frequency of the sound (i.e.
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 yCError(component,...)
#define yCTrace(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 write_wav_file(const Sound &data, const char *filename)
Write a sound to a .wav file.
bool read_wav_bytestream(Sound &data, const char *bytestream)
Read a sound from a byte array.
#define YARP_END_PACK
Ends 1 byte packing for structs/classes.
#define YARP_BEGIN_PACK
Starts 1 byte packing for structs/classes.