Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
maxi-js-emscripten
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
3
Issues
3
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Daniel Clarke
maxi-js-emscripten
Commits
4dd91ce1
Commit
4dd91ce1
authored
Nov 20, 2015
by
Daniel Clarke
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
working with safari now
parent
2cafb6fe
Changes
4
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
149 additions
and
161 deletions
+149
-161
Makefile
Makefile
+1
-1
maxiLib.js
maxiLib/maxiLib.js
+54
-66
maxi_emscr.h
src/cpp/maxi_emscr.h
+33
-33
maxi_webAudio.js
src/js/maxi_webAudio.js
+61
-61
No files found.
Makefile
View file @
4dd91ce1
...
...
@@ -10,7 +10,7 @@ SOURCE=src/cpp/maxi_emscr.cpp
# destination .js file
OUTPUT
=
maxiLib/maxiLib.js
EXP_FUNCS
=
-s
EXPORTED_FUNCTIONS
=
"['_sumArray']"
#
EXP_FUNCS=-s EXPORTED_FUNCTIONS="['_sumArray']"
# https://kripken.github.io/emscripten-site/docs/tools_reference/emcc.html
CFLAGS
=
-O2
$(EXP_FUNCS)
-s
DISABLE_EXCEPTION_CATCHING
=
0
-s
ALLOW_MEMORY_GROWTH
=
1
--memory-init-file
0
--profiling
...
...
maxiLib/maxiLib.js
View file @
4dd91ce1
This diff is collapsed.
Click to expand it.
src/cpp/maxi_emscr.h
View file @
4dd91ce1
...
...
@@ -63,14 +63,14 @@ public:
int
sumArray
(
uintptr_t
input
,
size_t
len
)
{
const
int
*
ptr
=
reinterpret_cast
<
int
*>
(
input
);
// double n = 0;
// for(int i = 0; i < len; i++){
// n+=ptr[i];
// }
// double n = 0;
// for(int i = 0; i < len; i++){
// n+=ptr[i];
// }
return
ptr
[
0
];
}
};
class
maxiSettings
{
public:
...
...
@@ -127,7 +127,7 @@ class maxiEnvelope {
public:
// maxiEnvelope(){}
double
line
(
int
numberofsegments
,
std
::
vector
<
double
>&
segments
);
// double line(int numberofsegments , double segments[1000]);
// double line(int numberofsegments , double segments[1000]);
void
trigger
(
int
index
,
double
amp
);
int
valindex
;
...
...
@@ -194,7 +194,7 @@ class maxiMix {
// double two[2];
// double four[4];
// double eight[8];
public:
// double x;
// double y;
...
...
@@ -204,7 +204,7 @@ public:
currently using non-pointer version for embind, need to sort out pointer stuff though
embind has no support for pointers to primitives!
*/
// double *stereo(double input,double two[2],double x);
// double *stereo(double input,double two[2],double x);
// double *quad(double input,double four[4], double x,double y);
// double *ambisonic(double input,double eight[8],double x,double y, double z);
...
...
@@ -215,37 +215,37 @@ public:
};
//lagging with an exponential moving average
//a lower alpha value gives a slower lag
template
<
class
T
>
class
maxiLagExp
{
public:
//lagging with an exponential moving average
//a lower alpha value gives a slower lag
template
<
class
T
>
class
maxiLagExp
{
public:
T
alpha
,
alphaReciprocal
;
T
val
;
maxiLagExp
()
{
init
(
0
.
5
,
0
.
0
);
init
(
0
.
5
,
0
.
0
);
};
// haven't worked out how to do this (override) with smart_ptr_constructor?!
// maxiLagExp(T initAlpha, T initVal) {
// init(initAlpha, initVal);
// }
// haven't worked out how to do this (override) with smart_ptr_constructor?!
// maxiLagExp(T initAlpha, T initVal) {
// init(initAlpha, initVal);
// }
void
init
(
T
initAlpha
,
T
initVal
)
{
alpha
=
initAlpha
;
alphaReciprocal
=
1
.
0
-
alpha
;
val
=
initVal
;
alpha
=
initAlpha
;
alphaReciprocal
=
1
.
0
-
alpha
;
val
=
initVal
;
}
// no need for inline if declared/defined in .h file
// no need for inline if declared/defined in .h file
void
addSample
(
T
newVal
)
{
val
=
(
alpha
*
newVal
)
+
(
alphaReciprocal
*
val
);
val
=
(
alpha
*
newVal
)
+
(
alphaReciprocal
*
val
);
}
T
value
()
{
return
val
;
return
val
;
}
};
};
//lagging with an exponential moving average
...
...
@@ -255,16 +255,16 @@ public:
//public:
// double alpha, alphaReciprocal;
// double val;
//
//
// maxiLagExp() {
// init(0.5, 0.0);
// };
//
//
//
//
// maxiLagExp(double initAlpha, double initVal) {
// init(initAlpha, initVal);
// }
//
//
// void init(double initAlpha, double initVal) {
// alpha = initAlpha;
// alphaReciprocal = 1.0 - alpha;
...
...
@@ -274,7 +274,7 @@ public:
// void addSample(double newVal) {
// val = (alpha * newVal) + (alphaReciprocal * val);
// }
//
//
// double value() {
// return val;
// }
...
...
@@ -364,7 +364,7 @@ public:
double
play
();
void
clear
(){
tempVec
.
clear
();}
double
playOnce
();
double
playOnce
();
//
double
playOnce
(
double
speed
);
//
...
...
@@ -379,7 +379,7 @@ public:
//
double
play4
(
double
frequency
,
double
start
,
double
end
);
//
double
bufferPlay
(
unsigned
char
&
bufferin
,
long
length
);
double
bufferPlay
(
unsigned
char
&
bufferin
,
long
length
);
//
// double bufferPlay(unsigned char &bufferin,double speed,long length);
//
...
...
src/js/maxi_webAudio.js
View file @
4dd91ce1
// might adopt some strange functions from Module?
// var maximJs = Module;
var
maximTools
=
{};
// alternatively...
// probably better this way
// no inheritance of Module stuff...
...
...
@@ -27,42 +29,14 @@ maximJs.maxiChorus = Module.maxiChorus;
maximJs
.
maxiEnvelopeFollower
=
Module
.
maxiEnvelopeFollower
;
// alternative array method to avoid mixing vector terminology with arrays
// seems like bad practice though and needs some testing...
// how to stop people messing with vec and its effects on object
// ------------------------------------------------
// maxiArray - could extend Array object?
// cheaty array method to avoid mixing vector terminology with arrays
// but have to copy everything?!
// better to use GetArrayAsVectorDbl function ???
maximJs
.
maxiArray
=
function
maxiArray
(){
this
.
length
=
0
;
this
.
vec
=
new
Module
.
VectorDouble
();
this
.
set
=
function
(
arrayIn
){
this
.
clear
();
this
.
vec
=
GetArrayAsVectorDbl
(
arrayIn
);
this
.
length
=
this
.
vec
.
size
();
};
// set object properties to mimic array
this
.
SetSqBrackets
=
function
(
useSq
){
for
(
var
i
=
0
;
i
<
this
.
length
;
i
++
){
if
(
useSq
){
this
[
i
]
=
this
.
vec
.
get
(
i
);
}
else
{
delete
this
[
i
];
}
}
};
this
.
clear
=
function
(
useSq
){
for
(
var
i
=
0
;
i
<
this
.
length
;
i
++
){
delete
this
[
i
];
}
Module
.
vectorTools
.
clearVectorDbl
(
this
.
vec
);
this
.
length
=
0
;
};
this
.
push
=
function
(
num
){
this
.
vec
.
push_back
(
num
);
this
.
length
++
;
};
var
vec
=
new
Module
.
VectorDouble
();
// this.update = function(){
// var lengthsMatch = this.length !== this.vec.size();
...
...
@@ -83,6 +57,54 @@ this.push = function(num){
// };
};
maximJs
.
maxiArray
.
prototype
.
asVector
=
function
(
arrayIn
){
return
this
.
vec
;
};
maximJs
.
maxiArray
.
prototype
.
asJsArray
=
function
(
arrayIn
){
var
arrayOut
=
[];
for
(
var
i
=
0
;
i
<
this
.
length
;
i
++
){
array
.
push
(
this
.
vec
.
get
(
i
));
}
return
arrayOut
;
};
maximJs
.
maxiArray
.
prototype
.
set
=
function
(
arrayIn
){
this
.
clear
();
this
.
vec
=
GetArrayAsVectorDbl
(
arrayIn
);
this
.
length
=
this
.
vec
.
size
();
this
.
SetSqBrackets
(
true
);
};
maximJs
.
maxiArray
.
prototype
.
push
=
function
(
num
){
this
.
vec
.
push_back
(
num
);
this
[
this
.
length
]
=
num
;
this
.
length
++
;
};
// set object properties to mimic array
// this doesn't seem particularly efficient or smart
maximJs
.
maxiArray
.
prototype
.
SetSqBrackets
=
function
(
useSq
){
for
(
var
i
=
0
;
i
<
this
.
length
;
i
++
){
if
(
useSq
){
this
[
i
]
=
this
.
vec
.
get
(
i
);
}
else
{
delete
this
[
i
];
}
}
};
maximJs
.
maxiArray
.
prototype
.
clear
=
function
(
useSq
){
for
(
var
i
=
0
;
i
<
this
.
length
;
i
++
){
delete
this
[
i
];
}
Module
.
vectorTools
.
clearVectorDbl
(
this
.
vec
);
this
.
length
=
0
;
};
function
GetArrayAsVectorDbl
(
arrayIn
){
var
vecOut
=
new
Module
.
VectorDouble
();
for
(
var
i
=
0
;
i
<
arrayIn
.
length
;
i
++
){
...
...
@@ -92,13 +114,15 @@ function GetArrayAsVectorDbl(arrayIn){
return
vecOut
;
}
// ------------------------------------------------
// would be nice to put this (all below) in function/class of some sort
// Temporary patch until all browsers support unprefixed context.
AudioContext
=
AudioContext
||
webkitAudioContext
;
//
AudioContext = AudioContext || webkitAudioContext;
// var context;
var
context
=
new
AudioContext
();
// var context = new AudioContext();
var
context
=
new
webkitAudioContext
()
||
new
AudioContext
();
// context = new (window.AudioContext || window.webkitAudioContext)();
var
source
;
...
...
@@ -175,7 +199,7 @@ function process(event) {
}
else
{
for
(
var
channel
=
0
;
channel
<
numChannels
;
channel
++
)
{
for
(
var
channel
=
0
;
channel
<
numChannels
;
channel
++
)
{
event
.
outputBuffer
.
getChannelData
(
channel
)[
i
]
=
output
;
}
}
...
...
@@ -205,22 +229,6 @@ function init() {
setup
();
}
// function loadSampleBuffers(url){
// bufferLoader = new BufferLoader(
// context,
// [url],
// finishedLoading
// );
// bufferLoader.load();
// // var sources = [];
// // for(var i = 0; i < urls.length; i++){
// // var sourceI = context.createBufferSource();
// // sourceI.buffer = bufferList[i];
// // }
// }
function
loadSample
(
url
,
samplePlayer
)
{
var
data
=
[];
...
...
@@ -269,11 +277,3 @@ function loadSample(url, samplePlayer) {
function
transferComplete
(
evt
)
{
console
.
log
(
"
The transfer is complete.
"
);
}
// function playSound(buffer) {
// var source = context.createBufferSource(); // creates a sound source
// source.buffer = buffer; // tell the source which sound to play
// source.connect(context.destination); // connect the source to the context's destination (the speakers)
// source.start(0); // play the source now
// // note: on older systems, may have to use deprecated noteOn(time);
// }
\ No newline at end of file
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