Skip to content

Instantly share code, notes, and snippets.

@AkiyukiOkayasu
Last active December 8, 2017 05:16
Show Gist options
  • Save AkiyukiOkayasu/1f1e7633df24d464f82a232fa80d0202 to your computer and use it in GitHub Desktop.
Save AkiyukiOkayasu/1f1e7633df24d464f82a232fa80d0202 to your computer and use it in GitHub Desktop.
JUCEでWavファイルを書き出す
void MainContentComponent::exportWav(AudioSampleBuffer &bufferToWrite, String fileName)
{
const double sampleRate = deviceManager.getCurrentAudioDevice()->getCurrentSampleRate();//現在のサンプルレートを取得
const int numChannel = bufferToWrite.getNumChannels();
const int bitDepth = 32;//32bitFloat
File file(File::getSpecialLocation(File::SpecialLocationType::userDesktopDirectory).getChildFile(fileName));
file.deleteFile();
ScopedPointer<FileOutputStream> fos(file.createOutputStream());
WavAudioFormat wavFormat;
ScopedPointer<AudioFormatWriter> writer(wavFormat.createWriterFor(fos, sampleRate, numChannel, bitDepth, StringPairArray(), 0));
fos.release();
writer->writeFromAudioSampleBuffer(bufferToWrite, 0, bufferToWrite.getNumSamples());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment