本文整理汇总了C++中AudioFormatReader::searchForLevel方法的典型用法代码示例。如果您正苦于以下问题:C++ AudioFormatReader::searchForLevel方法的具体用法?C++ AudioFormatReader::searchForLevel怎么用?C++ AudioFormatReader::searchForLevel使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AudioFormatReader
的用法示例。
在下文中一共展示了AudioFormatReader::searchForLevel方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: update
void Sample::update(const String& path, WavAudioFormat& wavAudioFormat)
{
// Don't load a subsequent sample if a new sample is already loaded (but not yet played).
if (_readyToSwap)
return;
// Find audio file.
String fileName(path);
fileName = File::addTrailingSeparator(fileName);
fileName += _name;
fileName += EXT;
File file(fileName);
Time modification = file.getLastModificationTime();
if (modification <= _lastModification)
return;
// Read audio file. We only read the left channel, mono is good enough.
AudioFormatReader* reader = wavAudioFormat.createReaderFor(file.createInputStream(), true);
if (reader == nullptr)
return;
_lastModification = modification;
int64 start = reader->searchForLevel(0, reader->lengthInSamples, SAMPLE_START_THRESHOLD, 1.0, 0);
if (start == -1)
start = 0;
int count = (int)(reader->lengthInSamples - start);
_processor->writeTrace(String() << "Loading " << _name << " from disk (skip=" << start << ")");
int newIndex = !_bufferIndex;
AudioSampleBuffer* buffer = &(_buffers[newIndex]);
buffer->setSize(1, count);
reader->read(buffer, 0, count, start, true, false);
delete reader;
// Done.
_readyToSwap = true;
}