From a0fcab8310205759d5803c8d4f4bc0665636bc02 Mon Sep 17 00:00:00 2001 From: Nikolai Rodionov Date: Sat, 3 Jan 2026 14:11:44 +0100 Subject: [PATCH] Nothing has happend Signed-off-by: Nikolai Rodionov --- conanfile.py | 1 + coreaudio.cpp | 113 +++++++++++++++++++++++++++++++++++++++++++ src/gui/editor.cpp | 7 +++ src/main.cpp | 118 ++++++--------------------------------------- 4 files changed, 135 insertions(+), 104 deletions(-) create mode 100644 coreaudio.cpp create mode 100644 src/gui/editor.cpp diff --git a/conanfile.py b/conanfile.py index 0eca1ec..a4aa33b 100644 --- a/conanfile.py +++ b/conanfile.py @@ -20,6 +20,7 @@ class daw_projectConan(ConanFile): self.requires("conan-test-lib/0.0.2") self.requires("qt/6.10.1") self.requires("libsndfile/1.2.2") + self.requires("gtest/1.17.0") def layout(self): self.folders.build = "build" diff --git a/coreaudio.cpp b/coreaudio.cpp new file mode 100644 index 0000000..bba0f80 --- /dev/null +++ b/coreaudio.cpp @@ -0,0 +1,113 @@ + + + +#include +#include +#include +#include +#include + +constexpr double SAMPLE_RATE = 44100.0; +constexpr double FREQUENCY = 440.0; // A4 +constexpr double AMPLITUDE = 0.25; + +struct SineState { + double phase = 0.0; +}; + +OSStatus renderCallback( + void* inRefCon, + AudioUnitRenderActionFlags* ioActionFlags, + const AudioTimeStamp* inTimeStamp, + UInt32 inBusNumber, + UInt32 inNumberFrames, + AudioBufferList* ioData) +{ + auto* state = static_cast(inRefCon); + double phase = state->phase; + double phaseIncrement = 2.0 * M_PI * FREQUENCY / SAMPLE_RATE; + + for (UInt32 frame = 0; frame < inNumberFrames; ++frame) { + float sample = static_cast(std::sin(phase) * AMPLITUDE); + phase += phaseIncrement; + if (phase >= 2.0 * M_PI) + phase -= 2.0 * M_PI; + + // Write same sample to all channels + for (UInt32 buffer = 0; buffer < ioData->mNumberBuffers; ++buffer) { + float* data = static_cast(ioData->mBuffers[buffer].mData); + data[frame] = sample; + } + } + + state->phase = phase; + return noErr; +} + +int main() { + AudioUnit audioUnit; + SineState state; + + // Describe output unit + AudioComponentDescription desc{}; + desc.componentType = kAudioUnitType_Output; + desc.componentSubType = kAudioUnitSubType_DefaultOutput; + desc.componentManufacturer = kAudioUnitManufacturer_Apple; + + AudioComponent comp = AudioComponentFindNext(nullptr, &desc); + if (!comp) { + std::cerr << "Failed to find audio component\n"; + return 1; + } + + AudioComponentInstanceNew(comp, &audioUnit); + + // Set stream format + AudioStreamBasicDescription format{}; + format.mSampleRate = SAMPLE_RATE; + format.mFormatID = kAudioFormatLinearPCM; + format.mFormatFlags = kAudioFormatFlagIsFloat | kAudioFormatFlagIsPacked; + format.mBitsPerChannel = 32; + format.mChannelsPerFrame = 2; + format.mBytesPerFrame = sizeof(float) * format.mChannelsPerFrame; + format.mFramesPerPacket = 1; + format.mBytesPerPacket = format.mBytesPerFrame; + + AudioUnitSetProperty( + audioUnit, + kAudioUnitProperty_StreamFormat, + kAudioUnitScope_Input, + 0, + &format, + sizeof(format) + ); + + // Set render callback + AURenderCallbackStruct callback{}; + callback.inputProc = renderCallback; + callback.inputProcRefCon = &state; + + AudioUnitSetProperty( + audioUnit, + kAudioUnitProperty_SetRenderCallback, + kAudioUnitScope_Input, + 0, + &callback, + sizeof(callback) + ); + + AudioUnitInitialize(audioUnit); + AudioOutputUnitStart(audioUnit); + + std::cout << "Playing sine wave (Ctrl+C to quit)...\n"; + while (true) { + sleep(1); + } + + AudioOutputUnitStop(audioUnit); + AudioUnitUninitialize(audioUnit); + AudioComponentInstanceDispose(audioUnit); + + return 0; +} + diff --git a/src/gui/editor.cpp b/src/gui/editor.cpp new file mode 100644 index 0000000..4304e30 --- /dev/null +++ b/src/gui/editor.cpp @@ -0,0 +1,7 @@ +#include + +QPushButton renderButton() +{ + QPushButton button ("Hello world !"); + return button; +} diff --git a/src/main.cpp b/src/main.cpp index c42d329..84c8e21 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,110 +1,20 @@ -#include -#include -#include -#include -#include +#include +#include +#include -constexpr double SAMPLE_RATE = 44100.0; -constexpr double FREQUENCY = 440.0; // A4 -constexpr double AMPLITUDE = 0.25; - -struct SineState { - double phase = 0.0; -}; - -OSStatus renderCallback( - void* inRefCon, - AudioUnitRenderActionFlags* ioActionFlags, - const AudioTimeStamp* inTimeStamp, - UInt32 inBusNumber, - UInt32 inNumberFrames, - AudioBufferList* ioData) -{ - auto* state = static_cast(inRefCon); - double phase = state->phase; - double phaseIncrement = 2.0 * M_PI * FREQUENCY / SAMPLE_RATE; - - for (UInt32 frame = 0; frame < inNumberFrames; ++frame) { - float sample = static_cast(std::sin(phase) * AMPLITUDE); - phase += phaseIncrement; - if (phase >= 2.0 * M_PI) - phase -= 2.0 * M_PI; - - // Write same sample to all channels - for (UInt32 buffer = 0; buffer < ioData->mNumberBuffers; ++buffer) { - float* data = static_cast(ioData->mBuffers[buffer].mData); - data[frame] = sample; - } - } - - state->phase = phase; - return noErr; +void renderButton(QWidget *parent) { + QPushButton *button = new QPushButton("Hello world!", parent); + button->show(); } -int main() { - AudioUnit audioUnit; - SineState state; +int main(int argc, char **argv) { + QApplication app (argc, argv); + + QWidget window; + window.resize(300, 200); + window.show(); - // Describe output unit - AudioComponentDescription desc{}; - desc.componentType = kAudioUnitType_Output; - desc.componentSubType = kAudioUnitSubType_DefaultOutput; - desc.componentManufacturer = kAudioUnitManufacturer_Apple; - - AudioComponent comp = AudioComponentFindNext(nullptr, &desc); - if (!comp) { - std::cerr << "Failed to find audio component\n"; - return 1; - } - - AudioComponentInstanceNew(comp, &audioUnit); - - // Set stream format - AudioStreamBasicDescription format{}; - format.mSampleRate = SAMPLE_RATE; - format.mFormatID = kAudioFormatLinearPCM; - format.mFormatFlags = kAudioFormatFlagIsFloat | kAudioFormatFlagIsPacked; - format.mBitsPerChannel = 32; - format.mChannelsPerFrame = 2; - format.mBytesPerFrame = sizeof(float) * format.mChannelsPerFrame; - format.mFramesPerPacket = 1; - format.mBytesPerPacket = format.mBytesPerFrame; - - AudioUnitSetProperty( - audioUnit, - kAudioUnitProperty_StreamFormat, - kAudioUnitScope_Input, - 0, - &format, - sizeof(format) - ); - - // Set render callback - AURenderCallbackStruct callback{}; - callback.inputProc = renderCallback; - callback.inputProcRefCon = &state; - - AudioUnitSetProperty( - audioUnit, - kAudioUnitProperty_SetRenderCallback, - kAudioUnitScope_Input, - 0, - &callback, - sizeof(callback) - ); - - AudioUnitInitialize(audioUnit); - AudioOutputUnitStart(audioUnit); - - std::cout << "Playing sine wave (Ctrl+C to quit)...\n"; - while (true) { - sleep(1); - } - - AudioOutputUnitStop(audioUnit); - AudioUnitUninitialize(audioUnit); - AudioComponentInstanceDispose(audioUnit); - - return 0; + renderButton(&window); + return app.exec(); }