mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-10 23:44:24 +00:00
AudioRecordingDemo: Use the new AudioFormat::createWriterFor overload
This commit is contained in:
parent
9feee44070
commit
eb7de7f15b
1 changed files with 9 additions and 5 deletions
|
|
@ -83,21 +83,25 @@ public:
|
||||||
// Create an OutputStream to write to our destination file...
|
// Create an OutputStream to write to our destination file...
|
||||||
file.deleteFile();
|
file.deleteFile();
|
||||||
|
|
||||||
if (auto fileStream = std::unique_ptr<FileOutputStream> (file.createOutputStream()))
|
if (std::unique_ptr<OutputStream> fileStream { file.createOutputStream() })
|
||||||
{
|
{
|
||||||
// Now create a WAV writer object that writes to our output stream...
|
// Now create a WAV writer object that writes to our output stream...
|
||||||
WavAudioFormat wavFormat;
|
WavAudioFormat wavFormat;
|
||||||
|
|
||||||
if (auto writer = wavFormat.createWriterFor (fileStream.get(), sampleRate, 1, 16, {}, 0))
|
using Opts = AudioFormatWriterOptions;
|
||||||
|
|
||||||
|
if (auto writer = wavFormat.createWriterFor (fileStream, Opts{}.withSampleRate (sampleRate)
|
||||||
|
.withNumChannels (1)
|
||||||
|
.withBitsPerSample (16)))
|
||||||
{
|
{
|
||||||
fileStream.release(); // (passes responsibility for deleting the stream to the writer object that is now using it)
|
auto* writerPtr = writer.get();
|
||||||
|
|
||||||
// Now we'll create one of these helper objects which will act as a FIFO buffer, and will
|
// 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.
|
// write the data to disk on our background thread.
|
||||||
threadedWriter.reset (new AudioFormatWriter::ThreadedWriter (writer, backgroundThread, 32768));
|
threadedWriter.reset (new AudioFormatWriter::ThreadedWriter (writer.release(), backgroundThread, 32768));
|
||||||
|
|
||||||
// Reset our recording thumbnail
|
// Reset our recording thumbnail
|
||||||
thumbnail.reset (writer->getNumChannels(), writer->getSampleRate());
|
thumbnail.reset (writerPtr->getNumChannels(), writerPtr->getSampleRate());
|
||||||
nextSampleNum = 0;
|
nextSampleNum = 0;
|
||||||
|
|
||||||
// And now, swap over our active writer pointer so that the audio callback will start using it..
|
// And now, swap over our active writer pointer so that the audio callback will start using it..
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue