MCPcopy Create free account
hub / github.com/Tracktion/choc / main

Function main

examples/audio_sine_wave.cpp:8–30  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6#include "../choc/text/choc_Files.h"
7
8int main()
9{
10 const double sampleRate = 44100.0;
11 const double frequency = 440.0;
12 const double duration = 2.0;
13 const int numChannels = 1;
14 const int numFrames = static_cast<int>(sampleRate * duration);
15
16 auto buffer = choc::buffer::createChannelArrayBuffer<float> (numChannels, numFrames, [&] (choc::buffer::ChannelCount, choc::buffer::FrameCount frame) -> float
17 {
18 return static_cast<float> (std::sin (2.0 * M_PI * frequency * static_cast<double> (frame) / sampleRate));
19 });
20
21 choc::audio::WAVAudioFileFormat writer;
22 auto wavData = writer.createData (buffer.getView(), 16);
23
24 if (choc::file::writeToFile ("sine_wave.wav", wavData.data(), wavData.size()))
25 std::cout << "Successfully wrote sine_wave.wav" << std::endl;
26 else
27 std::cout << "Failed to write sine_wave.wav" << std::endl;
28
29 return 0;
30}

Callers

nothing calls this directly

Calls 3

getViewMethod · 0.80
dataMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected