37 const char* file_ext = strrchr(filename,
'.');
38 if (file_ext ==
nullptr)
40 yCError(SOUNDFILE) <<
"cannot find file extension in file name";
44 if (strcmp(file_ext,
".wav") == 0)
48 else if (strcmp(file_ext,
".mp3") == 0)
52 yCError(SOUNDFILE) <<
"Unknown file format";
58 if (strcmp(format.c_str(),
".wav") == 0)
62 else if (strcmp(format.c_str(),
".mp3") == 0)
66 yCError(SOUNDFILE) <<
"Unknown file format";
72 const char* file_ext = strrchr(filename,
'.');
73 if (file_ext ==
nullptr)
75 yCError(SOUNDFILE) <<
"cannot find file extension in file name";
79 if (strcmp(file_ext,
".wav") == 0)
83 else if (strcmp(file_ext,
".mp3") == 0)
88 yCError(SOUNDFILE) <<
"Unknown file format";
99 yCError(SOUNDFILE,
"Unable to read data from file %s", filename);
110 m_sound_data.resize(0,0);
120 yCError(SOUNDFILE,
"File is not open yet");
124 if (m_index+block_size>m_totsize) {block_size= m_totsize-m_index;}
125 dest = m_sound_data.
subSound(m_index,m_index+block_size);
126 m_index += block_size;
134 yCError(SOUNDFILE,
"File is not open yet");
137 m_index=sample_offset;
145 yCError(SOUNDFILE,
"File is not open yet");
Class for storing sounds See Audio in YARP for additional documentation on YARP audio.
Sound subSound(size_t first_sample, size_t last_sample)
Returns a subpart of the sound.
size_t getSamples() const
Get the number of samples contained in the sound.
bool open(const char *filename)
bool rewind(size_t sample_offset=0)
size_t readBlock(Sound &dest, size_t block_size)
#define yCError(component,...)
#define YARP_LOG_COMPONENT(name,...)
An interface to the operating system, including Port based communication.
bool read(ImageOf< PixelRgb > &dest, const std::string &src, image_fileformat format=FORMAT_ANY)
bool write_mp3_file(const Sound &data, const char *filename, size_t bitrate=64000)
Write a sound to a mp3 file.
bool read_wav_file(Sound &data, const char *filename)
Read a sound from a .wav audio file.
bool read_mp3_file(Sound &data, const char *filename)
Read a sound from a .mp3 audio file.
bool read_mp3_bytestream(Sound &data, const char *bytestream, size_t streamsize)
Read a sound from a byte array.
bool write(const ImageOf< PixelRgb > &src, const std::string &dest, image_fileformat format=FORMAT_PPM)
bool read_bytestream(Sound &data, const char *filename, size_t streamsize, std::string format)
Read a sound from a byte array.
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.