Cleanup
[carla.git] / source / modules / ysfx / sources / ysfx_eel_utils.hpp
blob3933decc2fa352703925dae28e9bb10bc018a837
1 // Copyright 2021 Jean Pierre Cimalando
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 // SPDX-License-Identifier: Apache-2.0
18 #pragma once
19 #include "WDL/eel2/ns-eel.h"
20 #include "WDL/eel2/ns-eel-int.h"
21 #include <type_traits>
22 #include <cstdint>
24 template <class T>
25 inline typename std::enable_if<std::is_integral<T>::value, T>::type
26 ysfx_eel_round(EEL_F value)
28 return (T)(value + (EEL_F)0.0001); // same one as used in eel2 everywhere
31 //------------------------------------------------------------------------------
32 class ysfx_eel_ram_reader {
33 public:
34 ysfx_eel_ram_reader() = default;
35 ysfx_eel_ram_reader(NSEEL_VMCTX vm, int64_t addr);
36 EEL_F read_next();
38 private:
39 NSEEL_VMCTX m_vm{};
40 int64_t m_addr = 0;
41 const EEL_F *m_block = nullptr;
42 uint32_t m_block_avail = 0;
45 //------------------------------------------------------------------------------
46 class ysfx_eel_ram_writer {
47 public:
48 ysfx_eel_ram_writer() = default;
49 ysfx_eel_ram_writer(NSEEL_VMCTX vm, int64_t addr);
50 bool write_next(EEL_F value);
52 private:
53 NSEEL_VMCTX m_vm{};
54 int64_t m_addr = 0;
55 EEL_F *m_block = nullptr;
56 uint32_t m_block_avail = 0;