Skip to content

Commit 25955af

Browse files
fftr, vqtr
1 parent 67b0e56 commit 25955af

13 files changed

Lines changed: 624 additions & 5 deletions

File tree

src/api.h

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -852,6 +852,64 @@ enum
852852
1, \
853853
0, \
854854
double, \
855+
tic_mem*, s32 bin) \
856+
\
857+
\
858+
macro(fftr, \
859+
"fftr(startFreq,[endFreq])", \
860+
\
861+
"Get raw (non-normalized) Fast Fourier Transform magnitude for frequency range.\n" \
862+
"Reads one or averages many FFT values.\n" \
863+
"If endFreq is not given it returns a single value.\n" \
864+
"Returns raw magnitude without peak normalization.", \
865+
1, \
866+
2, \
867+
0, \
868+
double, \
869+
tic_mem*, s32 startFreq, s32 endFreq) \
870+
\
871+
\
872+
macro(fftrs, \
873+
"fftrs(startFreq,[endFreq])", \
874+
\
875+
"Get raw smoothed Fast Fourier Transform magnitude for frequency range.\n" \
876+
"Reads one or averages many FFT values.\n" \
877+
"If endFreq is not given it returns a single value.\n" \
878+
"Returns raw smoothed magnitude without peak normalization.", \
879+
1, \
880+
2, \
881+
0, \
882+
double, \
883+
tic_mem*, s32 startFreq, s32 endFreq) \
884+
\
885+
\
886+
macro(vqtr, \
887+
"vqtr(bin)", \
888+
\
889+
"Get raw (non-normalized) Variable-Q Transform magnitude for a specific frequency bin.\n" \
890+
"VQT provides 120 bins (0-119) with logarithmic frequency spacing for musical analysis.\n" \
891+
"Each bin corresponds to a musical note: bin = octave * 12 + note\n" \
892+
"where octave is 0-9 and note is 0-11 (C=0, C#=1, D=2, ..., B=11).\n" \
893+
"Returns raw magnitude without peak normalization.", \
894+
1, \
895+
1, \
896+
0, \
897+
double, \
898+
tic_mem*, s32 bin) \
899+
\
900+
\
901+
macro(vqtrs, \
902+
"vqtrs(bin)", \
903+
\
904+
"Get raw smoothed Variable-Q Transform magnitude for a specific frequency bin.\n" \
905+
"VQT provides 120 bins (0-119) with logarithmic frequency spacing for musical analysis.\n" \
906+
"Each bin corresponds to a musical note: bin = octave * 12 + note\n" \
907+
"where octave is 0-9 and note is 0-11 (C=0, C#=1, D=2, ..., B=11).\n" \
908+
"Returns raw smoothed magnitude without peak normalization.", \
909+
1, \
910+
1, \
911+
0, \
912+
double, \
855913
tic_mem*, s32 bin)
856914

857915
#define TIC_API_DEF(name, _, __, ___, ____, _____, ret, ...) ret tic_api_##name(__VA_ARGS__);

src/api/janet.c

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,10 @@ static Janet janet_fft(int32_t argc, Janet* argv);
8383
static Janet janet_ffts(int32_t argc, Janet* argv);
8484
static Janet janet_vqt(int32_t argc, Janet* argv);
8585
static Janet janet_vqts(int32_t argc, Janet* argv);
86+
static Janet janet_fftr(int32_t argc, Janet* argv);
87+
static Janet janet_fftrs(int32_t argc, Janet* argv);
88+
static Janet janet_vqtr(int32_t argc, Janet* argv);
89+
static Janet janet_vqtrs(int32_t argc, Janet* argv);
8690

8791
static void closeJanet(tic_mem* tic);
8892
static bool initJanet(tic_mem* tic, const char* code);
@@ -150,6 +154,10 @@ static const JanetReg janet_c_functions[] =
150154
{"ffts", janet_ffts, NULL},
151155
{"vqt", janet_vqt, NULL},
152156
{"vqts", janet_vqts, NULL},
157+
{"fftr", janet_fftr, NULL},
158+
{"fftrs", janet_fftrs, NULL},
159+
{"vqtr", janet_vqtr, NULL},
160+
{"vqtrs", janet_vqtrs, NULL},
153161
{NULL, NULL, NULL}
154162
};
155163

@@ -1108,6 +1116,48 @@ static Janet janet_vqts(int32_t argc, Janet* argv)
11081116
return janet_wrap_number(core->api.vqts(tic, bin));
11091117
}
11101118

1119+
static Janet janet_fftr(int32_t argc, Janet* argv)
1120+
{
1121+
janet_arity(argc, 1, 2);
1122+
1123+
s32 start_freq = janet_getinteger(argv, 0);
1124+
s32 end_freq = argc >= 2 ? janet_getinteger(argv, 1) : -1;
1125+
1126+
tic_core* core = getJanetMachine(); tic_mem* tic = (tic_mem*)core;
1127+
return janet_wrap_number(core->api.fftr(tic, start_freq, end_freq));
1128+
}
1129+
1130+
static Janet janet_fftrs(int32_t argc, Janet* argv)
1131+
{
1132+
janet_arity(argc, 1, 2);
1133+
1134+
s32 start_freq = janet_getinteger(argv, 0);
1135+
s32 end_freq = argc >= 2 ? janet_getinteger(argv, 1) : -1;
1136+
1137+
tic_core* core = getJanetMachine(); tic_mem* tic = (tic_mem*)core;
1138+
return janet_wrap_number(core->api.fftrs(tic, start_freq, end_freq));
1139+
}
1140+
1141+
static Janet janet_vqtr(int32_t argc, Janet* argv)
1142+
{
1143+
janet_fixarity(argc, 1);
1144+
1145+
s32 bin = janet_getinteger(argv, 0);
1146+
1147+
tic_core* core = getJanetMachine(); tic_mem* tic = (tic_mem*)core;
1148+
return janet_wrap_number(core->api.vqtr(tic, bin));
1149+
}
1150+
1151+
static Janet janet_vqtrs(int32_t argc, Janet* argv)
1152+
{
1153+
janet_fixarity(argc, 1);
1154+
1155+
s32 bin = janet_getinteger(argv, 0);
1156+
1157+
tic_core* core = getJanetMachine(); tic_mem* tic = (tic_mem*)core;
1158+
return janet_wrap_number(core->api.vqtrs(tic, bin));
1159+
}
1160+
11111161
/* ***************** */
11121162
static void reportError(tic_core* core, Janet result)
11131163
{

src/api/js.c

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1048,6 +1048,40 @@ static JSValue js_vqts(JSContext *ctx, JSValueConst this_val, s32 argc, JSValueC
10481048
return JS_NewFloat64(ctx, core->api.vqts(tic, bin));
10491049
}
10501050

1051+
static JSValue js_fftr(JSContext *ctx, JSValueConst this_val, s32 argc, JSValueConst *argv)
1052+
{
1053+
tic_core* core = getCore(ctx); tic_mem* tic = (tic_mem*)core;
1054+
s32 startFreq = getInteger(ctx, argv[0]);
1055+
s32 endFreq = argc >= 2 ? getInteger(ctx, argv[1]) : -1;
1056+
1057+
return JS_NewFloat64(ctx, core->api.fftr(tic, startFreq, endFreq));
1058+
}
1059+
1060+
static JSValue js_fftrs(JSContext *ctx, JSValueConst this_val, s32 argc, JSValueConst *argv)
1061+
{
1062+
tic_core* core = getCore(ctx); tic_mem* tic = (tic_mem*)core;
1063+
s32 startFreq = getInteger(ctx, argv[0]);
1064+
s32 endFreq = argc >= 2 ? getInteger(ctx, argv[1]) : -1;
1065+
1066+
return JS_NewFloat64(ctx, core->api.fftrs(tic, startFreq, endFreq));
1067+
}
1068+
1069+
static JSValue js_vqtr(JSContext *ctx, JSValueConst this_val, s32 argc, JSValueConst *argv)
1070+
{
1071+
tic_core* core = getCore(ctx); tic_mem* tic = (tic_mem*)core;
1072+
s32 bin = getInteger(ctx, argv[0]);
1073+
1074+
return JS_NewFloat64(ctx, core->api.vqtr(tic, bin));
1075+
}
1076+
1077+
static JSValue js_vqtrs(JSContext *ctx, JSValueConst this_val, s32 argc, JSValueConst *argv)
1078+
{
1079+
tic_core* core = getCore(ctx); tic_mem* tic = (tic_mem*)core;
1080+
s32 bin = getInteger(ctx, argv[0]);
1081+
1082+
return JS_NewFloat64(ctx, core->api.vqtrs(tic, bin));
1083+
}
1084+
10511085
static bool initJavascript(tic_mem* tic, const char* code)
10521086
{
10531087
closeJavascript(tic);

src/api/luaapi.c

Lines changed: 76 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
// SOFTWARE.
2222

2323
#include "core/core.h"
24-
#include "ext/vqt.h"
2524

2625
#include <stdlib.h>
2726
#include <lua.h>
@@ -1606,7 +1605,7 @@ static s32 lua_vqt(lua_State* lua)
16061605
{
16071606
s32 bin = getLuaNumber(lua, 1);
16081607

1609-
lua_pushnumber(lua, tic_api_vqt(tic, bin));
1608+
lua_pushnumber(lua, core->api.vqt(tic, bin));
16101609
return 1;
16111610
}
16121611

@@ -1624,14 +1623,88 @@ static s32 lua_vqts(lua_State* lua)
16241623
{
16251624
s32 bin = getLuaNumber(lua, 1);
16261625

1627-
lua_pushnumber(lua, tic_api_vqts(tic, bin));
1626+
lua_pushnumber(lua, core->api.vqts(tic, bin));
16281627
return 1;
16291628
}
16301629

16311630
luaL_error(lua, "invalid params, vqts(bin)\n");
16321631
return 0;
16331632
}
16341633

1634+
static s32 lua_fftr(lua_State* lua)
1635+
{
1636+
tic_core* core = getLuaCore(lua);
1637+
tic_mem* tic = (tic_mem*)core;
1638+
s32 top = lua_gettop(lua);
1639+
1640+
if (top >= 1)
1641+
{
1642+
s32 startFreq = getLuaNumber(lua, 1);
1643+
s32 endFreq = top >= 2 ? getLuaNumber(lua, 2) : -1;
1644+
1645+
lua_pushnumber(lua, core->api.fftr(tic, startFreq, endFreq));
1646+
return 1;
1647+
}
1648+
1649+
luaL_error(lua, "invalid params, fftr(startFreq [, endFreq])\n");
1650+
return 0;
1651+
}
1652+
1653+
static s32 lua_fftrs(lua_State* lua)
1654+
{
1655+
tic_core* core = getLuaCore(lua);
1656+
tic_mem* tic = (tic_mem*)core;
1657+
s32 top = lua_gettop(lua);
1658+
1659+
if (top >= 1)
1660+
{
1661+
s32 startFreq = getLuaNumber(lua, 1);
1662+
s32 endFreq = top >= 2 ? getLuaNumber(lua, 2) : -1;
1663+
1664+
lua_pushnumber(lua, core->api.fftrs(tic, startFreq, endFreq));
1665+
return 1;
1666+
}
1667+
1668+
luaL_error(lua, "invalid params, fftrs(startFreq [, endFreq])\n");
1669+
return 0;
1670+
}
1671+
1672+
static s32 lua_vqtr(lua_State* lua)
1673+
{
1674+
tic_core* core = getLuaCore(lua);
1675+
tic_mem* tic = (tic_mem*)core;
1676+
s32 top = lua_gettop(lua);
1677+
1678+
if (top >= 1)
1679+
{
1680+
s32 bin = getLuaNumber(lua, 1);
1681+
1682+
lua_pushnumber(lua, core->api.vqtr(tic, bin));
1683+
return 1;
1684+
}
1685+
1686+
luaL_error(lua, "invalid params, vqtr(bin)\n");
1687+
return 0;
1688+
}
1689+
1690+
static s32 lua_vqtrs(lua_State* lua)
1691+
{
1692+
tic_core* core = getLuaCore(lua);
1693+
tic_mem* tic = (tic_mem*)core;
1694+
s32 top = lua_gettop(lua);
1695+
1696+
if (top >= 1)
1697+
{
1698+
s32 bin = getLuaNumber(lua, 1);
1699+
1700+
lua_pushnumber(lua, core->api.vqtrs(tic, bin));
1701+
return 1;
1702+
}
1703+
1704+
luaL_error(lua, "invalid params, vqtrs(bin)\n");
1705+
return 0;
1706+
}
1707+
16351708

16361709
static int lua_dofile(lua_State *lua)
16371710
{

src/api/mruby.c

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,82 @@ static mrb_value mrb_vqts(mrb_state* mrb, mrb_value self)
606606
}
607607
}
608608

609+
static mrb_value mrb_fftr(mrb_state* mrb, mrb_value self)
610+
{
611+
mrb_int start_freq, end_freq = -1;
612+
mrb_int argc = mrb_get_args(mrb, "i|i", &start_freq, &end_freq);
613+
614+
tic_core* core = getMRubyMachine(mrb);
615+
tic_mem* tic = (tic_mem*)core;
616+
617+
if (argc == 0)
618+
{
619+
mrb_raise(mrb, E_ARGUMENT_ERROR, "invalid params, fftr [ start_freq end_freq ]\n");
620+
return mrb_nil_value();
621+
}
622+
else
623+
{
624+
return mrb_float_value(mrb, core->api.fftr(tic, start_freq, end_freq));
625+
}
626+
}
627+
628+
static mrb_value mrb_fftrs(mrb_state* mrb, mrb_value self)
629+
{
630+
mrb_int start_freq, end_freq = -1;
631+
mrb_int argc = mrb_get_args(mrb, "i|i", &start_freq, &end_freq);
632+
633+
tic_core* core = getMRubyMachine(mrb);
634+
tic_mem* tic = (tic_mem*)core;
635+
636+
if (argc == 0)
637+
{
638+
mrb_raise(mrb, E_ARGUMENT_ERROR, "invalid params, fftrs [ start_freq end_freq ]\n");
639+
return mrb_nil_value();
640+
}
641+
else
642+
{
643+
return mrb_float_value(mrb, core->api.fftrs(tic, start_freq, end_freq));
644+
}
645+
}
646+
647+
static mrb_value mrb_vqtr(mrb_state* mrb, mrb_value self)
648+
{
649+
mrb_int bin;
650+
mrb_int argc = mrb_get_args(mrb, "i", &bin);
651+
652+
tic_core* core = getMRubyMachine(mrb);
653+
tic_mem* tic = (tic_mem*)core;
654+
655+
if (argc == 0)
656+
{
657+
mrb_raise(mrb, E_ARGUMENT_ERROR, "invalid params, vqtr(bin)\n");
658+
return mrb_nil_value();
659+
}
660+
else
661+
{
662+
return mrb_float_value(mrb, core->api.vqtr(tic, bin));
663+
}
664+
}
665+
666+
static mrb_value mrb_vqtrs(mrb_state* mrb, mrb_value self)
667+
{
668+
mrb_int bin;
669+
mrb_int argc = mrb_get_args(mrb, "i", &bin);
670+
671+
tic_core* core = getMRubyMachine(mrb);
672+
tic_mem* tic = (tic_mem*)core;
673+
674+
if (argc == 0)
675+
{
676+
mrb_raise(mrb, E_ARGUMENT_ERROR, "invalid params, vqtrs(bin)\n");
677+
return mrb_nil_value();
678+
}
679+
else
680+
{
681+
return mrb_float_value(mrb, core->api.vqtrs(tic, bin));
682+
}
683+
}
684+
609685
typedef struct
610686
{
611687
mrb_state* mrb;

0 commit comments

Comments
 (0)