@@ -228,7 +228,7 @@ export class AudioNode extends AudioNodeBase {
228228 }
229229 }
230230
231- private get _stereoOnly ( ) {
231+ private get _stereoOnly ( ) : any {
232232 return this instanceof PannerNode || this instanceof StereoPannerNode || this instanceof ConvolverNode || this instanceof DynamicsCompressorNode ;
233233 }
234234
@@ -405,7 +405,7 @@ export class GainNode extends AudioNode {
405405}
406406
407407export class AudioDestinationNode extends AudioNode {
408- [ native_ ] : org . nativescript . audiocontext . AudioNode ;
408+ [ native_ ] : org . nativescript . audiocontext . GainNode ;
409409 constructor ( context : NativeBaseAudioContext , node : org . nativescript . audiocontext . GainNode ) {
410410 super ( context ) ;
411411 this [ native_ ] = node ;
@@ -894,7 +894,7 @@ export class MediaElementAudioSourceNode extends AudioNode {
894894const QUANTUM = 128 ;
895895
896896function createAudioBuffer ( numberOfChannels : number | { length : number ; numberOfChannels ?: number ; sampleRate : number } , length ?: number , sampleRate ?: number ) {
897- return new AudioBuffer ( typeof numberOfChannels === 'object' ? numberOfChannels : { numberOfChannels, length, sampleRate } ) ;
897+ return new AudioBuffer ( typeof numberOfChannels === 'object' ? numberOfChannels : { numberOfChannels, length : length ?? 0 , sampleRate } ) ;
898898}
899899
900900function decodeAudioData ( ctx : org . nativescript . audiocontext . AudioContextInstance , source : string | ArrayBuffer | ArrayBufferView , successCallback ?: ( buffer : AudioBuffer ) => void , errorCallback ?: ( error : Error ) => void ) : Promise < AudioBuffer > {
@@ -942,7 +942,7 @@ export class OfflineAudioContext extends BaseAudioContext {
942942 super ( ) ;
943943 const options = typeof numberOfChannels === 'object' ? numberOfChannels : { numberOfChannels, length : lengthInFrames , sampleRate } ;
944944 const channels = Math . floor ( options . numberOfChannels ?? 1 ) ;
945- const length = Math . floor ( options . length ) ;
945+ const length = Math . floor ( options ? .length ?? 0 ) ;
946946 const rate = options . sampleRate ?? 48000 ;
947947 checkChannels ( 'OfflineAudioContext' , channels ) ;
948948 if ( ! ( length >= 1 ) ) throw domError ( 'NotSupportedError' , `OfflineAudioContext: length ${ options . length } must be at least 1` ) ;
@@ -1099,7 +1099,6 @@ export class OfflineAudioContext extends BaseAudioContext {
10991099 decodeAudioData ( source : string | ArrayBuffer | ArrayBufferView , successCallback ?: ( buffer : AudioBuffer ) => void , errorCallback ?: ( error : Error ) => void ) : Promise < AudioBuffer > {
11001100 return decodeAudioData ( this . native , source , successCallback , errorCallback ) ;
11011101 }
1102-
11031102}
11041103
11051104let workletScriptPath : string | null = null ;
@@ -1164,10 +1163,14 @@ export class AudioWorklet {
11641163 }
11651164
11661165 addModule ( moduleURL : string | { href : string } , _options ?: { credentials ?: string } ) : Promise < void > {
1167- let host : WorkletHost ;
1166+ let host : WorkletHost | null = null ;
11681167 try {
11691168 if ( this [ context_ ] . state === 'closed' ) throw domError ( 'InvalidStateError' , 'The AudioContext is closed' ) ;
11701169 host = this . _scope ( true ) ;
1170+
1171+ if ( ! host ) {
1172+ throw domError ( 'InvalidStateError' , 'Unable to initialize AudioWorklet' ) ;
1173+ }
11711174 } catch ( e ) {
11721175 return Promise . reject ( e ) ;
11731176 }
@@ -1209,15 +1212,7 @@ export class AudioWorkletNode extends AudioNode {
12091212 } ;
12101213 const defaults = ( Array as any ) . create ( 'double' , descriptors . length ) ;
12111214 descriptors . forEach ( ( d , i ) => ( defaults [ i ] = parameterData ?. [ d . name ] ?? d . defaultValue ) ) ;
1212- const native = AudioContext . getInstance ( ) . createWorklet (
1213- context . native ,
1214- ring as any ,
1215- ints ( inputChannels ) ,
1216- ints ( outputChannelCount ) ,
1217- ints ( [ layout . slotWords , layout . header , layout . inputCounts , layout . inputData , layout . outputCounts , layout . paramLengths , layout . paramData ] ) ,
1218- ints ( layout . outputData ) ,
1219- defaults ,
1220- ) ;
1215+ const native = AudioContext . getInstance ( ) . createWorklet ( context . native , ring as any , ints ( inputChannels ) , ints ( outputChannelCount ) , ints ( [ layout . slotWords , layout . header , layout . inputCounts , layout . inputData , layout . outputCounts , layout . paramLengths , layout . paramData ] ) , ints ( layout . outputData ) , defaults ) ;
12211216 if ( ! native ) throw domError ( 'NotSupportedError' , 'AudioWorkletNode: the audio engine is unavailable' ) ;
12221217 const header = new Uint32Array ( ring , layout . header * 4 , 8 ) ;
12231218 if ( Atomics . load ( header , RING_NATIVE_MARK ) !== 0x574b4c54 ) {
@@ -1426,7 +1421,6 @@ export class AudioContext extends BaseAudioContext {
14261421 return new AudioBufferSourceNode ( this , options ) ;
14271422 }
14281423
1429-
14301424 decodeAudioData ( source : string | ArrayBuffer | ArrayBufferView , successCallback ?: ( buffer : AudioBuffer ) => void , errorCallback ?: ( error : Error ) => void ) : Promise < AudioBuffer > {
14311425 return decodeAudioData ( this . native , source , successCallback , errorCallback ) ;
14321426 }
@@ -1918,8 +1912,8 @@ export class PeriodicWave {
19181912 private imag : Float32Array ;
19191913 private disableNormalization : boolean ;
19201914 constructor ( _context : NativeBaseAudioContext , options : PeriodicWaveOptions = { } ) {
1921- const imagOnly = ! options . real && options . imag ;
1922- this . real = options . real ? Float32Array . from ( options . real ) : new Float32Array ( imagOnly ? options . imag . length : 2 ) ;
1915+ const imagOnly = ! options . real ? options . imag : undefined ;
1916+ this . real = options . real ? Float32Array . from ( options . real ) : new Float32Array ( imagOnly ? imagOnly . length : 2 ) ;
19231917 this . imag = options . imag ? Float32Array . from ( options . imag ) : new Float32Array ( this . real . length ) ;
19241918 if ( this . real . length !== this . imag . length || this . real . length < 2 ) throw domError ( 'IndexSizeError' , `PeriodicWave: real (${ this . real . length } ) and imag (${ this . imag . length } ) must match and be at least 2 long` ) ;
19251919 this . disableNormalization = ! ! options . disableNormalization ;
0 commit comments