Nu:Tekt NTS-1 digital SDK  v1.1-0
userosc.h
Go to the documentation of this file.
1 /*
2  BSD 3-Clause License
3 
4  Copyright (c) 2018, KORG INC.
5  All rights reserved.
6 
7  Redistribution and use in source and binary forms, with or without
8  modification, are permitted provided that the following conditions are met:
9 
10  * Redistributions of source code must retain the above copyright notice, this
11  list of conditions and the following disclaimer.
12 
13  * Redistributions in binary form must reproduce the above copyright notice,
14  this list of conditions and the following disclaimer in the documentation
15  and/or other materials provided with the distribution.
16 
17  * Neither the name of the copyright holder nor the names of its
18  contributors may be used to endorse or promote products derived from
19  this software without specific prior written permission.
20 
21  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
25  FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27  SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 
32 //*/
33 
45 #ifndef __userosc_h
46 #define __userosc_h
47 
48 #include <stdint.h>
49 
50 #include "osc_api.h"
51 #include "userprg.h"
52 
53 #ifdef __cplusplus
54 extern "C" {
55 #endif
56 
60  typedef struct user_osc_param {
62  int32_t shape_lfo;
64  uint16_t pitch;
66  uint16_t cutoff;
68  uint16_t resonance;
69  uint16_t reserved0[3];
71 
75  typedef enum {
92  k_num_user_osc_param_id
94 
98 #define param_val_to_f32(val) ((uint16_t)val * 9.77517106549365e-004f)
99 
101  typedef void (*UserOscFuncEntry)(uint32_t platform, uint32_t api);
103  typedef void (*UserOscFuncInit)(uint32_t platform, uint32_t api);
105  typedef void (*UserOscFuncCycle)(const user_osc_param_t * const params, int32_t *buf, const uint32_t frames);
107  typedef void (*UserOscFuncOn)(const user_osc_param_t * const params);
109  typedef void (*UserOscFuncOff)(const user_osc_param_t * const params);
111  typedef void (*UserOscFuncMute)(const user_osc_param_t * const params);
113  typedef void (*UserOscFuncValue)(uint16_t value);
115  typedef void (*UserOscFuncParam)(uint16_t idx, uint16_t value);
117  typedef void (*UserOscFuncDummy)(void);
118 
120 #pragma pack(push, 1)
121  typedef struct user_osc_hook_table {
122  uint8_t magic[4];
123  uint32_t api;
124  uint8_t platform;
125  uint8_t reserved0[7];
126 
127  UserOscFuncInit func_entry;
128  UserOscFuncCycle func_cycle;
129  UserOscFuncOn func_on;
130  UserOscFuncOff func_off;
131  UserOscFuncMute func_mute;
132  UserOscFuncValue func_value;
133  UserOscFuncParam func_param;
134  UserOscFuncDummy reserved1[5];
135  } user_osc_hook_table_t;
136 #pragma pack(pop)
137 
139 #pragma pack(push, 1)
140  typedef struct user_osc_data {
141  user_prg_header_t header;
142  user_osc_hook_table_t hooks;
143  // ... more bytes following
144  } user_osc_data_t;
145 #pragma pack(pop)
146 
152 #define OSC_INIT __attribute__((used)) _hook_init
153 #define OSC_CYCLE __attribute__((used)) _hook_cycle
154 #define OSC_NOTEON __attribute__((used)) _hook_on
155 #define OSC_NOTEOFF __attribute__((used)) _hook_off
156 #define OSC_MUTE __attribute__((used)) _hook_mute
157 #define OSC_VALUE __attribute__((used)) _hook_value
158 #define OSC_PARAM __attribute__((used)) _hook_param
159 
161  void _entry(uint32_t platform, uint32_t api);
162 
169  void _hook_init(uint32_t platform, uint32_t api);
170 
181  void _hook_cycle(const user_osc_param_t * const params, int32_t *yn, const uint32_t frames);
182 
188  void _hook_on(const user_osc_param_t * const params);
189 
195  void _hook_off(const user_osc_param_t * const params);
196 
198  void _hook_mute(const user_osc_param_t * const params);
199 
201  void _hook_value(uint16_t value);
202 
213  void _hook_param(uint16_t index, uint16_t value);
214 
217 #ifdef __cplusplus
218 } // extern "C"
219 #endif
220 
221 #endif // __userosc_h
222 
user_osc_param_t
struct user_osc_param user_osc_param_t
Internal realtime parameters.
k_user_osc_param_id2
Edit parameter 2.
Definition: userosc.h:79
user_osc_param::pitch
uint16_t pitch
Current pitch.
Definition: userosc.h:64
_hook_off
void _hook_off(const user_osc_param_t *const params)
Note off callback.
k_user_osc_param_id3
Edit parameter 3.
Definition: userosc.h:81
_hook_cycle
void _hook_cycle(const user_osc_param_t *const params, int32_t *yn, const uint32_t frames)
Rendering callback.
k_user_osc_param_shiftshape
Alternative Shape parameter: generally available via a shift function.
Definition: userosc.h:91
_hook_init
void _hook_init(uint32_t platform, uint32_t api)
Initialization callback.
k_user_osc_param_id6
Edit parameter 6.
Definition: userosc.h:87
k_user_osc_param_shape
Shape parameter.
Definition: userosc.h:89
user_osc_param::cutoff
uint16_t cutoff
Current cutoff value (0x0000-0x1fff)
Definition: userosc.h:66
k_user_osc_param_id1
Edit parameter 1.
Definition: userosc.h:77
user_osc_param::shape_lfo
int32_t shape_lfo
Value of LFO implicitely applied to shape parameter.
Definition: userosc.h:62
userprg.h
Common C interface header for custom user programs.
_hook_param
void _hook_param(uint16_t index, uint16_t value)
Parameter change callback.
k_user_osc_param_id4
Edit parameter 4.
Definition: userosc.h:83
osc_api.h
Oscillator runtime API.
k_user_osc_param_id5
Edit parameter 5.
Definition: userosc.h:85
user_osc_param
Internal realtime parameters.
Definition: userosc.h:60
user_osc_param::resonance
uint16_t resonance
Current resonance value (0x0000-0x1fff)
Definition: userosc.h:68
user_osc_param_id_t
user_osc_param_id_t
User facing osc-specific parameters.
Definition: userosc.h:75
_hook_on
void _hook_on(const user_osc_param_t *const params)
Note on callback.