本文整理汇总了C++中AudioFormatManager::createReaderFor方法的典型用法代码示例。如果您正苦于以下问题:C++ AudioFormatManager::createReaderFor方法的具体用法?C++ AudioFormatManager::createReaderFor怎么用?C++ AudioFormatManager::createReaderFor使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AudioFormatManager
的用法示例。
在下文中一共展示了AudioFormatManager::createReaderFor方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: set_file
//- LISP API -
// playback-set-file (string)fileName -> t/nil
base::cell_t set_file(base::lisp &gl, base::cell_t c, base::cells_t &) {
if (base::lisp::validate(c, base::cell::list(1), base::cell::typeString)) {
const auto &fname = c + 1;
// stop current playback
ts.stop();
ts.setSource(nullptr);
frs = nullptr;
AudioFormatReader *r;
// ectract CUE information (if any)
std::regex cue("^(.*):(\\d+):(\\d+)$");
std::smatch result;
std::regex_search(fname->s, result, cue);
if (result.size() == 4) {
// is cue
int32 start = base::fromStr<int32>(result[2].str());
int32 end = base::fromStr<int32>(result[3].str());
int32 duration = end - start;
AudioFormatReader *tr = fm.createReaderFor(File(result[1].str()));
// start, end are in frames (1 frame = 1/75 second) - convert to sample
float samplesInOneSecond = tr->sampleRate; // AudioSubsectionReader will handle channels count
float startSecond = (float)start / 75.0f;
float durationSecond = (float)duration / 75.0f;
float startSample = startSecond * samplesInOneSecond;
float durationSamples = durationSecond * samplesInOneSecond;
// some CUE may have 0 length (play to end)
if (end <= start)
durationSamples = tr->lengthInSamples;
r = new AudioSubsectionReader(tr, (int)startSample, (int)durationSamples, true);
}
else {
// regular file
r = fm.createReaderFor(File(fname->s));
}
if (r) {
frs = new AudioFormatReaderSource(r, true);
ts.setSource(frs, 32768, &thread, r->sampleRate);
return gl.t();
}
gl.signalError(base::strs("file not found or file format not supported: ", fname->s));
return gl.nil();
}
gl.signalError("playback-set-file: invalid arguments, expected (string)");
return gl.nil();
}
示例2: setFile
void IRAgent::setFile(const File& file, size_t fileChannel)
{
AudioFormatManager formatManager;
formatManager.registerBasicFormats();
ScopedPointer<AudioFormatReader> audioFormatReader(formatManager.createReaderFor(file));
{
ScopedLock lock(_mutex);
if (audioFormatReader)
{
if (_file == file && _fileChannel == fileChannel)
{
return;
}
_file = file;
_fileSampleCount = static_cast<size_t>(audioFormatReader->lengthInSamples);
_fileChannelCount = static_cast<size_t>(audioFormatReader->numChannels);
_fileSampleRate = audioFormatReader->sampleRate;
_fileChannel = fileChannel;
}
else
{
_file = File::nonexistent;
_fileSampleCount = 0;
_fileChannelCount = 0;
_fileSampleRate = 0.0;
_fileChannel = 0;
}
}
propagateChange();
updateConvolver();
}
示例3: setTickSample
void setTickSample (void const* audioData, int dataBytes)
{
ScopedPointer <MemoryInputStream> mis (new MemoryInputStream (audioData, dataBytes, false));
m_synth.clearVoices ();
m_synth.clearSounds ();
AudioFormatManager afm;
afm.registerBasicFormats ();
{
ScopedPointer <AudioFormatReader> afr (afm.createReaderFor (mis));
if (afr != nullptr)
{
mis.release ();
BigInteger midiNotes;
midiNotes.setRange (0, 127, true);
SynthesiserSound::Ptr sound = new SamplerSound (
"Tick",
*afr,
midiNotes,
60,
0,
0,
60./40.);
m_synth.addSound (sound);
m_synth.addVoice (new SamplerVoice);
}
}
}
示例4: filesDropped
void TrackComponent::filesDropped(const StringArray & files, int x, int)
{
for (auto current = files.begin(), end = files.end(); current != end; ++current)
{
const String fileString = *current;
String format;
if(fileString.contains(".wav") || fileString.contains(".WAV"))
format = "WAV";
else if(fileString.contains(".aif") || fileString.contains(".aiff") || fileString.contains(".AIF") || fileString.contains(".AIFF"))
format = "AIFF";
else if(fileString.contains(".flac") || fileString.contains(".FLAC"))
format = "FLAC";
File file(fileString);
AudioFormatManager formatManager;
formatManager.registerBasicFormats();
AudioFormatReader* reader = formatManager.createReaderFor(file);
Region* region = new SampleRegion(reader, 1, &file);
if(x > _mixerOffset)
{
int64 samplesRange = secondsToSamples((double)_numberOfClips, _sampleRate);
int64 positionSamples = pixelsToSamples(x - _mixerOffset, _numberOfClips * _pixelsPerClip, samplesRange);
_track->add(positionSamples, region);
createRegionGUI(x, region, formatManager, file);
}
else if(x < _mixerOffset)
{
_track->add(0, region);
createRegionGUI(_mixerOffset, region, formatManager, file);
}
}
}
示例5: MemoryInputStream
Oscillator::Oscillator (double sampleRate)
:
sampRate(sampleRate),
squareBuffer(1, 22071),
sawBuffer(1, 21984),
sawDownBuffer(1, 21984)
{
currentPhase = 0.0;
currentSample = 0.0;
stepSize = 0;
squareBuffer.clear();
sawBuffer.clear();
sawDownBuffer.clear();
sharedMemory.enter();
AudioFormatManager formatManager;
formatManager.registerBasicFormats();
ScopedPointer <AudioFormatReader> squareReader
(formatManager.createReaderFor(new MemoryInputStream (MainBinaryData::squarewave20500_wav,
MainBinaryData::squarewave20500_wavSize,
false)));
squareReader->read(&squareBuffer, 0, squareReader->lengthInSamples, 0, true, false);
squareNumSamples = squareReader->lengthInSamples;
ScopedPointer <AudioFormatReader> sawReader
(formatManager.createReaderFor(new MemoryInputStream (MainBinaryData::sawwave20500_wav,
MainBinaryData::sawwave20500_wavSize,
false)));
sawReader->read(&sawBuffer, 0, sawReader->lengthInSamples, 0, true, false);
ScopedPointer <AudioFormatReader> sawDownReader
(formatManager.createReaderFor(new MemoryInputStream (MainBinaryData::sawdownwave20500_wav,
MainBinaryData::sawdownwave20500_wavSize,
false)));
sawDownReader->read(&sawDownBuffer, 0, sawDownReader->lengthInSamples, 0, true, false);
sawNumSamples = sawReader->lengthInSamples;
sharedMemory.exit();
}
示例6: Thread
KeyAnalysisThread::KeyAnalysisThread(SingleAudioFileForAnalysis* _fileToAnalyze, AudioFormatManager& _audioFormatManager)
: Thread("Key Analysis Thread" + _fileToAnalyze->getFileName()),
fileToAnalyze(_fileToAnalyze)
//audioFormatManager(_audioFormatManager)
{
audioFormatReader = _audioFormatManager.createReaderFor(_fileToAnalyze->getFileToBeAnalyzed());
DBG("Creating thread: " << getThreadName());
interval = Random::getSystemRandom().nextInt(50) + 8;
startThread();
}
示例7: setPolyphony
void AudioFilePlayer::setPolyphony (int value)
{
int arraySize = fileSource.size();
if (value > arraySize)
{
AudioFormatManager formatManager;
formatManager.registerBasicFormats();
ScopedPointer <AudioFormatReader> reader (formatManager.createReaderFor (currentFile));
for (int i = 0; i < (value - arraySize); i++)
{
//add element
fileSource.add (new AudioTransportSource());
//add new element as an input source to audioMixer
audioMixer.addInputSource(fileSource.getLast(), false);
//apply audio file to new element
if (currentFile != File::nonexistent)
{
//here, do I need to do the...
//if (reader != 0)
//{
/// currentAudioFileSource = new AudioFormatReaderSource (reader, true);
//}
//... like in setAudioFile() above?
//this will involve having to delete currentAudioFileSource first.
addtoFileSourceArray (fileSource.size()-1, reader);
}
}
//set AFTER elements have been created so any calls to
//isCurrentlyPlaying() don't cause a crash due to
//elements not existing yet.
polyphony = value;
}
else if (value < arraySize)
{
//set BEFORE elements have been deleted so any calls to
//isCurrentlyPlaying() don't cause a crash due to
//elements not existing anymore.
polyphony = value;
for (int i = 0; i < (arraySize - value); i++)
{
//remove elements
audioMixer.removeInputSource(fileSource.getLast());
fileSource.removeLast();
}
}
}
示例8: set_file
//- LISP API -
// playback-set-file (string)fileName -> t/nil
base::cell_t set_file(base::lisp &gl, base::cell_t c, base::cells_t &) {
if (base::lisp::validate(c, base::cell::list(1), base::cell::typeString)) {
const auto &fname = c + 1;
// stop current playback
ts.stop();
ts.setSource(nullptr);
frs = nullptr;
AudioFormatReader *r;
// ectract CUE information (if any)
std::regex cue("^(.*):(\\d+):(\\d+)$");
std::smatch result;
std::regex_search(fname->s, result, cue);
if (result.size() == 4) {
// is cue
int32 start = base::fromStr<int32>(result[2].str());
int32 end = base::fromStr<int32>(result[3].str());
AudioFormatReader *tr = fm.createReaderFor(File(result[1].str()));
r = new AudioSubsectionReader(tr, start, end - start, true);
}
else {
// regular file
r = fm.createReaderFor(File(fname->s));
}
if (r) {
frs = new AudioFormatReaderSource(r, true);
ts.setSource(frs, 32768, &thread, r->sampleRate);
return gl.t();
}
gl.signalError(base::strs("file not found or file format not supported: ", fname->s));
return gl.nil();
}
gl.signalError("playback-set-file: invalid arguments, expected (string)");
return gl.nil();
}
示例9: readDataFile
bool FileWatcherThread::readDataFile(AudioSampleBuffer *buffer, File file) {
AudioFormatManager formatManager;
formatManager.registerBasicFormats();
ScopedPointer<AudioFormatReader> reader = formatManager.createReaderFor(file);
if (reader != 0) {
int sampleCount = (int) reader->lengthInSamples;
buffer->setSize(kNumSampleChannels, sampleCount, false, true, false);
reader->read(buffer, 0, sampleCount, 0, true, true);
if (reader->numChannels != kNumSampleChannels) {
printf("File is mono, copying data to second channel\n");
buffer->copyFrom(1, 0, *buffer, 0, 0, sampleCount);
}
return true;
}
return false;
}
示例10: setAudioFile
//called from either the constructor, or setSamplerAudioFilePath() in PadSettings
void AudioFilePlayer::setAudioFile (File audioFile_)
{
if (audioFile_ != File::nonexistent)
{
//passes in pads audio file
File audioFile (audioFile_);
//if the audio file is different from the previous one, stop and load in the new file
if (audioFile != currentFile)
{
// unload the previous file source and delete it..
broadcaster.sendActionMessage("OFF");
for (int i = 0; i < polyphony; i++)
{
fileSource[i]->stop();
fileSource[i]->setPosition(0.0);
fileSource[i]->setSource (0);
}
deleteAndZero (currentAudioFileSource);
// create a new file source from the file..
// get a format manager and set it up with the basic types (wav, ogg and aiff).
AudioFormatManager formatManager;
formatManager.registerBasicFormats();
AudioFormatReader* reader = formatManager.createReaderFor (audioFile);
if (reader != 0)
{
currentFile = audioFile;
currentAudioFileSource = new AudioFormatReaderSource (reader, true);
//add the audio file to the fileSource array
for (int i = 0; i < polyphony; i++)
{
addtoFileSourceArray(i, reader);
}
}
}
}
}
示例11: loadFileIntoTransport
void loadFileIntoTransport (const File& audioFile)
{
// unload the previous file source and delete it..
transportSource.stop();
transportSource.setSource (nullptr);
currentAudioFileSource = nullptr;
AudioFormatReader* reader = formatManager.createReaderFor (audioFile);
if (reader != nullptr)
{
currentAudioFileSource = new AudioFormatReaderSource (reader, true);
// ..and plug it into our transport source
transportSource.setSource (currentAudioFileSource,
32768, // tells it to buffer this many samples ahead
&thread, // this is the background thread to use for reading-ahead
reader->sampleRate); // allows for sample rate correction
}
}
示例12: initWithJuceFile
void DiskIn::initWithJuceFile(File const& file,
bool loopFlag,
const double startTime,
const int numFrames,
const UGen::DoneAction doneAction) throw()
{
AudioFormatManager formatManager;
formatManager.registerBasicFormats();
AudioFormatReader* reader = formatManager.createReaderFor (file);
int numChannels = reader->numChannels;
delete reader;
initInternal(numChannels);
generateFromProxyOwner(new DiskInUGenInternal(file,
numChannels,
loopFlag,
startTime,
numFrames,
doneAction));
}
示例13: loadFileIntoTransport
void AudioDemoPlaybackPage::loadFileIntoTransport (const File& audioFile)
{
// unload the previous file source and delete it..
transportSource.stop();
transportSource.setSource (0);
deleteAndZero (currentAudioFileSource);
// get a format manager and set it up with the basic types (wav and aiff).
AudioFormatManager formatManager;
formatManager.registerBasicFormats();
AudioFormatReader* reader = formatManager.createReaderFor (audioFile);
if (reader != 0)
{
currentAudioFileSource = new AudioFormatReaderSource (reader, true);
// ..and plug it into our transport source
transportSource.setSource (currentAudioFileSource,
32768, // tells it to buffer this many samples ahead
reader->sampleRate);
}
}
示例14: mouseDown
void TrackComponent::mouseDown(const MouseEvent &e) {
ModifierKeys modifiers = ModifierKeys::getCurrentModifiersRealtime();
int posX;
// check the mod keys ..
if (modifiers.isPopupMenu() || modifiers.isCtrlDown())
{
ScopedPointer<PopupMenu> trackMenu_ = new PopupMenu();
trackMenu_->clear();
trackMenu_->addCommandItem(&_commands, MainWindow::showMixer);
trackMenu_->addItem(1, "Add Region", true);
MouseEvent ev = e.getEventRelativeTo(this);
for(auto region : _regionComponents)
{
posX = ev.x;
region->setBroughtToFrontOnMouseClick(true);
if(region->getPositionX() < posX && posX < (region->getPositionX() + region->getRegionWidth()))
{
trackMenu_->addItem(2, "Remove Region", true);
}
}
switch (trackMenu_->show())
{
case 1:
{
FileChooser chooser("Select an audio file to add...",
File::nonexistent,
"*.wav; *aif; *.flac");
if (chooser.browseForFileToOpen()) {
File audioFile(chooser.getResult());
const String fileString = audioFile.getFullPathName();
String format;
if (fileString.contains(".wav"))
format = "WAV";
else if (fileString.contains(".aif") || fileString.contains(".aiff"))
format = "AIFF";
else if (fileString.contains(".flac"))
format = "FLAC";
AudioFormatManager formatManager;
formatManager.registerBasicFormats();
AudioFormatReader* reader = formatManager.createReaderFor(audioFile);
Audio::Region* region = new Audio::SampleRegion(reader, 1, &audioFile);
Point<int> position = e.getPosition();
int x = position.getX();
if (x > _mixerOffset)
{
int64 samplesRange = secondsToSamples(100, _sampleRate);
int64 positionSamples = pixelsToSamples(x - _mixerOffset, 100 * _pixelsPerClip, samplesRange);
_track->add(positionSamples, region);
createRegionGUI(x, region, formatManager, audioFile);
getParentComponent()->resized();
}
else if (x < _mixerOffset)
{
_track->add(0, region);
createRegionGUI(_mixerOffset, region, formatManager, audioFile);
getParentComponent()->resized();
}
}
}
break;
case 2:
{
CriticalSection critical;
critical.enter();
for(size_t i = 0; i < _regionComponents.size(); ++i)
{
Rectangle<int> bounds_ = _regionComponents.at(i)->getBounds();
posX = ev.x;
if((int)_regionComponents.at(i)->getPositionX() < posX && posX < ((int)_regionComponents.at(i)->getPositionX() + (int)_regionComponents.at(i)->getRegionWidth()))
{
_track->remove(_regionComponents.at(i)->getRegion(), _posX.at(i));
std::vector<RegionComponent*>::iterator regit = _regionComponents.begin() + i;
RegionComponent* component = _regionComponents.at(i);
removeChildComponent(_regionComponents.at(i));
_regionComponents.erase(regit);
delete component;
_regions.erase(_posX.at(i));
std::vector<int64>::iterator posit = _posX.begin() + i;;
_posX.erase(posit);
std::vector<int64>::iterator sampsit = _sizeSamps.begin() + i;;
_sizeSamps.erase(sampsit);
}
}
critical.exit();
}
default:
break;
}
}
}
示例15: loadIr
bool Mcfx_convolverAudioProcessor::loadIr(AudioSampleBuffer* IRBuffer, const File& audioFile, int channel, double &samplerate, float gain, int offset, int length)
{
if (!audioFile.existsAsFile())
{
std::cout << "ERROR: file does not exist!!" << std::endl;
return false;
}
AudioFormatManager formatManager;
// this can read .wav and .aiff
formatManager.registerBasicFormats();
AudioFormatReader* reader = formatManager.createReaderFor(audioFile);
if (!reader) {
std::cout << "ERROR: could not read impulse response file!" << std::endl;
return false;
}
//AudioFormatReader* reader = wavFormat.createMemoryMappedReader(audioFile);
int64 ir_length = (int)reader->lengthInSamples-offset;
if (ir_length <= 0) {
std::cout << "wav file has zero samples" << std::endl;
return false;
}
if (reader->numChannels <= channel) {
std::cout << "wav file doesn't have enough channels: " << reader->numChannels << std::endl;
return false;
}
AudioSampleBuffer ReadBuffer(reader->numChannels, ir_length); // create buffer
reader->read(&ReadBuffer, 0, ir_length, offset, true, true);
// set the samplerate -> maybe we have to resample later...
samplerate = reader->sampleRate;
//std::cout << "ReadRMS: " << ReadBuffer.getRMSLevel(channel, 0, ir_length) << std::endl;
// check if we want a shorter impulse response
if (ir_length > length && length != 0)
ir_length = length;
// copy the wanted channel into our IR Buffer
IRBuffer->setSize(1, ir_length);
IRBuffer->copyFrom(0, 0, ReadBuffer, channel, 0, ir_length);
// scale ir with gain
IRBuffer->applyGain(gain);
// std::cout << "ReadRMS: " << IRBuffer->getRMSLevel(0, 0, ir_length) << std::endl;
delete reader;
return true;
}