Passing an SB pointer to a JS function
Posted: Tue Mar 07, 2017 12:26 pm
Hello,
I would like to load an encrypted sound, then later an entire databank into a WebAudio buffer, via the 'context.decodeAudioData' function.
At the moment, I'm using SB's ReadFile() and ReadData() functions to load a file, then decrypt the loaded buffer with the AES cypher. This works.
My problem is that the decodeAudioData() function expects an ArrayBuffer, which should be an Uint8Array type, but this is not true for the SB pointer. Is there a way to convert it to the appropriate Uint8Array format? Here's a simplified version of what I'm using, without decryption.
I would like to load an encrypted sound, then later an entire databank into a WebAudio buffer, via the 'context.decodeAudioData' function.
At the moment, I'm using SB's ReadFile() and ReadData() functions to load a file, then decrypt the loaded buffer with the AES cypher. This works.
My problem is that the decodeAudioData() function expects an ArrayBuffer, which should be an Uint8Array type, but this is not true for the SB pointer. Is there a way to convert it to the appropriate Uint8Array format? Here's a simplified version of what I'm using, without decryption.
Code: Select all
Procedure createSoundWithBuffer(buffer)
EnableJS
var sound;
v_sonoobject.context.decodeAudioData(v_buffer, function(buff) {
sound = v_sonoobject.createSound(buff);
sound.play();
});
DisableJS
EndProcedure
Procedure fread(Status, Filename$, File, SizeRead)
Select Status
Case #PB_Status_Loaded
*sbuf=AllocateMemory(SizeRead,#PB_Memory_NoClear)
ReadData(file,*sbuf,0,SizeRead)
!f_createsoundwithbuffer(p_sbuf);
Case #PB_Status_Progress
; File loading in progress, use FileProgress() get the current progress
Case #PB_Status_Error
; File loading has failed
EndSelect
EndProcedure
ReadFile(0,"file.mp3", @fread())