A modern Music Player Daemon based on Rockbox open source high quality audio player
libadwaita audio rust zig deno mpris rockbox mpd
at master 198 lines 4.1 kB view raw
1/* Copyright (c) 1997-1999 Miller Puckette. 2* For information on usage and redistribution, and for a DISCLAIMER OF ALL 3* WARRANTIES, see the file, "LICENSE.txt," in this distribution. */ 4 5/* utility functions for signals 6*/ 7 8#ifdef ROCKBOX 9#include "plugin.h" 10#include "../../pdbox.h" 11#endif 12 13#include "m_pd.h" 14#include "../../math.h" 15#define LOGTEN 2.302585092994 16 17float mtof(float f) 18{ 19 if (f <= -1500) return(0); 20 else if (f > 1499) return(mtof(1499)); 21 else return (8.17579891564 * exp(.0577622650 * f)); 22} 23 24float ftom(float f) 25{ 26 return (f > 0 ? 17.3123405046 * log(.12231220585 * f) : -1500); 27} 28 29float powtodb(float f) 30{ 31 if (f <= 0) return (0); 32 else 33 { 34 float val = 100 + 10./LOGTEN * log(f); 35 return (val < 0 ? 0 : val); 36 } 37} 38 39float rmstodb(float f) 40{ 41 if (f <= 0) return (0); 42 else 43 { 44 float val = 100 + 20./LOGTEN * log(f); 45 return (val < 0 ? 0 : val); 46 } 47} 48 49float dbtopow(float f) 50{ 51 if (f <= 0) 52 return(0); 53 else 54 { 55 if (f > 870) 56 f = 870; 57 return (exp((LOGTEN * 0.1) * (f-100.))); 58 } 59} 60 61float dbtorms(float f) 62{ 63 if (f <= 0) 64 return(0); 65 else 66 { 67 if (f > 485) 68 f = 485; 69 } 70 return (exp((LOGTEN * 0.05) * (f-100.))); 71} 72 73/* ------------- corresponding objects ----------------------- */ 74 75static t_class *mtof_class; 76 77static void *mtof_new(void) 78{ 79 t_object *x = (t_object *)pd_new(mtof_class); 80 outlet_new(x, &s_float); 81 return (x); 82} 83 84static void mtof_float(t_object *x, t_float f) 85{ 86 outlet_float(x->ob_outlet, mtof(f)); 87} 88 89 90static t_class *ftom_class; 91 92static void *ftom_new(void) 93{ 94 t_object *x = (t_object *)pd_new(ftom_class); 95 outlet_new(x, &s_float); 96 return (x); 97} 98 99static void ftom_float(t_object *x, t_float f) 100{ 101 outlet_float(x->ob_outlet, ftom(f)); 102} 103 104 105static t_class *rmstodb_class; 106 107static void *rmstodb_new(void) 108{ 109 t_object *x = (t_object *)pd_new(rmstodb_class); 110 outlet_new(x, &s_float); 111 return (x); 112} 113 114static void rmstodb_float(t_object *x, t_float f) 115{ 116 outlet_float(x->ob_outlet, rmstodb(f)); 117} 118 119 120static t_class *powtodb_class; 121 122static void *powtodb_new(void) 123{ 124 t_object *x = (t_object *)pd_new(powtodb_class); 125 outlet_new(x, &s_float); 126 return (x); 127} 128 129static void powtodb_float(t_object *x, t_float f) 130{ 131 outlet_float(x->ob_outlet, powtodb(f)); 132} 133 134 135static t_class *dbtopow_class; 136 137static void *dbtopow_new(void) 138{ 139 t_object *x = (t_object *)pd_new(dbtopow_class); 140 outlet_new(x, &s_float); 141 return (x); 142} 143 144static void dbtopow_float(t_object *x, t_float f) 145{ 146 outlet_float(x->ob_outlet, dbtopow(f)); 147} 148 149 150static t_class *dbtorms_class; 151 152static void *dbtorms_new(void) 153{ 154 t_object *x = (t_object *)pd_new(dbtorms_class); 155 outlet_new(x, &s_float); 156 return (x); 157} 158 159static void dbtorms_float(t_object *x, t_float f) 160{ 161 outlet_float(x->ob_outlet, dbtorms(f)); 162} 163 164 165void x_acoustics_setup(void) 166{ 167 t_symbol *s = gensym("acoustics.pd"); 168 mtof_class = class_new(gensym("mtof"), mtof_new, 0, 169 sizeof(t_object), 0, 0); 170 class_addfloat(mtof_class, (t_method)mtof_float); 171 class_sethelpsymbol(mtof_class, s); 172 173 ftom_class = class_new(gensym("ftom"), ftom_new, 0, 174 sizeof(t_object), 0, 0); 175 class_addfloat(ftom_class, (t_method)ftom_float); 176 class_sethelpsymbol(ftom_class, s); 177 178 powtodb_class = class_new(gensym("powtodb"), powtodb_new, 0, 179 sizeof(t_object), 0, 0); 180 class_addfloat(powtodb_class, (t_method)powtodb_float); 181 class_sethelpsymbol(powtodb_class, s); 182 183 rmstodb_class = class_new(gensym("rmstodb"), rmstodb_new, 0, 184 sizeof(t_object), 0, 0); 185 class_addfloat(rmstodb_class, (t_method)rmstodb_float); 186 class_sethelpsymbol(rmstodb_class, s); 187 188 dbtopow_class = class_new(gensym("dbtopow"), dbtopow_new, 0, 189 sizeof(t_object), 0, 0); 190 class_addfloat(dbtopow_class, (t_method)dbtopow_float); 191 class_sethelpsymbol(dbtopow_class, s); 192 193 dbtorms_class = class_new(gensym("dbtorms"), dbtorms_new, 0, 194 sizeof(t_object), 0, 0); 195 class_addfloat(dbtorms_class, (t_method)dbtorms_float); 196 class_sethelpsymbol(dbtorms_class, s); 197} 198