本文整理汇总了C++中WavAudioFormat类的典型用法代码示例。如果您正苦于以下问题:C++ WavAudioFormat类的具体用法?C++ WavAudioFormat怎么用?C++ WavAudioFormat使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了WavAudioFormat类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: startRecording
//==============================================================================
void startRecording (const File& file)
{
stop();
if (sampleRate > 0)
{
// Create an OutputStream to write to our destination file...
file.deleteFile();
ScopedPointer<FileOutputStream> fileStream (file.createOutputStream());
if (fileStream != 0)
{
// Now create a WAV writer object that writes to our output stream...
WavAudioFormat wavFormat;
AudioFormatWriter* writer = wavFormat.createWriterFor (fileStream, sampleRate, 1, 16, StringPairArray(), 0);
if (writer != 0)
{
fileStream.release(); // (passes responsibility for deleting the stream to the writer object that is now using it)
// Now we'll create one of these helper objects which will act as a FIFO buffer, and will
// write the data to disk on our background thread.
threadedWriter = new AudioFormatWriter::ThreadedWriter (writer, backgroundThread, 32768);
// And now, swap over our active writer pointer so that the audio callback will start using it..
const ScopedLock sl (writerLock);
activeWriter = threadedWriter;
}
}
}
}
开发者ID:HsienYu,项目名称:JUCE,代码行数:32,代码来源:AudioDemoRecordPage.cpp
示例2: setUsingSampledSound
void setUsingSampledSound()
{
synth.clearSounds();
WavAudioFormat wavFormat;
AudioFormatReader* audioReader
= wavFormat.createReaderFor (new MemoryInputStream (BinaryData::cello_wav,
BinaryData::cello_wavSize,
false),
true);
BitArray allNotes;
allNotes.setRange (0, 128, true);
synth.addSound (new SamplerSound (T("demo sound"),
*audioReader,
allNotes,
74, // root midi note
0.1, // attack time
0.1, // release time
10.0 // maximum sample length
));
delete audioReader;
}
开发者ID:skhanker,项目名称:music-tutor,代码行数:26,代码来源:PHISynth.cpp
示例3: stop
/*
Start recording to a specified file
*/
void Audio::AudioRecorder::startRecording (const File& file)
{
// make sure recorder is stopped first
stop();
if (sampleRate > 0)
{
// delete file contents first
file.deleteFile();
// create file stream for file
ScopedPointer<FileOutputStream> fileStream (file.createOutputStream());
if (fileStream != nullptr)
{
// create a wav format writer
WavAudioFormat wavFormat;
AudioFormatWriter* writer = wavFormat.createWriterFor (fileStream, sampleRate, 1, 16, StringPairArray(), 0);
if (writer != nullptr)
{
fileStream.release();
// create a thread for the writer.
threadedWriter = new AudioFormatWriter::ThreadedWriter (writer, backgroundThread, 32768);
// set the next sample number to start
nextSampleNum = 0;
// scoped lock for writer
const ScopedLock sl (writerLock);
activeWriter = threadedWriter;
}
}
}
}
开发者ID:Bk8,项目名称:mordaw,代码行数:37,代码来源:Recorder.cpp
示例4: file
SampleItem::SampleItem(const String &filename)
{
this->filename = filename;
File file(filename);
if (file.exists())
{
shortname = file.getFileNameWithoutExtension();
FileInputStream *stream = new FileInputStream(file);
WavAudioFormat format;
AudioFormatReader *reader = format.createReaderFor(stream, false);
if (reader)
{
formatName = reader->getFormatName();
sampleRate = (int)reader->sampleRate;
size = (int)reader->lengthInSamples;
bits = reader->bitsPerSample;
delete reader;
}
else
{
sampleRate = 0;
size = 0;
bits = 0;
}
}
playing = false;
}
开发者ID:imekon,项目名称:juce-samples,代码行数:29,代码来源:SampleItem.cpp
示例5: initialiseSynth
void BeatboxVoxAudioProcessor::initialiseSynth()
{
/** NOTE: - Quick and dirty sample drum synth for prototype
* In future versions will ideally allow user to select sample to use and
* also manage sample rate changes effect on loaded samples.
*/
WavAudioFormat wavFormat;
BigInteger kickNoteRange;
BigInteger snareNoteRange;
BigInteger hihatNoteRange;
BigInteger osdTestSoundNoteRange;
drumSynth.clearSounds();
osdTestSynth.clearSounds();
std::unique_ptr<AudioFormatReader> readerKickDrum(wavFormat.createReaderFor(new MemoryInputStream(BinaryData::bassdrum_wav,
BinaryData::bassdrum_wavSize,
false),
true));
std::unique_ptr<AudioFormatReader> readerSnareDrum(wavFormat.createReaderFor(new MemoryInputStream(BinaryData::snaredrum_wav,
BinaryData::snaredrum_wavSize,
false),
true));
std::unique_ptr<AudioFormatReader> readerHiHat(wavFormat.createReaderFor(new MemoryInputStream(BinaryData::hihat_wav,
BinaryData::hihat_wavSize,
false),
true));
std::unique_ptr<AudioFormatReader> readerOSDTestSound(wavFormat.createReaderFor(new MemoryInputStream(BinaryData::osdTestOne_wav,
BinaryData::osdTestOne_wavSize,
false),
true));
kickNoteRange.setBit(kickNoteNumber);
snareNoteRange.setBit(snareNoteNumber);
hihatNoteRange.setBit(hihatNoteNumber);
osdTestSoundNoteRange.setBit(osdTestSoundNoteNumber);
drumSynth.addSound(new SamplerSound("Kick Sound", *readerKickDrum, kickNoteRange, kickNoteNumber, 0.0, 0.0, 5.0));
drumSynth.addSound(new SamplerSound("Snare Sound", *readerSnareDrum, snareNoteRange, snareNoteNumber, 0.0, 0.0, 5.0));
drumSynth.addSound(new SamplerSound("HiHat Sound", *readerHiHat, hihatNoteRange, hihatNoteNumber, 0.0, 0.0, 5.0));
drumSynth.addVoice(new SamplerVoice());
drumSynth.addSound(new NoiseSound(noiseNoteNumber));
drumSynth.addVoice(new NoiseVoice());
osdTestSynth.addSound(new SamplerSound("OSD Test Sound", *readerOSDTestSound, osdTestSoundNoteRange, osdTestSoundNoteNumber, 0.0, 0.0, 5.0));
osdTestSynth.addVoice(new SamplerVoice());
}
开发者ID:JoshMarler,项目名称:beatbox-vox,代码行数:54,代码来源:PluginProcessor.cpp
示例6: setDrumSound
void DrumMachine::setDrumSound(String soundName, File sample) {
WavAudioFormat wavFormat;
ScopedPointer<AudioFormatReader> audioReader(wavFormat.createReaderFor(new FileInputStream(sample), true));
BigInteger notes;
notes.setRange(lastNote, 1, true);
synth.addSound(new SamplerSound(soundName, *audioReader, notes,
lastNote, // root midi note
0.0, // attack time
0.0, // release time
10.0 // maximum sample length
));
soundToNote.set(soundName, lastNote++);
}
开发者ID:zenAudio,项目名称:beatmatic-xcode,代码行数:17,代码来源:drummachine.cpp
示例7: Writer
Writer (OutputStream* destStream, const String& formatName,
const File& lameApp, int vbr, int cbr,
double sampleRate, unsigned int numberOfChannels,
unsigned int bitsPerSample, const StringPairArray& metadata)
: AudioFormatWriter (destStream, formatName, sampleRate,
numberOfChannels, bitsPerSample),
vbrLevel (vbr), cbrBitrate (cbr),
tempWav (".wav")
{
WavAudioFormat wavFormat;
if (FileOutputStream* out = tempWav.getFile().createOutputStream())
{
writer = wavFormat.createWriterFor (out, sampleRate, numChannels,
bitsPerSample, metadata, 0);
args.add (lameApp.getFullPathName());
args.add ("--quiet");
if (cbrBitrate == 0)
{
args.add ("--vbr-new");
args.add ("-V");
args.add (String (vbrLevel));
}
else
{
args.add ("--cbr");
args.add ("-b");
args.add (String (cbrBitrate));
}
addMetadataArg (metadata, "id3title", "--tt");
addMetadataArg (metadata, "id3artist", "--ta");
addMetadataArg (metadata, "id3album", "--tl");
addMetadataArg (metadata, "id3comment", "--tc");
addMetadataArg (metadata, "id3date", "--ty");
addMetadataArg (metadata, "id3genre", "--tg");
addMetadataArg (metadata, "id3trackNumber", "--tn");
}
}
开发者ID:LeapMotionRV,项目名称:Badaboum,代码行数:42,代码来源:juce_LAMEEncoderAudioFormat.cpp
示例8: stop
void AudioRecorder::startRecording(const File& file){
stop();
if (sampleRate > 0) {
file.deleteFile();
ScopedPointer<FileOutputStream> fileStream(file.createOutputStream());
if (fileStream != nullptr) {
WavAudioFormat wavFormat;
AudioFormatWriter* writer = wavFormat.createWriterFor(fileStream,
sampleRate, 1, 16, StringPairArray(), 0);
if (writer != nullptr) {
fileStream.release();
threadedWriter = new AudioFormatWriter::ThreadedWriter(writer,
backgroundThread, 32768);
// thumbnail.reset(writer->getNumChannels(), writer->getSampleRate());
nextSampleNum = 0;
const ScopedLock sl(writerLock);
activeWriter = threadedWriter;
}
}
}
}
开发者ID:milrob,项目名称:mastersProject,代码行数:21,代码来源:AudioRecorder.cpp
示例9: setUsingSampledSound
void setUsingSampledSound()
{
WavAudioFormat wavFormat;
ScopedPointer<AudioFormatReader> audioReader (wavFormat.createReaderFor (new MemoryInputStream (BinaryData::cello_wav,
BinaryData::cello_wavSize,
false),
true));
BigInteger allNotes;
allNotes.setRange (0, 128, true);
synth.clearSounds();
synth.addSound (new SamplerSound ("demo sound",
*audioReader,
allNotes,
74, // root midi note
0.1, // attack time
0.1, // release time
10.0 // maximum sample length
));
}
开发者ID:AmirooR,项目名称:JUCE,代码行数:22,代码来源:AudioSynthesiserDemo.cpp
示例10: switch
void MainPanel::setAudio (int audioId)
{
AudioSource* source = 0;
switch (audioId)
{
case 1: // Amen Break
{
WavAudioFormat waf;
AudioFormatReader* afr = waf.createReaderFor (
new MemoryInputStream (binaries::amenbreakloop_wav,
binaries::amenbreakloop_wavSize,
false),
true);
source = new ResamplingReader (afr);
}
break;
case 2: // sine wave
{
ToneGeneratorAudioSource* tgas = new ToneGeneratorAudioSource ();
tgas->setFrequency (440);
tgas->setAmplitude (1.f);
source = tgas;
}
break;
case 3: // White Noise
source = new NoiseAudioSource;
break;
case 4: // Pink Noise
source = new NoiseAudioSource (true);
break;
};
MainApp::getInstance().getAudioOutput().setSource (source);
}
开发者ID:EQ4,项目名称:DSPFiltersDemo,代码行数:39,代码来源:MainPanel.cpp
示例11: 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;
}
开发者ID:bystam,项目名称:remote-goat,代码行数:41,代码来源:PluginProcessor.cpp
示例12: menuItemSelected
virtual void menuItemSelected(int menuItemID, int)
{
if (menuItemID == 200)
{
WildcardFileFilter wildcardFilter("*.mid", String::empty, "Midi files");
FileBrowserComponent browser(FileBrowserComponent::canSelectFiles | FileBrowserComponent::openMode,
lastOpenedFile.exists() ? lastOpenedFile : File(String("C:\\Users\\GeorgeKrueger\\Documents")), &wildcardFilter, nullptr);
FileChooserDialogBox dialogBox("Open a midi file",
"Please choose a midi file to open...",
browser,
false,
Colours::lightgrey);
if (dialogBox.show())
{
File selectedFile = browser.getSelectedFile(0);
lastOpenedFile = selectedFile;
FileInputStream fileStream(selectedFile);
juce::MidiFile midiFile;
midiFile.readFrom(fileStream);
int numTracks = midiFile.getNumTracks();
midiFile.convertTimestampTicksToSeconds();
String msg;
msg << "Opened midi file: " << selectedFile.getFileName() << " Tracks: " << numTracks << "\n";
log(msg);
for (int i = 0; i < numTracks; ++i)
{
const MidiMessageSequence* msgSeq = midiFile.getTrack(i);
OwnedArray<PluginDescription> results;
String plugFile = "C:\\VST\\FMMF.dll";
VSTPluginFormat vstFormat;
vstFormat.findAllTypesForFile(results, plugFile);
if (results.size() > 0) {
msg.clear();
msg << "Found " << results.size() << " plugin(s) matching file " << plugFile << "\n";
log(msg);
int secsToRender = 10;
double sampleRate = 44100;
int totalSizeInSamples = static_cast<int>(44100 * secsToRender);
AudioPluginInstance* plugInst = vstFormat.createInstanceFromDescription(*results[0], sampleRate, totalSizeInSamples);
if (!plugInst) {
msg.clear();
msg << "Failed to load plugin " << plugFile << "\n";
log(msg);
continue;
}
int numInputChannels = plugInst->getTotalNumInputChannels();
int numOutputChannels = plugInst->getTotalNumOutputChannels();
msg.clear();
msg << "Plugin input channels: " << numInputChannels << " output channels: " << numOutputChannels
<< " Current program: " << plugInst->getCurrentProgram() << "\n";
log(msg);
int maxChannels = std::max(numInputChannels, numOutputChannels);
AudioBuffer<float> buffer(maxChannels, totalSizeInSamples);
MidiBuffer midiMessages;
for (int j = 0; j < msgSeq->getNumEvents(); ++j)
{
MidiMessageSequence::MidiEventHolder* midiEventHolder = msgSeq->getEventPointer(j);
MidiMessage midiMsg = midiEventHolder->message;
int samplePos = static_cast<int>(midiMsg.getTimeStamp() * sampleRate);
midiMessages.addEvent(midiMsg, samplePos);
}
plugInst->prepareToPlay(sampleRate, totalSizeInSamples);
plugInst->processBlock(buffer, midiMessages);
/*File txtOutFile("C:\\Users\\GeorgeKrueger\\Documents\\GitHub\\soundserver2\\out.txt");
FileOutputStream* txtOutStream = txtOutFile.createOutputStream();
for (int j = 0; j < 44100; ++j)
{
float sample = buffer.getSample(0, j);
txtOutStream->writeFloat(sample);
txtOutStream->writeText(" ", true, false);
}*/
File outputFile("C:\\Users\\GeorgeKrueger\\Documents\\GitHub\\soundserver2\\out.wav");
if (outputFile.exists()) {
outputFile.deleteFile();
}
FileOutputStream* fileOutputStream = outputFile.createOutputStream();
WavAudioFormat wavFormat;
StringPairArray metadataValues;
juce::AudioFormatWriter* wavFormatWriter = wavFormat.createWriterFor(
fileOutputStream, sampleRate, 2, 16, metadataValues, 0);
bool writeAudioDataRet = wavFormatWriter->writeFromAudioSampleBuffer(buffer, 0, buffer.getNumSamples());
wavFormatWriter->flush();
msg.clear();
msg << "Done writing to output file " << outputFile.getFileName() << " . Write return value: "
<< (int)writeAudioDataRet << "\n";
log(msg);
delete wavFormatWriter;
delete plugInst;
//.........这里部分代码省略.........
开发者ID:georgekrueger,项目名称:soundserver2,代码行数:101,代码来源:Main.cpp
示例13: ISTFT
//.........这里部分代码省略.........
// inverse short time fourier transform on temp_L and temp_R
istft->performInverseTransform(temp_L, ifftResults_Left);
istft->rescale(ifftResults_Left);
istft->performInverseTransform(temp_R, ifftResults_Right);
istft->rescale(ifftResults_Right);
// set values in output signal arrays for Harmonic output signal
for (int i = 0; i < WINDOW_SIZE; i++)
{
outputSignal_H[0].set(offset + i, (outputSignal_H[0][offset + i] + (ifftResults_Left[i] * istft->window[i])));
outputSignal_H[1].set(offset + i, (outputSignal_H[1][offset + i] + (ifftResults_Right[i] * istft->window[i])));
}
// insert 4096 samples into temp arrays from percussive spectrogram
for (int row = 0; row < WINDOW_SIZE; row++)
{
temp_L[row] = percussiveSpectrogramReal_Left(row, col);
temp_R[row] = percussiveSpectrogramReal_Right(row, col);
}
// inverse short time fourier transform on temp arrays
istft->performInverseTransform(temp_L, ifftResults_Left);
istft->rescale(ifftResults_Left);
istft->performInverseTransform(temp_R, ifftResults_Right);
istft->rescale(ifftResults_Right);
// set values in output arrays for Percussive output signal
for (int i = 0; i < WINDOW_SIZE; i++)
{
outputSignal_P[0].set(offset + i, (outputSignal_P[0][offset + i] + (ifftResults_Left[i] * istft->window[i])));
outputSignal_P[1].set(offset + i, (outputSignal_P[1][offset + i] + (ifftResults_Right[i] * istft->window[i])));
}
offset += HOP_SIZE; // increment offset by HOP_SIZE (1024)
}
//===================================================== WRITE FILES ==
float gain = 0.5f; // 1.0f divided by num of output files (2)
AudioSampleBuffer outSamples_H(2, numSamples);
AudioSampleBuffer outSamples_P(2, numSamples);
outSamples_H.clear();
outSamples_P.clear();
const float* leftData_H = outputSignal_H[0].getRawDataPointer();
const float* rightData_H = outputSignal_H[1].getRawDataPointer();
const float* leftData_P = outputSignal_P[0].getRawDataPointer();
const float* rightData_P = outputSignal_P[1].getRawDataPointer();
outSamples_H.addFrom(0, 0, leftData_H, numSamples, gain);
outSamples_H.addFrom(1, 0, rightData_H, numSamples, gain);
outSamples_P.addFrom(0, 0, leftData_P, numSamples, gain);
outSamples_P.addFrom(1, 0, rightData_P, numSamples, gain);
File* outputFile_H = new File(File::getCurrentWorkingDirectory().getChildFile(fileNameNoExt + "_harmonic.wav"));
File* outputFile_P = new File(File::getCurrentWorkingDirectory().getChildFile(fileNameNoExt + "_percussive.wav"));
if (outputFile_H->exists())
{
outputFile_H->deleteFile();
}
if (outputFile_P->exists())
{
outputFile_P->deleteFile();
}
FileOutputStream* output_H;
FileOutputStream* output_P;
output_H = outputFile_H->createOutputStream();
output_P = outputFile_P->createOutputStream();
// write from sample buffer
WavAudioFormat* wavFormat = new WavAudioFormat();
AudioFormatWriter* writer = wavFormat->createWriterFor(output_H, 44100.0, numChannels, 16, NULL, 0);
writer->flush();
writer->writeFromAudioSampleBuffer(outSamples_H, 0, numSamples);
delete writer;
writer = wavFormat->createWriterFor(output_P, 44100.0, numChannels, 16, NULL, 0);
writer->flush();
writer->writeFromAudioSampleBuffer(outSamples_P, 0, numSamples);
// cleanup
delete writer;
delete wavFormat;
wavFormat = nullptr;
writer = nullptr;
outSamples_H.clear();
outSamples_P.clear();
outputSignal_H[0].clear();
outputSignal_H[1].clear();
outputSignal_P[0].clear();
outputSignal_P[1].clear();
}
开发者ID:mangledjambon,项目名称:DrumBooth_GUI,代码行数:101,代码来源:HarmonicPercussiveSeparator.cpp
示例14: fl
//.........这里部分代码省略.........
o.resizable = false;
o.runModal();
ScopedPointer<XmlElement> audioState(deviceManager.createStateXml());
getAppProperties().getUserSettings()->setValue("audioDeviceState", audioState);
getAppProperties().getUserSettings()->saveIfNeeded();
//[/UserButtonCode_settingsButton]
}
else if (buttonThatWasClicked == playButton)
{
//[UserButtonCode_playButton] -- add your button handler code here..
const ScopedLock pal(playheadAudioLock);
playheadState = PlayheadState::playing;
playheadAudioSamplesCompleted = 0;
//[/UserButtonCode_playButton]
}
else if (buttonThatWasClicked == loopButton)
{
//[UserButtonCode_loopButton] -- add your button handler code here..
const ScopedLock pal(playheadAudioLock);
playheadState = PlayheadState::looping;
//[/UserButtonCode_loopButton]
}
else if (buttonThatWasClicked == stopButton)
{
//[UserButtonCode_stopButton] -- add your button handler code here..
const ScopedLock pal(playheadAudioLock);
playheadState = PlayheadState::stopped;
playheadAudioSamplesCompleted = 0;
//[/UserButtonCode_stopButton]
}
else if (buttonThatWasClicked == qDefaultButton)
{
//[UserButtonCode_qDefaultButton] -- add your button handler code here..
qSlider->setValue(1.0);
//[/UserButtonCode_qDefaultButton]
}
else if (buttonThatWasClicked == sDefaultButton)
{
//[UserButtonCode_sDefaultButton] -- add your button handler code here..
sSlider->setValue(1.0);
//[/UserButtonCode_sDefaultButton]
}
else if (buttonThatWasClicked == saveButton)
{
//[UserButtonCode_saveButton] -- add your button handler code here..
const ScopedLock pal(playheadAudioLock);
if (playheadAudio.getNumChannels() > 0 && playheadAudio.getNumSamples() > 0) {
FileChooser fileChooser("Save as...", File::nonexistent, "*.wav", true);
if (fileChooser.browseForFileToSave(true)) {
File outputFile = fileChooser.getResult();
outputFile.deleteFile();
WavAudioFormat wavFormat;
ScopedPointer<FileOutputStream> outputFileStream = outputFile.createOutputStream();
ScopedPointer<AudioFormatWriter> writer = wavFormat.createWriterFor(outputFileStream, 44100.0, playheadAudio.getNumChannels(), 16, StringPairArray(), 0);
writer->writeFromAudioSampleBuffer(playheadAudio, 0, playheadAudio.getNumSamples());
outputFileStream.release();
}
}
//[/UserButtonCode_saveButton]
}
else if (buttonThatWasClicked == inputRemoveButton)
{
//[UserButtonCode_inputRemoveButton] -- add your button handler code here..
const ScopedLock fl(soundListLock);
SparseSet<int> selectedRows = inputFileListComponent->getSelectedRows();
for (int i = 0; i < selectedRows.size(); ++i) {
int row = selectedRows[i];
int id = inputFileListComponent->getIdForRow(row);
const auto& iter = idToSound.find(id);
jassert(iter != idToSound.end());
idToSound.erase(iter);
}
if (selectedRows.size() > 0) {
inputFilesChanged(dontSendNotification);
}
//[/UserButtonCode_inputRemoveButton]
}
else if (buttonThatWasClicked == inputAddButton)
{
//[UserButtonCode_inputAddButton] -- add your button handler code here..
const ScopedLock fl(soundListLock);
FileChooser fileChooser("Add sound...", File::nonexistent, "*.wav;*.aif;*.aiff;*.ogg", true);
if (fileChooser.browseForMultipleFilesToOpen()) {
Array<File> files = fileChooser.getResults();
StringArray filePaths;
for (int i = 0; i < files.size(); ++i) {
filePaths.add(files[i].getFullPathName());
}
filesDropped(filePaths, -1, -1);
}
//[/UserButtonCode_inputAddButton]
}
//[UserbuttonClicked_Post]
//[/UserbuttonClicked_Post]
}
开发者ID:chrisdonahue,项目名称:ject,代码行数:101,代码来源:MainComponent.cpp
示例15: main
//.........这里部分代码省略.........
graph->addConnection(1000, 1, AUDIO_OUT_ID, 1);
plugInst->setCurrentProgram(program);
int numInputChannels = plugInst->getTotalNumInputChannels();
int numOutputChannels = plugInst->getTotalNumOutputChannels();
cout << "----- Plugin Information -----" << endl;
cout << "Input channels : " << numInputChannels << endl;
cout << "Output channels : " << numOutputChannels << endl;
cout << "Num Programs: " << plugInst->getNumPrograms() << endl;
cout << "Current program: " << plugInst->getCurrentProgram() << endl;
int numParams = plugInst->getNumParameters();
cout << "Num Parameters: " << numParams << endl;
for (int p = 0; p < numParams; ++p)
{
std::cout << "Param " << p << ": " << plugInst->getParameterName(p);
if (!plugInst->getParameterLabel(p).isEmpty()) {
cout << "(" << plugInst->getParameterLabel(p) << ")";
}
cout << " = " << plugInst->getParameter(p) << endl;
}
cout << "-----------------------------" << endl;
int maxChannels = std::max(numInputChannels, numOutputChannels);
AudioBuffer<float> entireAudioBuffer(maxChannels, totalSizeInSamples);
entireAudioBuffer.clear();
unsigned int midiSeqPos = 0;
graph->releaseResources();
graph->prepareToPlay(sampleRate, blockSize);
cout << "Num midi events: " << msgSeq->getNumEvents() << endl;
// Render the audio in blocks
for (int t = 0; t < totalSizeInSamples; t += blockSize)
{
//cout << "processing block " << t << " to " << t + blockSize << endl;
MidiBuffer midiBuffer;
for (int j = midiSeqPos; j < msgSeq->getNumEvents(); ++j)
{
MidiMessageSequence::MidiEventHolder* midiEventHolder = msgSeq->getEventPointer(j);
MidiMessage midiMsg = midiEventHolder->message;
int samplePos = static_cast<int>(midiMsg.getTimeStamp() * sampleRate);
if (samplePos >= t && samplePos < t + blockSize) {
if (midiMsg.isNoteOnOrOff()) {
if (midiMsg.isNoteOn()) {
cout << "note on event (" << midiMsg.getNoteNumber() << ") at " << samplePos << "(" << midiMsg.getTimeStamp() << "s) bufferpos=" << (samplePos - t) << endl;
}
else if (midiMsg.isNoteOff()) {
cout << "note off event (" << midiMsg.getNoteNumber() << ") at " << samplePos << "(" << midiMsg.getTimeStamp() << "s) bufferpos=" << (samplePos - t) << endl;
}
midiBuffer.addEvent(midiMsg, samplePos - t);
}
else if (midiMsg.isProgramChange()) {
program = midiMsg.getProgramChangeNumber();
plugInst->setCurrentProgram(program);
}
midiSeqPos++;
}
else {
break;
}
}
playHead.posInfo.timeInSamples = t;
playHead.posInfo.timeInSeconds = t / sampleRate;
AudioBuffer<float> blockAudioBuffer(entireAudioBuffer.getNumChannels(), blockSize);
blockAudioBuffer.clear();
graph->processBlock(blockAudioBuffer, midiBuffer);
for (int ch = 0; ch < entireAudioBuffer.getNumChannels(); ++ch) {
entireAudioBuffer.addFrom(ch, t, blockAudioBuffer, ch, 0, blockSize);
}
}
if (outWavFile.exists()) {
outWavFile.deleteFile();
}
FileOutputStream* fileOutputStream = outWavFile.createOutputStream();
WavAudioFormat wavFormat;
StringPairArray metadataValues;
juce::AudioFormatWriter* wavFormatWriter = wavFormat.createWriterFor(
fileOutputStream, sampleRate, 2, 16, metadataValues, 0);
bool writeAudioDataRet = wavFormatWriter->writeFromAudioSampleBuffer(entireAudioBuffer, 0, entireAudioBuffer.getNumSamples());
wavFormatWriter->flush();
cout << "Done writing to output file " << outWavFile.getFileName() << " . Write return value: "
<< (int)writeAudioDataRet << endl;
delete wavFormatWriter;
}
else {
cerr << "Could not find plugin from file " << plugFile << endl;
}
}
return 0;
}
开发者ID:georgekrueger,项目名称:midirender,代码行数:101,代码来源:Main.cpp
注:本文中的WavAudioFormat类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论