@@ -3,7 +3,7 @@ if (!(typeof SepiaFW == "object")){
33}
44( function ( parentModule ) {
55 var WebAudio = parentModule . webAudio || { } ;
6- WebAudio . version = "0.9.6 " ;
6+ WebAudio . version = "0.9.7 " ;
77
88 //Preparations
99 var AudioContext = window . AudioContext || window . webkitAudioContext ;
@@ -710,7 +710,7 @@ if (!(typeof SepiaFW == "object")){
710710
711711 } ) . then ( function ( ) {
712712 //continue with source handler
713- sourceHandler ( micRes . source , { } , micRes . info ) ;
713+ sourceHandler ( micRes . source , micRes . controls || { } , micRes . info ) ;
714714
715715 } ) . catch ( function ( err ) {
716716 if ( typeof err == "string" ) {
@@ -880,17 +880,34 @@ if (!(typeof SepiaFW == "object")){
880880 }
881881
882882 var info = { type : "mic" } ;
883+ var track0 ;
883884 if ( source . mediaStream && source . mediaStream . getAudioTracks ) {
884885 try {
885- var track0 = source . mediaStream . getAudioTracks ( ) [ 0 ] ;
886+ track0 = source . mediaStream . getAudioTracks ( ) [ 0 ] ;
886887 info . label = track0 . label ;
887888 if ( track0 . getSettings ) info . settings = track0 . getSettings ( ) ;
888889 else info . settings = { } ;
889890 info . settings . sampleRate = audioContext . sampleRate ;
890891 } catch ( e ) { } ;
891892 }
893+
894+ var controlEvents = {
895+ //onBeforeStart, onAfterStart, onBeforeStop, onAfterStop, onBeforeRelease, onAfterRelease
896+ onBeforeStart : function ( ) { } ,
897+ onAfterStop : function ( ) { } ,
898+ onAfterRelease : function ( ) {
899+ //release mic resources
900+ if ( track0 && typeof track0 . stop == "function" && track0 . readyState == "live" ) {
901+ track0 . stop ( ) ;
902+ }
903+ }
904+ }
892905
893- return resolve ( { source : source , info : info } ) ;
906+ return resolve ( {
907+ source : source ,
908+ controls : controlEvents ,
909+ info : info
910+ } ) ;
894911
895912 } ) . catch ( function ( err ) {
896913 return reject ( err ) ;
@@ -1078,10 +1095,28 @@ if (!(typeof SepiaFW == "object")){
10781095 type : "scriptProcessor" ,
10791096 typeData : res . info ,
10801097 hasWorkletSupport : false , //does not fit into audio processing thread (normal worklets)
1081- //TODO: ?!?
1082- start : function ( ) { } ,
1083- stop : function ( ) { } ,
1084- release : function ( ) { }
1098+ start : function ( ) {
1099+ //overwrites afterStart
1100+ if ( res . controls . onAfterStart ) res . controls . onAfterStart ( ) ;
1101+ } ,
1102+ stop : function ( ) {
1103+ //overwrites beforeStop
1104+ if ( res . controls . onBeforeStop ) res . controls . onBeforeStop ( ) ;
1105+ } ,
1106+ release : function ( ) {
1107+ //overwrites afterRelease
1108+ if ( res . controls . onAfterRelease ) res . controls . onAfterRelease ( ) ;
1109+ }
1110+ //TODO: implement more?!?
1111+ }
1112+ //remaining controlEvents - beforeStart, afterStart, beforeStop, afterStop, beforeRelease, afterRelease
1113+ if ( res . controls ) {
1114+ if ( res . controls . onBeforeStart ) customSource . beforeStart = res . controls . onBeforeStart ;
1115+ //if (res.controls.onAfterStart) customSource.afterStart = res.controls.onAfterStart;
1116+ //if (res.controls.onBeforeStop) customSource.beforeStop = res.controls.onBeforeStop;
1117+ if ( res . controls . onAfterStop ) customSource . afterStop = res . controls . onAfterStop ;
1118+ if ( res . controls . onBeforeRelease ) customSource . beforeRelease = res . controls . onBeforeRelease ;
1119+ //if (res.controls.onAfterRelease) customSource.afterRelease = res.controls.onAfterRelease;
10851120 }
10861121
10871122 if ( options . onaudioprocess ) {
0 commit comments