Skip to content

Commit

Permalink
[audio] Add two simple utility objects
Browse files Browse the repository at this point in the history
  • Loading branch information
jcelerier committed May 11, 2024
1 parent 6ac4c13 commit a0b3e28
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 0 deletions.
46 changes: 46 additions & 0 deletions examples/Advanced/Utilities/AudioSum.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#pragma once

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

#include <halp/audio.hpp>
#include <halp/controls.hpp>
#include <halp/meta.hpp>
#include <halp/soundfile_port.hpp>

namespace ao
{
class AudioSum
{
public:
halp_meta(name, "Audio Sum")
halp_meta(c_name, "audio_sum")
halp_meta(category, "Audio")
halp_meta(author, "Jean-Michaël Celerier")
halp_meta(description, "Sum all the input channels")
halp_meta(uuid, "8938ca07-ce26-4d0a-b7f9-bff465a28a97")

struct
{
halp::dynamic_audio_bus<"Input", double> audio;
} inputs;

struct
{
halp::fixed_audio_bus<"Output", double, 1> audio;
} outputs;

void operator()(int frames)
{
auto out = outputs.audio.channel(0, frames);
for(int j = 0; j < frames; j++)
out[j] = 0.;

for(int i = 0; i < inputs.audio.channels; i++)
{
const auto in = inputs.audio.channel(i, frames);
for(int j = 0; j < frames; j++)
out[j] += in[j];
}
}
};
}
44 changes: 44 additions & 0 deletions examples/Advanced/Utilities/Silence.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#pragma once

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

#include <halp/audio.hpp>
#include <halp/controls.hpp>
#include <halp/meta.hpp>
#include <halp/soundfile_port.hpp>

namespace ao
{
class Silence
{
public:
halp_meta(name, "Silence")
halp_meta(c_name, "silence")
halp_meta(category, "Audio")
halp_meta(author, "Jean-Michaël Celerier")
halp_meta(description, "Enjoy the silence")
halp_meta(uuid, "3bf48e32-06c0-4693-8a80-062ae9b5eac8")

struct
{
halp::spinbox_i32<"Channels"> channels;
} inputs;

struct
{
halp::variable_audio_bus<"Output", double> audio;
} outputs;

using setup = halp::setup;
void prepare(halp::setup s) { outputs.audio.request_channels(inputs.channels); }

void operator()()
{
if(outputs.audio.channels != inputs.channels)
{
outputs.audio.request_channels(inputs.channels);
return;
}
}
};
}

0 comments on commit a0b3e28

Please sign in to comment.