Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Mick Grierson
maxi-js-emscripten
Commits
19f5fb0f
Commit
19f5fb0f
authored
Dec 04, 2015
by
Dr-Dan
Browse files
maxiFFT partially implemented, related example also complete.
parent
d03ebeb2
Changes
14
Expand all
Hide whitespace changes
Inline
Side-by-side
Makefile
View file @
19f5fb0f
...
...
@@ -8,7 +8,7 @@ EMSCR=../../em++
POST_JS
=
src/js/maxi_webAudio.js
#the .cpp file that is used
SOURCE_MAXI
=
src/cpp/maxi_emscr_new.cpp
#src/cpp/libs/fft.cpp
SOURCE_MAXI
=
src/cpp/maxi_emscr_new.cpp
# destination .js file
OUTPUT_MAXI
=
maxiLib/maxiLib.js
...
...
@@ -16,23 +16,21 @@ OUTPUT_MAXI=maxiLib/maxiLib.js
# ----------------------------------------
# extra libs stuff
#the .cpp file that is used
SOURCE_FFT
=
src/cpp/libs/fft.cpp
SOURCE_maxiFFT
=
src/cpp/libs/maxiFFT.cpp
# destination for maxiFFT from when I didn't know better
# OUTPUT_maxiFFT=maxiLib/libs/maxiLib_maxiFFT.js
# destination for fft
OUTPUT_FFT
=
maxiLib/libs/maxiLib_fft.js
# ----------------------------------------
# General flags
# https://kripken.github.io/emscripten-site/docs/tools_reference/emcc.html
CFLAGS
=
-O3
-s
DISABLE_EXCEPTION_CATCHING
=
0
-s
ALLOW_MEMORY_GROWTH
=
1
--memory-init-file
0
--profiling
# -s DEMANGLE_SUPPORT=1
CFLAGS
=
-O3
-s
DISABLE_EXCEPTION_CATCHING
=
0
-s
ALLOW_MEMORY_GROWTH
=
1
-s
ASSERTIONS
=
1
--memory-init-file
0
--profiling
# ----------------------------------------
# Final paths
maxi
:
$(EMSCR)
$(CFLAGS)
--post-js
$(POST_JS)
--bind
-o
$(OUTPUT_MAXI)
$(SOURCE_MAXI)
fft
:
$(EMSCR)
$(CFLAGS)
--bind
-o
$(OUTPUT_FFT)
$(SOURCE_FFT)
$(EMSCR)
$(CFLAGS)
--post-js
$(POST_JS)
--bind
-o
$(OUTPUT_MAXI)
$(SOURCE_MAXI)
$(SOURCE_maxiFFT)
all
:
maxi fft
\ No newline at end of file
all
:
maxi
\ No newline at end of file
maxiLib/index.php
0 → 100644
View file @
19f5fb0f
<html><head>
<meta
http-equiv=
"content-type"
content=
"text/html; charset=UTF-8"
>
<title>
Javascript Audio Processing
</title>
</head>
<body>
<?php
$directory
=
"maximilian_examples_web/"
;
$phpfiles
=
glob
(
$directory
.
"*.html"
);
natsort
(
$phpfiles
);
foreach
(
$phpfiles
as
$phpfile
)
{
echo
"</br>"
;
echo
"<a href=
$phpfile
>"
.
basename
(
$phpfile
)
.
"</a>"
;
}
?>
</body>
</html>
\ No newline at end of file
maxiLib/libs/maxiLib_fft.js
deleted
100644 → 0
View file @
d03ebeb2
This diff is collapsed.
Click to expand it.
maxiLib/maxiLib.js
View file @
19f5fb0f
This diff is collapsed.
Click to expand it.
maxiLib/maximilian_examples_web/15_Polysnth.html
View file @
19f5fb0f
...
...
@@ -92,7 +92,7 @@ function setup(){
ADSR
[
i
].
setRelease
(
2000
);
}
setNumChannels
(
true
,
2
);
OutputIsArray
(
true
,
2
);
}
function
play
(){
...
...
maxiLib/maximilian_examples_web/21_maxiFFT.html
0 → 100644
View file @
19f5fb0f
<!--
Copyright 2010, Google Inc.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following disclaimer
in the documentation and/or other materials provided with the
distribution.
* Neither the name of Google Inc. nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-->
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html><head>
<meta
http-equiv=
"content-type"
content=
"text/html; charset=UTF-8"
>
<title>
Javascript Audio Processing
</title>
<!-- <link rel="stylesheet" type="text/css" href="javascript-processing_files/simple.css"> -->
<!-- <script src="../libs/maxiLib_maxiFFT.js"></script> -->
<script
src=
"../maxiLib.js"
></script>
<!-- Our javascript code -->
</head>
<body>
<h1>
FFT
</h1>
<p>
FFT example
</p>
</body>
<script
type=
"text/javascript"
>
var
fft
=
new
maximJs
.
maxiFFT
();
var
osc
=
new
maximJs
.
maxiOsc
();
var
fftSize
=
1024
;
var
magMult
=
6
;
var
count
=
0
;
var
updateIncr
=
50
;
var
ignoreCount
=
false
;
var
bars
=
[];
var
barsBottom
=
600
;
var
barsLeft
=
50
;
function
setup
(){
fft
.
setup
(
fftSize
,
512
,
256
);
// create fft display bars
for
(
var
i
=
0
;
i
<
fftSize
/
2
;
i
++
){
bars
.
push
(
document
.
createElement
(
"
p
"
));
bars
[
i
].
setAttribute
(
"
id
"
,
"
bar
"
+
i
);
bars
[
i
].
style
.
position
=
"
absolute
"
;
bars
[
i
].
style
.
left
=
barsLeft
+
i
+
"
px
"
;
bars
[
i
].
style
.
top
=
barsBottom
+
"
px
"
;
bars
[
i
].
style
.
marginBottom
=
50
+
"
px
"
;
bars
[
i
].
style
.
backgroundColor
=
"
blue
"
;
bars
[
i
].
style
.
width
=
"
1px
"
;
bars
[
i
].
style
.
height
=
"
1px
"
;
document
.
body
.
appendChild
(
bars
[
i
]);
}
}
function
play
(){
// create wave for fft
var
wave
=
osc
.
square
(
220
);
// process wave
if
(
fft
.
process
(
wave
)){
fft
.
magsToDB
();
count
++
;
// increment counter
// update if counter divisible by updateIncr
if
(
ignoreCount
||
count
%
updateIncr
==
0
){
for
(
var
i
=
0
;
i
<
fftSize
/
2
;
i
++
)
{
// change elements based on input
bars
[
i
].
style
.
height
=
(
fft
.
getMagnitude
(
i
)
*
magMult
)
+
"
px
"
;
// this must be done to change height in correct direction
bars
[
i
].
style
.
top
=
barsBottom
+
-
(
fft
.
getMagnitude
(
i
)
*
magMult
)
+
"
px
"
;
}
}
}
if
(
!
ignoreCount
){
// output can sound bad with all this dom business
output
=
wave
;
}
}
</script>
</html>
maxiLib/maximilian_examples_web/5_FM1.html
View file @
19f5fb0f
...
...
@@ -50,7 +50,8 @@ var myOtherSine = new maximJs.maxiOsc();
function
play
(){
// these two sines will beat together. They're now a bit too loud though.
output
=
mySine
.
sinewave
(
400
+
(
myOtherSine
.
sinewave
(
1
)
*
100
));
output
=
mySine
.
sinewave
(
440
+
(
myOtherSine
.
sinewave
(
1
)
*
100
));
}
...
...
maxiLib/maximilian_examples_web/8_Counting3.html
View file @
19f5fb0f
...
...
@@ -51,7 +51,7 @@ var CurrentCount;//we're going to put the current count in this variable so that
var
myOscOutput
;
//we're going to stick the output here to make it easier to mess with stuff.
function
play
(){
CurrentCount
=
myCounter
.
phasor
(
1
,
1
,
9
);
//phasor can take three arguments; frequency, start value and end value.
CurrentCount
=
Math
.
floor
(
myCounter
.
phasor
(
1
,
1
,
9
)
)
;
//phasor can take three arguments; frequency, start value and end value.
if
(
CurrentCount
<
5
){
//simple if statement
myOscOutput
=
mySwitchableOsc
.
square
(
CurrentCount
*
100
);
...
...
src/cpp/libs/fft_embind.h
deleted
100755 → 0
View file @
d03ebeb2
/*
* maximilian
* platform independent synthesis library using portaudio or rtaudio
*
* Created by Mick Grierson on 29/12/2009.
* Copyright 2009 Mick Grierson & Strangeloop Limited. All rights reserved.
* Thanks to the Goldsmiths Creative Computing Team.
* Special thanks to Arturo Castro for the PortAudio implementation.
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
*/
#ifndef _FFT
#define _FFT
#ifndef M_PI
#define M_PI 3.14159265358979323846
/* pi */
#endif
#ifdef __APPLE_CC__
#include <Accelerate/Accelerate.h>
#endif
class
fft
{
public:
fft
(
int
fftSize
);
~
fft
();
int
n
;
//fftSize
int
half
;
//halfFFTSize
float
*
in_real
,
*
out_real
,
*
in_img
,
*
out_img
;
#ifdef __APPLE_CC__
int
log2n
;
//log2(n);
FFTSetup
setupReal
;
COMPLEX_SPLIT
A
;
float
*
polar
;
void
powerSpectrum_vdsp
(
int
start
,
float
*
data
,
float
*
window
,
float
*
magnitude
,
float
*
phase
);
void
inversePowerSpectrum_vdsp
(
int
start
,
float
*
finalOut
,
float
*
window
,
float
*
magnitude
,
float
*
phase
);
void
convToDB_vdsp
(
float
*
in
,
float
*
out
);
#endif
/* Calculate the power spectrum */
void
powerSpectrum
(
int
start
,
float
*
data
,
float
*
window
,
float
*
magnitude
,
float
*
phase
);
/* ... the inverse */
void
inversePowerSpectrum
(
int
start
,
float
*
finalOut
,
float
*
window
,
float
*
magnitude
,
float
*
phase
);
void
convToDB
(
float
*
in
,
float
*
out
);
static
void
genWindow
(
int
whichFunction
,
int
NumSamples
,
float
*
window
);
};
#endif
src/cpp/libs/maxiFFT.cpp
View file @
19f5fb0f
...
...
@@ -31,9 +31,10 @@
*/
#include "maxiFFT.h"
#include "maximilian.h"
#include <iostream>
#include "math.h"
#include "maxiFFT_embind.h"
using
namespace
std
;
...
...
@@ -86,13 +87,13 @@ bool maxiFFT::process(float value) {
return
newFFT
;
}
float
*
maxiFFT
::
magsToDB
()
{
float
maxiFFT
::
magsToDB
()
{
#if defined(__APPLE_CC__) && !defined(_NO_VDSP)
_fft
->
convToDB_vdsp
(
magnitudes
,
magnitudesDB
);
#else
_fft
->
convToDB
(
magnitudes
,
magnitudesDB
);
#endif
return
magnitudesDB
;
return
*
magnitudesDB
;
}
float
maxiFFT
::
spectralFlatness
()
{
...
...
src/cpp/libs/maxiFFT.h
View file @
19f5fb0f
...
...
@@ -38,6 +38,7 @@
#include "fft.h"
#include "stddef.h"
#include "../maxi_emscr_new.h"
class
maxiFFT
{
...
...
@@ -49,13 +50,17 @@ public:
~
maxiFFT
();
void
setup
(
int
fftSize
,
int
windowSize
,
int
hopSize
);
bool
process
(
float
value
);
float
*
magsToDB
();
float
magsToDB
();
float
*
magnitudes
,
*
phases
,
*
magnitudesDB
;
float
*
avgPower
;
int
windowSize
;
int
hopSize
;
int
bins
;
float
getMagnitude
(
int
n
){
return
magnitudes
[
n
];
}
//features
float
spectralFlatness
();
float
spectralCentroid
();
...
...
src/cpp/libs/maxiFFT_embind.h
0 → 100755
View file @
19f5fb0f
/*
contains all bindings for use with emscripten
*/
#ifndef Maxi_Emscripten_maxiFFT_embind_h
#define Maxi_Emscripten_maxiFFT_embind_h
#include <emscripten.h>
#include <emscripten/bind.h>
#include "fft.cpp"
using
namespace
emscripten
;
EMSCRIPTEN_BINDINGS
(
my_module_maxiFFT
)
{
// -------------------------------------------------------------------------------------------
// LIBS
// MAXI MAXI CLOCK
class_
<
maxiFFT
>
(
"maxiFFT"
)
// .constructor<>()
// .constructor<int>()
.
smart_ptr_constructor
(
"shared_ptr<maxiFFT>"
,
&
std
::
make_shared
<
maxiFFT
>
)
.
function
(
"setup"
,
&
maxiFFT
::
setup
)
.
function
(
"process"
,
&
maxiFFT
::
process
)
.
function
(
"magsToDB"
,
&
maxiFFT
::
magsToDB
)
.
function
(
"spectralFlatness"
,
&
maxiFFT
::
spectralFlatness
)
.
function
(
"spectralCentroid"
,
&
maxiFFT
::
spectralCentroid
)
.
function
(
"getMagnitude"
,
&
maxiFFT
::
getMagnitude
)
// .function("setTempo", &maxiClock::setTempo)
// .function("setTicksPerBeat", &maxiClock::setTicksPerBeat)
// .function("isTick", &maxiClock::isTick)
// .property("tick", &maxiClock::getTick, &maxiClock::setTick)
;
};
#endif
src/cpp/maxi_embind.h
View file @
19f5fb0f
...
...
@@ -6,6 +6,7 @@
#include <emscripten.h>
#include <emscripten/bind.h>
//#include "libs/maxiFFT.h"
//extern "C" {
// // class arrayTest{
...
...
@@ -331,6 +332,21 @@ EMSCRIPTEN_BINDINGS(my_module) {
.
property
(
"tick"
,
&
maxiClock
::
getTick
,
&
maxiClock
::
setTick
)
;
// class_<maxiFFT>("maxiFFT")
// // .constructor<>()
// // .constructor<int>()
// .smart_ptr_constructor("shared_ptr<maxiFFT>",&std::make_shared<maxiFFT>)
// .function("setup", &maxiFFT::setup, allow_raw_pointers())
// .function("process", &maxiFFT::process, allow_raw_pointers())
// .function("magsToDB", &maxiFFT::magsToDB, allow_raw_pointers())
// .function("spectralFlatness", &maxiFFT::spectralFlatness, allow_raw_pointers())
// .function("spectralCentroid", &maxiFFT::spectralCentroid, allow_raw_pointers())
// // .function("setTempo", &maxiClock::setTempo)
// // .function("setTicksPerBeat", &maxiClock::setTicksPerBeat)
// // .function("isTick", &maxiClock::isTick)
//
// // .property("tick", &maxiClock::getTick, &maxiClock::setTick)
// ;
};
#endif
src/js/maxi_webAudio.js
View file @
19f5fb0f
...
...
@@ -27,7 +27,7 @@ maximJs.maxiChorus = Module.maxiChorus;
maximJs
.
maxiEnvelopeFollower
=
Module
.
maxiEnvelopeFollower
;
maximJs
.
maxiClock
=
Module
.
maxiClock
;
maximJs
.
maxiFFT
=
Module
.
maxiFFT
;
// ------------------------------------------------
// maxiArray - could extend Array object?
// cheaty array method to avoid mixing vector terminology with arrays
...
...
Write
Preview
Markdown
is supported
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