Skip to content

Commit

Permalink
[standalone] Improvements, support for audio
Browse files Browse the repository at this point in the history
  • Loading branch information
jcelerier committed Sep 27, 2023
1 parent 3588527 commit 1d62074
Show file tree
Hide file tree
Showing 13 changed files with 368 additions and 165 deletions.
119 changes: 118 additions & 1 deletion cmake/avendish.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,114 @@ find_package(Boost QUIET REQUIRED)
find_package(Threads QUIET)
find_package(fmt QUIET)


set(AVENDISH_SOURCES
"${AVND_SOURCE_DIR}/include/avnd/concepts/all.hpp"
"${AVND_SOURCE_DIR}/include/avnd/concepts/attributes.hpp"
"${AVND_SOURCE_DIR}/include/avnd/concepts/audio_port.hpp"
"${AVND_SOURCE_DIR}/include/avnd/concepts/audio_processor.hpp"
"${AVND_SOURCE_DIR}/include/avnd/concepts/callback.hpp"
"${AVND_SOURCE_DIR}/include/avnd/concepts/channels.hpp"
"${AVND_SOURCE_DIR}/include/avnd/concepts/fft.hpp"
"${AVND_SOURCE_DIR}/include/avnd/concepts/generic.hpp"
"${AVND_SOURCE_DIR}/include/avnd/concepts/gfx.hpp"
"${AVND_SOURCE_DIR}/include/avnd/concepts/layout.hpp"
"${AVND_SOURCE_DIR}/include/avnd/concepts/message.hpp"
"${AVND_SOURCE_DIR}/include/avnd/concepts/midi.hpp"
"${AVND_SOURCE_DIR}/include/avnd/concepts/midi_port.hpp"
"${AVND_SOURCE_DIR}/include/avnd/concepts/modules.hpp"
"${AVND_SOURCE_DIR}/include/avnd/concepts/object.hpp"
"${AVND_SOURCE_DIR}/include/avnd/concepts/painter.hpp"
"${AVND_SOURCE_DIR}/include/avnd/concepts/parameter.hpp"
"${AVND_SOURCE_DIR}/include/avnd/concepts/port.hpp"
"${AVND_SOURCE_DIR}/include/avnd/concepts/processor.hpp"
"${AVND_SOURCE_DIR}/include/avnd/concepts/schedule.hpp"
"${AVND_SOURCE_DIR}/include/avnd/concepts/soundfile.hpp"
"${AVND_SOURCE_DIR}/include/avnd/concepts/synth.hpp"

"${AVND_SOURCE_DIR}/include/avnd/introspection/channels.hpp"
"${AVND_SOURCE_DIR}/include/avnd/introspection/input.hpp"
"${AVND_SOURCE_DIR}/include/avnd/introspection/messages.hpp"
"${AVND_SOURCE_DIR}/include/avnd/introspection/midi.hpp"
"${AVND_SOURCE_DIR}/include/avnd/introspection/modules.hpp"
"${AVND_SOURCE_DIR}/include/avnd/introspection/output.hpp"
"${AVND_SOURCE_DIR}/include/avnd/introspection/port.hpp"
"${AVND_SOURCE_DIR}/include/avnd/introspection/widgets.hpp"

"${AVND_SOURCE_DIR}/include/avnd/wrappers/audio_channel_manager.hpp"
"${AVND_SOURCE_DIR}/include/avnd/wrappers/avnd.hpp"
"${AVND_SOURCE_DIR}/include/avnd/wrappers/bus_host_process_adapter.hpp"
"${AVND_SOURCE_DIR}/include/avnd/wrappers/configure.hpp"
"${AVND_SOURCE_DIR}/include/avnd/wrappers/control_display.hpp"
"${AVND_SOURCE_DIR}/include/avnd/wrappers/controls.hpp"
"${AVND_SOURCE_DIR}/include/avnd/wrappers/controls_double.hpp"
"${AVND_SOURCE_DIR}/include/avnd/wrappers/controls_fp.hpp"
"${AVND_SOURCE_DIR}/include/avnd/wrappers/controls_storage.hpp"
"${AVND_SOURCE_DIR}/include/avnd/wrappers/effect_container.hpp"
"${AVND_SOURCE_DIR}/include/avnd/wrappers/metadatas.hpp"
"${AVND_SOURCE_DIR}/include/avnd/wrappers/prepare.hpp"
"${AVND_SOURCE_DIR}/include/avnd/wrappers/process_adapter.hpp"
"${AVND_SOURCE_DIR}/include/avnd/wrappers/process_execution.hpp"
"${AVND_SOURCE_DIR}/include/avnd/wrappers/widgets.hpp"

"${AVND_SOURCE_DIR}/include/avnd/common/aggregates.hpp"
"${AVND_SOURCE_DIR}/include/avnd/common/concepts_polyfill.hpp"
"${AVND_SOURCE_DIR}/include/avnd/common/coroutines.hpp"
"${AVND_SOURCE_DIR}/include/avnd/common/dummy.hpp"
"${AVND_SOURCE_DIR}/include/avnd/common/errors.hpp"
"${AVND_SOURCE_DIR}/include/avnd/common/export.hpp"
"${AVND_SOURCE_DIR}/include/avnd/common/for_nth.hpp"
"${AVND_SOURCE_DIR}/include/avnd/common/function_reflection.hpp"
"${AVND_SOURCE_DIR}/include/avnd/common/index_sequence.hpp"
"${AVND_SOURCE_DIR}/include/avnd/common/limited_string.hpp"
"${AVND_SOURCE_DIR}/include/avnd/common/limited_string_view.hpp"
"${AVND_SOURCE_DIR}/include/avnd/common/span_polyfill.hpp"
"${AVND_SOURCE_DIR}/include/avnd/common/struct_reflection.hpp"
"${AVND_SOURCE_DIR}/include/avnd/common/widechar.hpp"

"${AVND_SOURCE_DIR}/include/halp/attributes.hpp"
"${AVND_SOURCE_DIR}/include/halp/audio.hpp"
"${AVND_SOURCE_DIR}/include/halp/callback.hpp"
"${AVND_SOURCE_DIR}/include/halp/compat/gamma.hpp"
"${AVND_SOURCE_DIR}/include/halp/controls.basic.hpp"
"${AVND_SOURCE_DIR}/include/halp/controls.buttons.hpp"
"${AVND_SOURCE_DIR}/include/halp/controls.enums.hpp"
"${AVND_SOURCE_DIR}/include/halp/controls.hpp"
"${AVND_SOURCE_DIR}/include/halp/controls.sliders.gcc10.hpp"
"${AVND_SOURCE_DIR}/include/halp/controls.sliders.hpp"
"${AVND_SOURCE_DIR}/include/halp/controls.typedefs.hpp"
"${AVND_SOURCE_DIR}/include/halp/controls_fmt.hpp"
"${AVND_SOURCE_DIR}/include/halp/curve.hpp"
"${AVND_SOURCE_DIR}/include/halp/custom_widgets.hpp"
"${AVND_SOURCE_DIR}/include/halp/fft.hpp"
"${AVND_SOURCE_DIR}/include/halp/file_port.hpp"
"${AVND_SOURCE_DIR}/include/halp/geometry.hpp"
"${AVND_SOURCE_DIR}/include/halp/gradient_port.hpp"
"${AVND_SOURCE_DIR}/include/halp/inline.hpp"
"${AVND_SOURCE_DIR}/include/halp/layout.hpp"
"${AVND_SOURCE_DIR}/include/halp/log.hpp"
"${AVND_SOURCE_DIR}/include/halp/mappers.hpp"
"${AVND_SOURCE_DIR}/include/halp/messages.hpp"
"${AVND_SOURCE_DIR}/include/halp/meta.hpp"
"${AVND_SOURCE_DIR}/include/halp/midi.hpp"
"${AVND_SOURCE_DIR}/include/halp/midifile_port.hpp"
"${AVND_SOURCE_DIR}/include/halp/polyfill.hpp"
"${AVND_SOURCE_DIR}/include/halp/reactive_value.hpp"
"${AVND_SOURCE_DIR}/include/halp/sample_accurate_controls.hpp"
"${AVND_SOURCE_DIR}/include/halp/schedule.hpp"
"${AVND_SOURCE_DIR}/include/halp/smoothers.hpp"
"${AVND_SOURCE_DIR}/include/halp/soundfile_port.hpp"
"${AVND_SOURCE_DIR}/include/halp/static_string.hpp"
"${AVND_SOURCE_DIR}/include/halp/texture.hpp"
"${AVND_SOURCE_DIR}/include/halp/texture_formats.hpp"
"${AVND_SOURCE_DIR}/include/halp/value_types.hpp"

"${AVND_SOURCE_DIR}/include/gpp/commands.hpp"
"${AVND_SOURCE_DIR}/include/gpp/generators.hpp"
"${AVND_SOURCE_DIR}/include/gpp/meta.hpp"
"${AVND_SOURCE_DIR}/include/gpp/layout.hpp"
)

include(avendish.disableexceptions)
include(avendish.sources)

Expand All @@ -26,8 +134,17 @@ include(avendish.example)

# Used for getting completion in IDEs...
function(avnd_register)
cmake_parse_arguments(AVND "" "TARGET;MAIN_FILE;MAIN_CLASS;C_NAME" "" ${ARGN})
cmake_parse_arguments(AVND "" "TARGET;MAIN_FILE;MAIN_CLASS;C_NAME;COMPILE_OPTIONS;COMPILE_DEFINITIONS;LINK_LIBRARIES" "" ${ARGN})
target_sources(Avendish PRIVATE "${AVND_MAIN_FILE}")
if(AVND_COMPILE_OPTIONS)
target_compile_options(Avendish PRIVATE "${AVND_COMPILE_OPTIONS}")
endif()
if(AVND_COMPILE_DEFINITIONS)
target_compile_definitions(Avendish PRIVATE "${AVND_COMPILE_DEFINITIONS}")
endif()
if(AVND_LINK_LIBRARIES)
target_link_libraries(Avendish PRIVATE "${AVND_LINK_LIBRARIES}")
endif()
endfunction()

# Bindings to programming languages, things with a proper object model
Expand Down
7 changes: 7 additions & 0 deletions cmake/avendish.examples.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,13 @@ avnd_make_object(
C_NAME avnd_init
)

avnd_make_all(
TARGET Sines
MAIN_FILE examples/Raw/Sines.hpp
MAIN_CLASS examples::Sine
C_NAME avnd_sines
)

avnd_make_object(
TARGET Callback
MAIN_FILE examples/Raw/Callback.hpp
Expand Down
3 changes: 2 additions & 1 deletion cmake/avendish.ossia.cmake
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
find_package(ossia QUIET)
find_package(SDL2 QUIET)

if(NOT TARGET ossia::ossia)
if(1)
#if(NOT TARGET ossia::ossia)
message(STATUS "libossia not found, skipping bindings...")

function(avnd_make_ossia)
Expand Down
106 changes: 1 addition & 105 deletions cmake/avendish.sources.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -18,111 +18,7 @@ endif()

target_sources(Avendish
PUBLIC
"${AVND_SOURCE_DIR}/include/avnd/concepts/all.hpp"
"${AVND_SOURCE_DIR}/include/avnd/concepts/attributes.hpp"
"${AVND_SOURCE_DIR}/include/avnd/concepts/audio_port.hpp"
"${AVND_SOURCE_DIR}/include/avnd/concepts/audio_processor.hpp"
"${AVND_SOURCE_DIR}/include/avnd/concepts/callback.hpp"
"${AVND_SOURCE_DIR}/include/avnd/concepts/channels.hpp"
"${AVND_SOURCE_DIR}/include/avnd/concepts/fft.hpp"
"${AVND_SOURCE_DIR}/include/avnd/concepts/generic.hpp"
"${AVND_SOURCE_DIR}/include/avnd/concepts/gfx.hpp"
"${AVND_SOURCE_DIR}/include/avnd/concepts/layout.hpp"
"${AVND_SOURCE_DIR}/include/avnd/concepts/message.hpp"
"${AVND_SOURCE_DIR}/include/avnd/concepts/midi.hpp"
"${AVND_SOURCE_DIR}/include/avnd/concepts/midi_port.hpp"
"${AVND_SOURCE_DIR}/include/avnd/concepts/modules.hpp"
"${AVND_SOURCE_DIR}/include/avnd/concepts/object.hpp"
"${AVND_SOURCE_DIR}/include/avnd/concepts/painter.hpp"
"${AVND_SOURCE_DIR}/include/avnd/concepts/parameter.hpp"
"${AVND_SOURCE_DIR}/include/avnd/concepts/port.hpp"
"${AVND_SOURCE_DIR}/include/avnd/concepts/processor.hpp"
"${AVND_SOURCE_DIR}/include/avnd/concepts/schedule.hpp"
"${AVND_SOURCE_DIR}/include/avnd/concepts/soundfile.hpp"
"${AVND_SOURCE_DIR}/include/avnd/concepts/synth.hpp"

"${AVND_SOURCE_DIR}/include/avnd/introspection/channels.hpp"
"${AVND_SOURCE_DIR}/include/avnd/introspection/input.hpp"
"${AVND_SOURCE_DIR}/include/avnd/introspection/messages.hpp"
"${AVND_SOURCE_DIR}/include/avnd/introspection/midi.hpp"
"${AVND_SOURCE_DIR}/include/avnd/introspection/modules.hpp"
"${AVND_SOURCE_DIR}/include/avnd/introspection/output.hpp"
"${AVND_SOURCE_DIR}/include/avnd/introspection/port.hpp"
"${AVND_SOURCE_DIR}/include/avnd/introspection/widgets.hpp"

"${AVND_SOURCE_DIR}/include/avnd/wrappers/audio_channel_manager.hpp"
"${AVND_SOURCE_DIR}/include/avnd/wrappers/avnd.hpp"
"${AVND_SOURCE_DIR}/include/avnd/wrappers/bus_host_process_adapter.hpp"
"${AVND_SOURCE_DIR}/include/avnd/wrappers/configure.hpp"
"${AVND_SOURCE_DIR}/include/avnd/wrappers/control_display.hpp"
"${AVND_SOURCE_DIR}/include/avnd/wrappers/controls.hpp"
"${AVND_SOURCE_DIR}/include/avnd/wrappers/controls_double.hpp"
"${AVND_SOURCE_DIR}/include/avnd/wrappers/controls_fp.hpp"
"${AVND_SOURCE_DIR}/include/avnd/wrappers/controls_storage.hpp"
"${AVND_SOURCE_DIR}/include/avnd/wrappers/effect_container.hpp"
"${AVND_SOURCE_DIR}/include/avnd/wrappers/metadatas.hpp"
"${AVND_SOURCE_DIR}/include/avnd/wrappers/prepare.hpp"
"${AVND_SOURCE_DIR}/include/avnd/wrappers/process_adapter.hpp"
"${AVND_SOURCE_DIR}/include/avnd/wrappers/process_execution.hpp"
"${AVND_SOURCE_DIR}/include/avnd/wrappers/widgets.hpp"

"${AVND_SOURCE_DIR}/include/avnd/common/aggregates.hpp"
"${AVND_SOURCE_DIR}/include/avnd/common/concepts_polyfill.hpp"
"${AVND_SOURCE_DIR}/include/avnd/common/coroutines.hpp"
"${AVND_SOURCE_DIR}/include/avnd/common/dummy.hpp"
"${AVND_SOURCE_DIR}/include/avnd/common/errors.hpp"
"${AVND_SOURCE_DIR}/include/avnd/common/export.hpp"
"${AVND_SOURCE_DIR}/include/avnd/common/for_nth.hpp"
"${AVND_SOURCE_DIR}/include/avnd/common/function_reflection.hpp"
"${AVND_SOURCE_DIR}/include/avnd/common/index_sequence.hpp"
"${AVND_SOURCE_DIR}/include/avnd/common/limited_string.hpp"
"${AVND_SOURCE_DIR}/include/avnd/common/limited_string_view.hpp"
"${AVND_SOURCE_DIR}/include/avnd/common/span_polyfill.hpp"
"${AVND_SOURCE_DIR}/include/avnd/common/struct_reflection.hpp"
"${AVND_SOURCE_DIR}/include/avnd/common/widechar.hpp"

"${AVND_SOURCE_DIR}/include/halp/attributes.hpp"
"${AVND_SOURCE_DIR}/include/halp/audio.hpp"
"${AVND_SOURCE_DIR}/include/halp/callback.hpp"
"${AVND_SOURCE_DIR}/include/halp/compat/gamma.hpp"
"${AVND_SOURCE_DIR}/include/halp/controls.basic.hpp"
"${AVND_SOURCE_DIR}/include/halp/controls.buttons.hpp"
"${AVND_SOURCE_DIR}/include/halp/controls.enums.hpp"
"${AVND_SOURCE_DIR}/include/halp/controls.hpp"
"${AVND_SOURCE_DIR}/include/halp/controls.sliders.gcc10.hpp"
"${AVND_SOURCE_DIR}/include/halp/controls.sliders.hpp"
"${AVND_SOURCE_DIR}/include/halp/controls.typedefs.hpp"
"${AVND_SOURCE_DIR}/include/halp/controls_fmt.hpp"
"${AVND_SOURCE_DIR}/include/halp/curve.hpp"
"${AVND_SOURCE_DIR}/include/halp/custom_widgets.hpp"
"${AVND_SOURCE_DIR}/include/halp/fft.hpp"
"${AVND_SOURCE_DIR}/include/halp/file_port.hpp"
"${AVND_SOURCE_DIR}/include/halp/geometry.hpp"
"${AVND_SOURCE_DIR}/include/halp/gradient_port.hpp"
"${AVND_SOURCE_DIR}/include/halp/inline.hpp"
"${AVND_SOURCE_DIR}/include/halp/layout.hpp"
"${AVND_SOURCE_DIR}/include/halp/log.hpp"
"${AVND_SOURCE_DIR}/include/halp/mappers.hpp"
"${AVND_SOURCE_DIR}/include/halp/messages.hpp"
"${AVND_SOURCE_DIR}/include/halp/meta.hpp"
"${AVND_SOURCE_DIR}/include/halp/midi.hpp"
"${AVND_SOURCE_DIR}/include/halp/midifile_port.hpp"
"${AVND_SOURCE_DIR}/include/halp/polyfill.hpp"
"${AVND_SOURCE_DIR}/include/halp/reactive_value.hpp"
"${AVND_SOURCE_DIR}/include/halp/sample_accurate_controls.hpp"
"${AVND_SOURCE_DIR}/include/halp/schedule.hpp"
"${AVND_SOURCE_DIR}/include/halp/smoothers.hpp"
"${AVND_SOURCE_DIR}/include/halp/soundfile_port.hpp"
"${AVND_SOURCE_DIR}/include/halp/static_string.hpp"
"${AVND_SOURCE_DIR}/include/halp/texture.hpp"
"${AVND_SOURCE_DIR}/include/halp/texture_formats.hpp"
"${AVND_SOURCE_DIR}/include/halp/value_types.hpp"

"${AVND_SOURCE_DIR}/include/gpp/commands.hpp"
"${AVND_SOURCE_DIR}/include/gpp/generators.hpp"
"${AVND_SOURCE_DIR}/include/gpp/meta.hpp"
"${AVND_SOURCE_DIR}/include/gpp/layout.hpp"

${AVENDISH_SOURCES}
"${AVND_SOURCE_DIR}/src/dummy.cpp"
)

Expand Down
5 changes: 3 additions & 2 deletions cmake/avendish.standalone.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ function(avnd_make_standalone)

avnd_common_setup("${AVND_TARGET}" "${AVND_FX_TARGET}")

target_sources(Avendish PRIVATE
target_sources("${AVND_FX_TARGET}" PRIVATE
"${AVND_SOURCE_DIR}/include/avnd/binding/standalone/audio.hpp"
"${AVND_SOURCE_DIR}/include/avnd/binding/standalone/configure.hpp"
"${AVND_SOURCE_DIR}/include/avnd/binding/standalone/standalone.hpp"
Expand Down Expand Up @@ -139,6 +139,7 @@ function(avnd_make_standalone)
target_sources(
${AVND_FX_TARGET}
PRIVATE
${AVENDISH_SOURCES}
"${CMAKE_BINARY_DIR}/${MAIN_OUT_FILE}_standalone.cpp"
)

Expand Down Expand Up @@ -167,7 +168,7 @@ function(avnd_make_standalone)

avnd_common_setup("${AVND_TARGET}" "${AVND_FX_TARGET}")

target_sources(Avendish PRIVATE
target_sources(${AVND_FX_TARGET} PRIVATE
"${AVND_SOURCE_DIR}/include/avnd/binding/standalone/audio.hpp"
"${AVND_SOURCE_DIR}/include/avnd/binding/standalone/configure.hpp"
"${AVND_SOURCE_DIR}/include/avnd/binding/standalone/standalone.hpp"
Expand Down
9 changes: 5 additions & 4 deletions examples/Raw/Sines.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include <cmath>

#include <numbers>
#include <ratio>
#include <vector>

Expand Down Expand Up @@ -96,10 +97,10 @@ struct Sine
void operator()(const inputs& inputs, outputs& outputs)
{
const double phi[4] = {
2 * 3.14 * inputs.f1.value / setup.rate,
2 * 3.14 * inputs.f2.value / setup.rate,
2 * 3.14 * inputs.f3.value / setup.rate,
2 * 3.14 * inputs.f4.value / setup.rate,
2. * std::numbers::pi * inputs.f1.value / setup.rate,
2. * std::numbers::pi * inputs.f2.value / setup.rate,
2. * std::numbers::pi * inputs.f3.value / setup.rate,
2. * std::numbers::pi * inputs.f4.value / setup.rate,
};
outputs.audio.sample = 0.;
for(int i = 0; i < 4; i++)
Expand Down
74 changes: 74 additions & 0 deletions include/avnd/binding/standalone/audio.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#pragma once

/* SPDX-License-Identifier: GPL-3.0-or-later */

#include <avnd/concepts/all.hpp>
#include <avnd/introspection/input.hpp>
#include <avnd/introspection/messages.hpp>
#include <avnd/introspection/output.hpp>
#include <avnd/wrappers/effect_container.hpp>
#include <avnd/wrappers/metadatas.hpp>
#include <avnd/wrappers/process_adapter.hpp>
#include <ossia/audio/audio_device.hpp>
#include <ossia/audio/audio_engine.hpp>

namespace standalone
{

struct audio_tick
{
int frames;
};

template <typename T>
struct audio_mapper
{
avnd::effect_container<T>& object;
ossia::audio_engine* audio{};

[[no_unique_address]] avnd::process_adapter<T> processor;

explicit audio_mapper(
avnd::effect_container<T>& object, int in_channels, int out_channels, int bs,
int rate)
: object{object}
{
int want_ins = avnd::input_channels<T>(in_channels);
int want_outs = avnd::output_channels<T>(out_channels);

int want_buffer_size = bs;
int want_sample_rate = rate;
audio = ossia::make_audio_engine(
"", std::string(avnd::get_name<T>()), "", "", want_ins, want_outs,
want_sample_rate, want_buffer_size);

// Allocate buffers that may be required for converting float <-> double
avnd::process_setup setup_info{
.input_channels = want_ins,
.output_channels = want_outs,
.frames_per_buffer = want_buffer_size,
.rate = (double)want_sample_rate};

processor.allocate_buffers(setup_info, float{});
processor.allocate_buffers(setup_info, double{});

avnd::prepare(object, setup_info);
audio->set_tick([this](auto& st) { (*this)(st); });
}

void operator()(const ossia::audio_tick_state& st)
{
audio_tick tick = {.frames = (int)st.frames};
int n = avnd::get_frames(tick);
auto ins = avnd::span<float*>{const_cast<float**>(st.inputs), (std::size_t)st.n_in};
auto outs = avnd::span<float*>{st.outputs, (std::size_t)st.n_out};
this->processor.process(object, ins, outs, tick);
}

~audio_mapper()
{
audio->stop();
delete audio;
}
};
}
Loading

0 comments on commit 1d62074

Please sign in to comment.