@@ -3,7 +3,7 @@ if (!(typeof SepiaFW == "object")){
33}
44( function ( parentModule ) {
55 var WebAudio = parentModule . webAudio || { } ;
6- WebAudio . version = "0.9.8 " ;
6+ WebAudio . version = "0.9.9 " ;
77
88 //Preparations
99 var AudioContext = window . AudioContext || window . webkitAudioContext ;
@@ -1183,6 +1183,29 @@ if (!(typeof SepiaFW == "object")){
11831183
11841184 //File AudioBufferSourceNode with start/stop/release
11851185 WebAudio . createFileSource = function ( fileUrl , options ) {
1186+ if ( ! options ) options = { } ; //e.g.: 'targetSampleRate'
1187+ return new Promise ( function ( resolve , reject ) {
1188+ try {
1189+ function errorCallback ( err ) {
1190+ reject ( err ) ;
1191+ }
1192+ function successCallback ( arrayBuffer ) {
1193+ WebAudio . createAudioBufferSource ( arrayBuffer , options ) . then ( function ( res ) {
1194+ res . typeData = {
1195+ fileUrl : fileUrl
1196+ }
1197+ resolve ( res ) ;
1198+ } ) . catch ( errorCallback ) ;
1199+ }
1200+ WebAudio . readFileAsBuffer ( fileUrl , successCallback , errorCallback ) ;
1201+
1202+ } catch ( err ) {
1203+ reject ( err ) ;
1204+ }
1205+ } ) ;
1206+ }
1207+ //Direct AudioBufferSourceNode with start/stop/release
1208+ WebAudio . createAudioBufferSource = function ( audioBuffer , options ) {
11861209 if ( ! options ) options = { } ; //e.g.: 'targetSampleRate'
11871210 return new Promise ( function ( resolve , reject ) {
11881211 ( async function ( ) {
@@ -1192,39 +1215,38 @@ if (!(typeof SepiaFW == "object")){
11921215 try { await audioContext . resume ( ) ; } catch ( error ) { } ; //TODO: prevent quirky stuff on e.g. iOS
11931216 await audioContext . suspend ( ) ;
11941217 var audioBufferSourceNode = audioContext . createBufferSource ( ) ;
1195-
1196- function successCallback ( arrayBuffer ) {
1197- audioContext . decodeAudioData ( arrayBuffer , function ( buffer ) {
1198- audioBufferSourceNode . buffer = buffer ;
1199- //audioBufferSourceNode.connect(audioContext.destination);
1200- audioBufferSourceNode . loop = true ;
1201- return resolve ( {
1202- node : audioBufferSourceNode ,
1203- type : "fileAudioBuffer" ,
1204- typeData : {
1205- fileUrl : fileUrl
1206- } ,
1207- start : function ( ) { audioBufferSourceNode . start ( ) ; } ,
1208- stop : function ( ) { audioBufferSourceNode . stop ( ) ; } ,
1209- release : function ( ) { } //TODO: ?!?
1210- } ) ;
1211-
1212- } , function ( err ) {
1213- return reject ( err ) ;
1218+ //decode to get buffer
1219+ audioContext . decodeAudioData ( audioBuffer , function ( buffer ) {
1220+ audioBufferSourceNode . buffer = buffer ;
1221+ audioBufferSourceNode . loop = true ;
1222+ return resolve ( {
1223+ node : audioBufferSourceNode ,
1224+ type : "fileAudioBuffer" ,
1225+ typeData : { } ,
1226+ start : function ( ) { audioBufferSourceNode . start ( ) ; } ,
1227+ stop : function ( ) { audioBufferSourceNode . stop ( ) ; } ,
1228+ release : function ( ) { } //TODO: ?!?
12141229 } ) ;
1215- }
1216- function errorCallback ( err ) {
1230+ } , function ( err ) {
12171231 return reject ( err ) ;
1218- }
1219- WebAudio . readFileAsBuffer ( fileUrl , successCallback , errorCallback ) ;
1220-
1232+ } ) ;
12211233 } catch ( err ) {
12221234 return reject ( err ) ;
12231235 }
12241236 } ) ( ) ;
12251237 } ) ;
12261238 }
12271239
1240+ //Create player for source nodes (e.g. audio URL or buffer nodes)
1241+ WebAudio . createAudioPlayer = function ( source , options , audioModules , onInit , onInitError ) {
1242+ if ( ! options ) options = { } ;
1243+ options . modules = audioModules || [ ] ;
1244+ options . customSource = source ;
1245+ if ( options . startSuspended == undefined ) options . startSuspended = true ;
1246+ var webAudioProcessor = new WebAudio . Processor ( options , onInit , onInitError ) ;
1247+ return webAudioProcessor ;
1248+ }
1249+
12281250 //Encode buffer to wave
12291251 WebAudio . encodeWaveBuffer = function ( buffer , sampleRate , channels , isFloat32 , successCallback , errorCallback ) {
12301252 var moduleFolder = WebAudio . defaultProcessorOptions . moduleFolder . replace ( / \/ $ / , "" ) + "/" ;
0 commit comments