-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[audio] Add two simple utility objects
- Loading branch information
Showing
2 changed files
with
90 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]; | ||
} | ||
} | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
}; | ||
} |