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
2090a747
Commit
2090a747
authored
Oct 19, 2015
by
Dr-Dan
Browse files
binded more play functions to maxiSample, play4 is misbehaving
parent
f808123b
Changes
8
Expand all
Hide whitespace changes
Inline
Side-by-side
Maxi_Emscripten/Maxi_Emscripten.xcodeproj/project.xcworkspace/xcshareddata/Maxi_Emscripten.xccheckout
0 → 100644
View file @
2090a747
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist
version=
"1.0"
>
<dict>
<key>
IDESourceControlProjectFavoriteDictionaryKey
</key>
<false/>
<key>
IDESourceControlProjectIdentifier
</key>
<string>
60ED41D8-5A86-4A08-934A-D5D543E71DB5
</string>
<key>
IDESourceControlProjectName
</key>
<string>
project
</string>
<key>
IDESourceControlProjectOriginsDictionary
</key>
<dict>
<key>
2653DE3A5C3DAD65C1C716DDF72F2CEE601CF5A0
</key>
<string>
http://gitlab.doc.gold.ac.uk/dclar011/maxi-js-emscripten.git
</string>
</dict>
<key>
IDESourceControlProjectPath
</key>
<string>
Maxi_Emscripten/Maxi_Emscripten.xcodeproj/project.xcworkspace
</string>
<key>
IDESourceControlProjectRelativeInstallPathDictionary
</key>
<dict>
<key>
2653DE3A5C3DAD65C1C716DDF72F2CEE601CF5A0
</key>
<string>
../../..
</string>
</dict>
<key>
IDESourceControlProjectURL
</key>
<string>
http://gitlab.doc.gold.ac.uk/dclar011/maxi-js-emscripten.git
</string>
<key>
IDESourceControlProjectVersion
</key>
<integer>
111
</integer>
<key>
IDESourceControlProjectWCCIdentifier
</key>
<string>
2653DE3A5C3DAD65C1C716DDF72F2CEE601CF5A0
</string>
<key>
IDESourceControlProjectWCConfigurations
</key>
<array>
<dict>
<key>
IDESourceControlRepositoryExtensionIdentifierKey
</key>
<string>
public.vcs.git
</string>
<key>
IDESourceControlWCCIdentifierKey
</key>
<string>
2653DE3A5C3DAD65C1C716DDF72F2CEE601CF5A0
</string>
<key>
IDESourceControlWCCName
</key>
<string>
maximilian
</string>
</dict>
</array>
</dict>
</plist>
Maxi_Emscripten/Maxi_Emscripten.xcodeproj/project.xcworkspace/xcuserdata/Dan.xcuserdatad/UserInterfaceState.xcuserstate
View file @
2090a747
No preview for this file type
Maxi_Emscripten/Maxi_Emscripten/maxi_embind.h
View file @
2090a747
...
...
@@ -80,14 +80,21 @@ EMSCRIPTEN_BINDINGS(my_module) {
class_
<
maxiSample
>
(
"maxiSample"
)
.
constructor
<>
()
.
function
(
"setSample"
,
&
maxiSample
::
setSample
)
.
function
(
"getSummary"
,
&
maxiSample
::
getSummary
)
.
function
(
"play"
,
&
maxiSample
::
play
)
// .function("getSummary", &maxiSample::getSummary)
.
function
(
"playOnce"
,
&
maxiSample
::
playOnce
)
.
function
(
"play"
,
select_overload
<
double
()
>
(
&
maxiSample
::
play
))
.
function
(
"play"
,
select_overload
<
double
(
double
)
>
(
&
maxiSample
::
play
))
.
function
(
"play"
,
select_overload
<
double
(
double
,
double
,
double
)
>
(
&
maxiSample
::
play
))
// .function("play", select_overload<double(double, double, double, double&)>(&maxiSample::play))
.
function
(
"play4"
,
&
maxiSample
::
play4
)
.
function
(
"trigger"
,
&
maxiSample
::
trigger
)
.
function
(
"clear"
,
&
maxiSample
::
clear
)
// .function("load", &maxiSample::load)
// .function("read", &maxiSample::read, allow_raw_pointers())
// .function("play", &maxiSample::play)
;
}
#endif
Maxi_Emscripten/Maxi_Emscripten/maxi_emscr.cpp
View file @
2090a747
...
...
@@ -540,26 +540,18 @@ bool maxiSample::read()
}
*/
//This plays back at the correct speed. Always loops.
//double maxiSample::play() {
// position++;
// if ((long) position == length) position=0;
// output = (double) temp[(long)position]/32767.0;
// return output;
//}
// my version for easier use with js
double
maxiSample
::
play
()
{
position
++
;
if
((
int
)
position
==
length
)
position
=
0
;
output
=
(
double
)(
myData
DC
.
at
((
int
)
position
));
output
=
(
double
)(
temp
DC
.
at
((
int
)
position
));
return
output
;
}
void
maxiSample
::
setSample
(
vector
<
double
>&
temp
){
myData
DC
=
temp
;
length
=
myData
DC
.
size
();
temp
DC
=
temp
;
length
=
temp
DC
.
size
();
}
...
...
@@ -576,15 +568,15 @@ void maxiSample::setSample(vector<double>& temp){
//}
//Same as above but takes a speed value specified as a ratio, with 1.0 as original speed
//
double maxiSample::playOnce(double speed) {
//
position=position+((speed*chandiv)/(maxiSettings::sampleRate/mySampleRate));
//
double remainder = position - (long) position;
//
if ((long) position<length)
//
output = (double) ((1-remainder) * temp
[
1+ (long) position
]
+ remainder * temp
[
2+(long) position
])/32767
;//linear interpolation
//
else
//
output=0;
//
return(output);
//
}
double
maxiSample
::
playOnce
(
double
speed
)
{
position
=
position
+
((
speed
*
chandiv
)
/
(
maxiSettings
::
sampleRate
/
mySampleRate
));
double
remainder
=
position
-
(
long
)
position
;
if
((
long
)
position
<
length
)
output
=
(
double
)
((
1
-
remainder
)
*
temp
DC
.
at
(
1
+
(
long
)
position
)
+
remainder
*
temp
DC
.
at
(
2
+
(
long
)
position
))
;
//linear interpolation
else
output
=
0
;
return
(
output
);
}
//As above but looping
double
maxiSample
::
play
(
double
speed
)
{
...
...
@@ -604,41 +596,42 @@ double maxiSample::play(double speed) {
}
if
(
position
+
2
<
length
)
{
b
=
position
+
2
;
b
=
position
+
2
;
}
else
{
b
=
length
-
1
;
b
=
length
-
1
;
}
output
=
(
double
)
((
1
-
remainder
)
*
temp
[
a
]
+
remainder
*
temp
[
b
])
/
32767
;
//linear interpolation
}
else
{
output
=
(
double
)
((
1
-
remainder
)
*
temp
DC
.
at
(
a
)
+
remainder
*
temp
DC
.
at
(
b
))
;
//linear interpolation
}
else
{
if
((
long
)
position
<
0
)
position
=
length
;
remainder
=
position
-
floor
(
position
);
if
(
position
-
1
>=
0
)
{
a
=
position
-
1
;
}
else
{
a
=
0
;
}
if
(
position
-
2
>=
0
)
{
b
=
position
-
2
;
}
else
{
b
=
0
;
}
output
=
(
double
)
((
-
1
-
remainder
)
*
temp
[
a
]
+
remainder
*
temp
[
b
])
/
32767
;
//linear interpolation
}
}
else
{
a
=
0
;
}
if
(
position
-
2
>=
0
)
{
b
=
position
-
2
;
}
else
{
b
=
0
;
}
output
=
(
double
)
((
-
1
-
remainder
)
*
temp
DC
.
at
(
a
)
+
remainder
*
temp
DC
.
at
(
b
))
;
//linear interpolation
}
return
(
output
);
}
/*
//placeholder
double
maxiSample
::
play
(
double
frequency
,
double
start
,
double
end
)
{
return
play
(
frequency
,
start
,
end
,
position
);
}
//This allows you to say how often a second you want a specific chunk of audio to play
double maxiSample::play(double frequency, double start, double end, double
&pos) {
double
maxiSample
::
play
(
double
frequency
,
double
start
,
double
end
,
double
&
pos
)
{
double
remainder
;
if
(
end
>=
length
)
end
=
length
-
1
;
long
a
,
b
;
...
...
@@ -666,8 +659,8 @@ double maxiSample::play(double frequency, double start, double end, double &pos)
b
=
length
-
1
;
}
output = (double) ((1-remainder) * temp
[a]
+
remainder * temp
[b])/32767
;//linear interpolation
output
=
(
double
)
((
1
-
remainder
)
*
temp
DC
.
at
(
a
)
+
remainder
*
temp
DC
.
at
(
b
))
;
//linear interpolation
}
else
{
frequency
=
frequency
-
(
frequency
+
frequency
);
if
(
pos
<=
start
)
pos
=
end
;
...
...
@@ -686,8 +679,8 @@ double maxiSample::play(double frequency, double start, double end, double &pos)
else
{
b
=
0
;
}
output = (double) ((-1-remainder) * temp
[a]
+
remainder * temp
[b])/32767
;//linear interpolation
output
=
(
double
)
((
-
1
-
remainder
)
*
temp
DC
.
at
(
a
)
+
remainder
*
temp
DC
.
at
(
b
))
;
//linear interpolation
}
...
...
@@ -696,42 +689,46 @@ double maxiSample::play(double frequency, double start, double end, double &pos)
//Same as above. better cubic inerpolation. Cobbled together from various (pd externals, yehar, other places).
// needs fixing for online version
double
maxiSample
::
play4
(
double
frequency
,
double
start
,
double
end
)
{
double
remainder
;
double
a
,
b
,
c
,
d
,
a1
,
a2
,
a3
;
if (frequency >0.) {
if
(
frequency
>
0.
)
{
if
(
position
<
start
)
{
position
=
start
;
}
if
(
position
>=
end
)
position
=
start
;
position
+=
((
end
-
start
)
/
(
maxiSettings
::
sampleRate
/
(
frequency
*
chandiv
)));
remainder
=
position
-
floor
(
position
);
if
(
position
>
0
)
{
a=temp
[(int
)(floor(position))-1
]
;
a
=
temp
DC
.
at
((
long
)(
floor
(
position
))
-
1
)
;
}
else
{
a=temp
[0]
;
a
=
temp
DC
.
at
(
0
)
;
}
b=temp
[
(long) position
]
;
b
=
temp
DC
.
at
(
(
long
)
position
)
;
if
(
position
<
end
-
2
)
{
c=temp
[
(long) position+1
]
;
c
=
temp
DC
.
at
(
(
long
)
position
+
1
)
;
}
else
{
c=temp
[0]
;
c
=
temp
DC
.
at
(
0
)
;
}
if
(
position
<
end
-
3
)
{
d=temp
[
(long) position+2
]
;
d
=
temp
DC
.
at
(
(
long
)
position
+
2
)
;
}
else
{
d=temp
[0]
;
d
=
temp
DC
.
at
(
0
)
;
}
a1
=
0.5
f
*
(
c
-
a
);
a2
=
a
-
2.5
*
b
+
2.
f
*
c
-
0.5
f
*
d
;
a3
=
0.5
f
*
(
d
-
a
)
+
1.5
f
*
(
b
-
c
);
output = (double) (((a3 * remainder + a2) * remainder + a1) * remainder + b)
/ 32767
;
output
=
(
double
)
(((
a3
*
remainder
+
a2
)
*
remainder
+
a1
)
*
remainder
+
b
);
}
else
{
frequency
=
frequency
-
(
frequency
+
frequency
);
...
...
@@ -739,38 +736,38 @@ double maxiSample::play4(double frequency, double start, double end) {
position
-=
((
end
-
start
)
/
(
maxiSettings
::
sampleRate
/
(
frequency
*
chandiv
)));
remainder
=
position
-
floor
(
position
);
if
(
position
>
start
&&
position
<
end
-
1
)
{
a=temp
[
(long) position+1
]
;
a
=
temp
DC
.
at
(
(
long
)
position
+
1
)
;
}
else
{
a=temp
[0]
;
a
=
temp
DC
.
at
(
0
)
;
}
b=temp
[
(long) position
]
;
b
=
temp
DC
.
at
(
(
long
)
position
)
;
if
(
position
>
start
)
{
c=temp
[
(long) position-1
]
;
c
=
temp
DC
.
at
(
(
long
)
position
-
1
)
;
}
else
{
c=temp
[0]
;
c
=
temp
DC
.
at
(
0
)
;
}
if
(
position
>
start
+
1
)
{
d=temp
[
(long) position-2
]
;
d
=
temp
DC
.
at
(
(
long
)
position
-
2
)
;
}
else
{
d=temp
[0]
;
d
=
temp
DC
.
at
(
0
)
;
}
a1
=
0.5
f
*
(
c
-
a
);
a2
=
a
-
2.5
*
b
+
2.
f
*
c
-
0.5
f
*
d
;
a3
=
0.5
f
*
(
d
-
a
)
+
1.5
f
*
(
b
-
c
);
output = (double) (((a3 * remainder + a2) * -remainder + a1) * -remainder + b)
/ 32767
;
output
=
(
double
)
(((
a3
*
remainder
+
a2
)
*
-
remainder
+
a1
)
*
-
remainder
+
b
);
}
return
(
output
);
}
/*
//You don't need to worry about this stuff.
double maxiSample::bufferPlay(unsigned char &bufferin,long length) {
double remainder;
...
...
Maxi_Emscripten/Maxi_Emscripten/maxi_emscr.h
View file @
2090a747
...
...
@@ -226,7 +226,7 @@ class maxiSample {
private:
string
myPath
;
int
myChunkSize
;
int
mySubChunk1Size
;
int
mySubChunk1Size
;
int
readChannel
;
short
myFormat
;
int
myByteRate
;
...
...
@@ -250,7 +250,7 @@ public:
short
*
temp
;
// different vars for use with js
vector
<
double
>
myData
DC
;
vector
<
double
>
temp
DC
;
// get/set for the Path property
~
maxiSample
()
...
...
@@ -300,21 +300,25 @@ public:
void
setSample
(
vector
<
double
>&
temp
);
double
play
();
void
clear
(){
myData
DC
.
clear
();}
void
clear
(){
temp
DC
.
clear
();}
// double play(vector<double>& temp, int length); // tester
// double playOnce();
//
//
double playOnce(double speed);
//
double
playOnce
(
double
speed
);
//
double
play
(
double
speed
);
double
play
(
double
frequency
,
double
start
,
double
end
);
// previously:
// double play(double frequency, double start, double end, double &pos);
// why this no work with bind? :
// non-const lvalue reference to type 'double' cannot bind to a temporary of type 'double'
double
play
(
double
frequency
,
double
start
,
double
end
,
double
&
pos
);
//
//
double
play4
(
double
frequency
,
double
start
,
double
end
);
//
// double play(double frequency, double start, double end, double &pos);
//
// double play(double frequency, double start, double end);
//
// double play4(double frequency, double start, double end);
//
// double bufferPlay(unsigned char &bufferin,long length);
//
// double bufferPlay(unsigned char &bufferin,double speed,long length);
...
...
web/maxiLib.js
View file @
2090a747
This diff is collapsed.
Click to expand it.
web/maximilian_examples_web/12_SamplePlayer.html
View file @
2090a747
...
...
@@ -48,7 +48,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
var
samplePlayer
=
new
Module
.
maxiSample
();
var
mySine
=
new
Module
.
maxiOsc
();
function
setup
(){
// loadSample("test.mp3");
// console.log(samplePlayer.load("Macintosh HD/Users/Dan/Documents/Programming/Emscripten/emsdk_portable/emscripten/tag-1.34.11/tests/maximilian/web/maximilian_examples_web/beat2.wav", 1));
...
...
@@ -58,7 +58,10 @@ loadSample("./beat2.wav", samplePlayer);
}
function
play
(){
output
=
samplePlayer
.
play
();
// output = samplePlayer.play();//just play the file. Looping is default for all play functions.
// output=samplePlayer.play(0.69);//play the file with a speed setting. 1. is normal speed.
output
=
samplePlayer
.
play
(
0.5
,
0
,
44100
);
//linear interpolationplay with a frequency input, start point and end point. Useful for syncing.
// output=samplePlayer.play4(0.5,0,44099);//cubic interpolation play with a frequency input, start point and end point. Useful for syncing.
}
...
...
web/maximilian_examples_web/9_Envelopes.html
View file @
2090a747
...
...
@@ -59,7 +59,7 @@ function setup(){
myEnvelopeData
.
push_back
(
1
);
myEnvelopeData
.
push_back
(
0
);
myEnvelopeData
.
push_back
(
0
);
myEnvelopeData
.
push_back
(
50
0
);
myEnvelopeData
.
push_back
(
1
0
);
myEnvelope
.
amplitude
=
myEnvelopeData
.
get
(
0
);
//initialise the envelope
}
...
...
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