Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
PoroCYon
Bonzomatic
Commits
c8564206
Commit
c8564206
authored
Oct 09, 2018
by
Gargaj
Browse files
change format to float, add amplification field
parent
3bcfbe02
Changes
4
Show whitespace changes
Inline
Side-by-side
README.md
View file @
c8564206
...
...
@@ -38,6 +38,7 @@ Create a `config.json` with e.g. the following contents: (all fields are optiona
},
"
rendering
"
:{
"
fftSmoothFactor
"
:
0.9
,
// 0.0 means there's no smoothing at all, 1.0 means the FFT is completely smoothed flat
"
fftAmplification
"
:
1.0
,
// 1.0 means no change, larger values will result in brighter/stronger bands, smaller values in darker/weaker ones
},
"
textures
"
:{
// the keys below will become the shader variable names
"
texChecker
"
:
"
textures/checker.png
"
,
...
...
src/FFT.h
View file @
c8564206
...
...
@@ -2,7 +2,9 @@
namespace
FFT
{
extern
float
fAmplification
;
bool
Open
();
bool
GetFFT
(
float
*
samples
);
bool
GetFFT
(
float
*
_
samples
);
void
Close
();
}
\ No newline at end of file
src/main.cpp
View file @
c8564206
...
...
@@ -124,6 +124,8 @@ int main(int argc, const char *argv[])
{
if
(
options
.
get
<
jsonxx
::
Object
>
(
"rendering"
).
has
<
jsonxx
::
Number
>
(
"fftSmoothFactor"
))
fFFTSmoothingFactor
=
options
.
get
<
jsonxx
::
Object
>
(
"rendering"
).
get
<
jsonxx
::
Number
>
(
"fftSmoothFactor"
);
if
(
options
.
get
<
jsonxx
::
Object
>
(
"rendering"
).
has
<
jsonxx
::
Number
>
(
"fftAmplification"
))
FFT
::
fAmplification
=
options
.
get
<
jsonxx
::
Object
>
(
"rendering"
).
get
<
jsonxx
::
Number
>
(
"fftAmplification"
);
}
if
(
options
.
has
<
jsonxx
::
Object
>
(
"textures"
))
...
...
src/platform_common/FFT.cpp
View file @
c8564206
...
...
@@ -13,6 +13,7 @@ namespace FFT
mal_context
context
;
mal_device
captureDevice
;
float
sampleBuf
[
FFT_SIZE
*
2
];
float
fAmplification
=
1.0
f
;
void
OnLog
(
mal_context
*
pContext
,
mal_device
*
pDevice
,
const
char
*
message
)
{
...
...
@@ -24,7 +25,7 @@ namespace FFT
frameCount
=
frameCount
<
FFT_SIZE
*
2
?
frameCount
:
FFT_SIZE
*
2
;
// Just rotate the buffer; copy existing, append new
const
mal_int16
*
samples
=
(
const
mal_int16
*
)
pSamples
;
const
float
*
samples
=
(
const
float
*
)
pSamples
;
float
*
p
=
sampleBuf
;
for
(
int
i
=
0
;
i
<
FFT_SIZE
*
2
-
frameCount
;
i
++
)
{
...
...
@@ -32,7 +33,7 @@ namespace FFT
}
for
(
int
i
=
0
;
i
<
frameCount
;
i
++
)
{
*
(
p
++
)
=
(
samples
[
i
*
2
]
+
samples
[
i
*
2
+
1
]
)
/
65535.0
f
;
// int16 max * 2 -> -1..1
*
(
p
++
)
=
(
samples
[
i
*
2
]
+
samples
[
i
*
2
+
1
]
)
/
2.0
f
*
fAmplification
;
}
}
...
...
@@ -52,7 +53,7 @@ namespace FFT
printf
(
"[FFT] MAL context initialized, backend is '%s'
\n
"
,
mal_get_backend_name
(
context
.
backend
)
);
const
mal_device_config
config
=
mal_device_config_init
(
mal_format_
s16
,
2
,
44100
,
OnReceiveFrames
,
NULL
);
const
mal_device_config
config
=
mal_device_config_init
(
mal_format_
f32
,
2
,
44100
,
OnReceiveFrames
,
NULL
);
result
=
mal_device_init
(
&
context
,
mal_device_type_capture
,
NULL
,
&
config
,
NULL
,
&
captureDevice
);
if
(
result
!=
MAL_SUCCESS
)
...
...
@@ -73,7 +74,7 @@ namespace FFT
return
true
;
}
bool
GetFFT
(
float
*
samples
)
bool
GetFFT
(
float
*
_
samples
)
{
kiss_fft_cpx
out
[
FFT_SIZE
+
1
];
kiss_fftr
(
fftcfg
,
sampleBuf
,
out
);
...
...
@@ -81,7 +82,7 @@ namespace FFT
for
(
int
i
=
0
;
i
<
FFT_SIZE
;
i
++
)
{
static
const
float
scaling
=
1.0
f
/
(
float
)
FFT_SIZE
;
samples
[
i
]
=
2.0
*
sqrtf
(
out
[
i
].
r
*
out
[
i
].
r
+
out
[
i
].
i
*
out
[
i
].
i
)
*
scaling
;
_
samples
[
i
]
=
2.0
*
sqrtf
(
out
[
i
].
r
*
out
[
i
].
r
+
out
[
i
].
i
*
out
[
i
].
i
)
*
scaling
;
}
return
true
;
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment