'Sample & Hold' node.

main
Ben Niemann 1 year ago
parent 3ccbc3a7a5
commit 2ab4c6ea1b

@ -0,0 +1,59 @@
/*
* @begin:license
*
* Copyright (c) 2015-2021, Ben Niemann <pink@odahoda.de>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* @end:license
*/
#include <cmath>
#include <string>
#include <vector>
#include "noisicaa/engine/engine_impl.h"
#include "noisicaa/engine/buffers.h"
#include "noisicaa/engine/block_context.h"
#include "noisicaa/engine/node_db.h"
#include "noisicaa/node_lib/sample_and_hold/audio.h"
namespace noisicaa::engine::sample_and_hold {
Node::Node(EngineImpl* engine, uint64_t id)
: ProcessorNode(engine, id, "noisicaa.node_lib.sample_and_hold") {}
Status Node::run(BlockContext* ctxt, const std::vector<Buffer*>* buffers) {
float* in = (float*)buffers->at(0)->data();
float* trigger = (float*)buffers->at(1)->data();
float* out = (float*)buffers->at(2)->data();
for (uint32_t smpl = 0 ; smpl < ctxt->block_size ; ++smpl, ++in, ++trigger) {
if (*trigger >= 0.55 && !_trig) {
_trig = true;
_hold = *in;
} else if (*trigger < 0.45 && _trig) {
_trig = false;
}
*out++ = _hold;
}
return Status::Ok();
}
NOISICAA_REGISTER_NODE_CLASS(Node, "node://sample-and-hold")
} // namespace noisicaa::engine::sample_and_hold

@ -0,0 +1,55 @@
// -*- mode: c++ -*-
/*
* @begin:license
*
* Copyright (c) 2015-2021, Ben Niemann <pink@odahoda.de>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* @end:license
*/
#ifndef _NOISICAA_NODE_LIB_SAMPLE_AND_HOLD_H
#define _NOISICAA_NODE_LIB_SAMPLE_AND_HOLD_H
#include <memory>
#include <vector>
#include "noisicaa/core/status.h"
#include "noisicaa/engine/processor_node.h"
namespace noisicaa::engine {
class EngineImpl;
class Program;
namespace sample_and_hold {
class Node : public ProcessorNode {
public:
Node(EngineImpl* engine, uint64_t id);
Status run(BlockContext* ctxt, const std::vector<Buffer*>* buffers) override;
private:
float _hold = 0.0;
bool _trig = false;
};
} // namespace sample_and_hold
} // namespace noisicaa::engine
#endif

@ -0,0 +1,13 @@
uri: builtin://sample-and-hold
audio_class_uri: node://sample-and-hold
display_name: Sample & Hold
ports:
- name: in
direction: INPUT
type: AUDIO
- name: trigger
direction: INPUT
type: AUDIO
- name: out
direction: OUTPUT
type: AUDIO

@ -0,0 +1,24 @@
# @begin:license
#
# Copyright (c) 2015-2021, Ben Niemann <pink@odahoda.de>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
# @end:license
def build(ctx):
ctx.noise_node(
has_audio=True,
)
Loading…
Cancel
Save