本文整理汇总了C++中AudioFormatManager类的典型用法代码示例。如果您正苦于以下问题:C++ AudioFormatManager类的具体用法?C++ AudioFormatManager怎么用?C++ AudioFormatManager使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了AudioFormatManager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: TextButton
AudioFileSelector::AudioFileSelector()
{
AudioFormatManager formatManager;
formatManager.registerBasicFormats();
playButton = new TextButton ("u", "click here to play the current audio file");
playButton->addListener (this);
playButton->setColour (TextButton::buttonColourId, Colours::white);
playButton->setColour (TextButton::buttonOnColourId, Colours::grey);
playButton->setConnectedEdges (Button::ConnectedOnRight | Button::ConnectedOnLeft);
fileChooser = new FilenameComponent ("AudioFile",
File::nonexistent,
true, false, false,
formatManager.getWildcardForAllFormats(),
String::empty,
"(choose an audio file)");
addAndMakeVisible (playButton);
addAndMakeVisible (fileChooser);
fileChooser->addListener (this);
fileChooser->setBrowseButtonText ("...");
}
示例2: if
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);
}
}
}
示例3: 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();
}
示例4: 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);
}
}
}
示例5: 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();
}
}
}
示例6: carla_get_supported_file_extensions
const char* carla_get_supported_file_extensions()
{
carla_debug("carla_get_supported_file_extensions()");
static CarlaString retText;
if (retText.isEmpty())
{
retText =
// Base types
"*.carxp;*.carxs"
// MIDI files
";*.mid;*.midi"
#ifdef HAVE_FLUIDSYNTH
// fluidsynth (sf2)
";*.sf2"
#endif
#ifdef HAVE_LINUXSAMPLER
// linuxsampler (gig and sfz)
";*.gig;*.sfz"
#endif
#ifdef WANT_ZYNADDSUBFX
// zynaddsubfx presets
";*.xmz;*.xiz"
#endif
;
#ifndef BUILD_BRIDGE
// Audio files
{
using namespace juce;
AudioFormatManager afm;
afm.registerBasicFormats();
String juceFormats;
for (AudioFormat **it=afm.begin(), **end=afm.end(); it != end; ++it)
{
const StringArray& exts((*it)->getFileExtensions());
for (String *eit=exts.begin(), *eend=exts.end(); eit != eend; ++eit)
juceFormats += String(";*" + (*eit)).toRawUTF8();
}
retText += juceFormats.toRawUTF8();
}
#endif
}
return retText;
}
示例7: sampRate
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();
}
示例8: 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;
}
示例9: 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();
}
示例10: audioFile
//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: throw
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));
}
示例12: deleteAndZero
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);
}
}
示例13: createDictionary
void Dictionary::createDictionary(std::string outputDir)
{
//open output file
std::fstream outputFile;
outputFile.open(outputDir+"W.txt", std::ios::out);
if (!outputFile.is_open()) {
std::cout << "Text file open error!";
return;
}
//prepare to read file
AudioFormatManager formatManager;
formatManager.registerBasicFormats();
kiss_fft_cfg fwd= kiss_fft_alloc(FFT_SIZE,0,NULL,NULL);
// HARD CODING HERE. REQUIRES MODIFICATION
float fs = 44100;
int nChannels = 2;
numSamplesToRead = round(fs*SECS_PER_BLOCK);
numSamplesPerBlock = numSamplesToRead/DOWNSAMPLE_RATE;
AudioSampleBuffer buffer(nChannels, numSamplesToRead);
float* audioBuffer = new float[numSamplesToRead];
for (int track = 21; track<=108; track++) {
// ANY BETTER WAYS TO DEAL WITH FILENAMES??
std::string strFileDir = sampleFileFolder + "MAPS_ISOL_NO_M_S0_M"+std::to_string(track)+"_AkPnBcht.wav";
File audioFileS0(strFileDir);
AudioFormatReader* reader;
if (audioFileS0.exists()) {
reader = formatManager.createReaderFor(audioFileS0);
}
else {
strFileDir = sampleFileFolder + "MAPS_ISOL_NO_M_S1_M"+std::to_string(track)+"_AkPnBcht.wav";
File audioFileS1(strFileDir);
reader = formatManager.createReaderFor(audioFileS1);
}
reader->read(&buffer, 0, numSamplesToRead, fs, true, true);
float* leftBuffer = buffer.getSampleData(0);
float* rightBuffer = buffer.getSampleData(1);
for (int i=0; i<numSamplesToRead; i++) {
audioBuffer[i] = (leftBuffer[i]+rightBuffer[i])/2;
}
antiAlias(audioBuffer, numSamplesToRead);
for (int i=0; i<numSamplesPerBlock; i++) {
audio[i].real( audioBuffer[i*DOWNSAMPLE_RATE]*hammWin(i, numSamplesPerBlock) );
audio[i].imag(0);
}
for (int i = numSamplesPerBlock; i<FFT_SIZE; i++) {
audio[i].real(0);
audio[i].imag(0);
}
kiss_fft(fwd, (kiss_fft_cpx*) audio, (kiss_fft_cpx*)spectrum);
for (int i = 0; i<FFT_SIZE/2; i++) {
W[i][track-21] = abs(spectrum[i]); //HARD CODING HERE!
}
delete reader;
}
delete [] audioBuffer;
for(int i = 0; i< FFT_SIZE/2; i++){
for (int j = 0; j<N_NOTES; j++) {
// fwrite(&W[i][j], sizeof(float), 1, file);
outputFile << W[i][j] << "\t";
}
outputFile<<std::endl;
}
outputFile.close();
}
示例14: getAudioFormatManagerInstance
static AudioFormatManager& getAudioFormatManagerInstance()
{
static AudioFormatManager afm;
afm.registerBasicFormats();
return afm;
}
示例15: PopupMenu
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;
}
}
}