NOTE: This documentation section is a work in progress!
Using std::vector with nom::SoundFileReader
NOM_ASSERT(fp != nullptr);
if(fp == nullptr) {
NOM_LOG_ERR(NOM_LOG_CATEGORY_APPLICATION,
"Failed to create audio buffer: out of memory!");
return;
}
if(fp->open(filename, metadata) == false) {
NOM_LOG_ERR(NOM_LOG_CATEGORY_APPLICATION,
"Could not load audio from input file:", filename);
return;
}
NOM_ASSERT(fp->valid() == true);
const nom::size_type CHUNK_SIZE = metadata.total_bytes;
std::vector<int16> read_buffer;
std::vector<int16> buffer = nullptr;
nom::size_type total_samples_read = 0;
int64 samples_read = -1;
while(samples_read != 0) {
samples_read = fp->read(read_buffer.data(), CHUNK_SIZE);
auto& samples = buffer;
samples.insert(samples.end(), read_buffer.begin(),
read_buffer.begin() + samples_read);
total_samples_read += samples_read;
if(total_samples_read >= CHUNK_SIZE) {
break;
}
}
delete NOM_SCAST(int16*, buffer);
buffer = nullptr;