Package client.teavm
Klasse ImportedApiSAB
java.lang.Object
client.teavm.ImportedApiSAB
- Alle implementierten Schnittstellen:
IImportedApi
SharedArrayBuffer (SAB)-based implementation of
ImportedApi.
This class enables high-performance, zero-copy data exchange between a TeaVM
Web Worker and the browser main thread. Large buffers for audio, video, and
oscilloscope data are shared via ByteBuffer backed by SABs,
and synchronization is achieved using atomic operations on a small control
buffer.
Buffers
- Audio samples: Written by the worker and read by the main thread.
- Video pixels: Written by the worker and read by the main thread.
- Oscilloscope gauges: Each chip has a map of shared buffers for waveform and envelope data.
Control Buffer
A small Int32Array stores atomic flags for synchronization:
jsControlBuffer[0] → SAMPLE_FLAG_INDEX (audio ready) jsControlBuffer[1] → FRAME_FLAG_INDEX (video ready) jsControlBuffer[2+] → OSC0_FLAG_INDEX + sidNum (oscilloscope ready per SID)
Flag values:
Synchronization Protocol
- Worker writes to a buffer and sets the corresponding flag to
ImportedApiSAB.CONTROL.FLAGS.READY. - Main thread processes the buffer, resets the flag to
ImportedApiSAB.CONTROL.FLAGS.NOT_READY, and notifies the worker. - Worker waits using
Atomics.wait(org.teavm.jso.typedarrays.Int32Array, int, int)until the flag is cleared, then continues.
This approach ensures efficient handshaking for real-time audio/video and oscilloscope data without copying large arrays.
Note: Currently, SABs are used for audio samples, video frames, and oscilloscope gauges only.
-
Verschachtelte Klassen - Übersicht
Verschachtelte Klassen -
Feldübersicht
FelderModifizierer und TypFeldBeschreibungprivate org.teavm.jso.typedarrays.Int32Arrayprivate org.teavm.jso.typedarrays.Uint8Arrayprivate org.teavm.jso.typedarrays.Int8Arrayprivate static final Stringprivate static final int -
Konstruktorübersicht
Konstruktoren -
Methodenübersicht
Modifizierer und TypMethodeBeschreibungvoidinitGaugeBuffer(String type, int chipNum, int pathLength) initPixelBuffer(int maxWidth, int maxHeight) initSampleBuffer(int chunkFrames, int channels) voidprocessOsc(int sidNum, ByteBuffer wav0, String wav0Txt, ByteBuffer wav1, String wav1Txt, ByteBuffer wav2, String wav2Txt, ByteBuffer env0, String env0Txt, ByteBuffer env1, String env1Txt, ByteBuffer env2, String env2Txt, ByteBuffer fre0, String frq0Txt, ByteBuffer frq1, String frq1Txt, ByteBuffer frq2, String frq2Txt, ByteBuffer vol, String volTxt, ByteBuffer res, String resTxt, ByteBuffer fil, String filTxt) voidprocessPixels(ByteBuffer pixelBuffer) voidprocessPrinter(IPaper.Outputs output) static voidvoidprocessSamples(ByteBuffer sampleBuffer, float[] lookupTable) voidprocessSidWrite(long absTime, int relTime, int addr, int value) static voidprocessSidWriteJS(double at, int ti, int ad, int va) voidprocessTimerEnd(double end) static voidprocessTimerEndJS(double ed) voidwhatsSid(byte[] array) static voidwhatsSidJS(byte[] ar, int le)
-
Felddetails
-
MODULE_NAME
- Siehe auch:
-
WAIT_TIMEOUT
private static final int WAIT_TIMEOUT- Siehe auch:
-
jsControlBuffer
private org.teavm.jso.typedarrays.Int32Array jsControlBuffer -
jsSampleBuffer
private org.teavm.jso.typedarrays.Int8Array jsSampleBuffer -
jsPixelBuffer
private org.teavm.jso.typedarrays.Uint8Array jsPixelBuffer -
jsGaugeBuffersByChipNum
-
-
Konstruktordetails
-
ImportedApiSAB
public ImportedApiSAB()
-
-
Methodendetails
-
initControlBuffer
public void initControlBuffer()- Angegeben von:
initControlBufferin SchnittstelleIImportedApi
-
initSampleBuffer
- Angegeben von:
initSampleBufferin SchnittstelleIImportedApi
-
initPixelBuffer
- Angegeben von:
initPixelBufferin SchnittstelleIImportedApi
-
initGaugeBuffer
- Angegeben von:
initGaugeBufferin SchnittstelleIImportedApi
-
processSamples
- Angegeben von:
processSamplesin SchnittstelleIImportedApi
-
processPixels
- Angegeben von:
processPixelsin SchnittstelleIImportedApi
-
processOsc
public void processOsc(int sidNum, ByteBuffer wav0, String wav0Txt, ByteBuffer wav1, String wav1Txt, ByteBuffer wav2, String wav2Txt, ByteBuffer env0, String env0Txt, ByteBuffer env1, String env1Txt, ByteBuffer env2, String env2Txt, ByteBuffer fre0, String frq0Txt, ByteBuffer frq1, String frq1Txt, ByteBuffer frq2, String frq2Txt, ByteBuffer vol, String volTxt, ByteBuffer res, String resTxt, ByteBuffer fil, String filTxt) - Angegeben von:
processOscin SchnittstelleIImportedApi
-
processSidWrite
public void processSidWrite(long absTime, int relTime, int addr, int value) - Angegeben von:
processSidWritein SchnittstelleIImportedApi
-
processTimerEnd
public void processTimerEnd(double end) - Angegeben von:
processTimerEndin SchnittstelleIImportedApi
-
processPrinter
- Angegeben von:
processPrinterin SchnittstelleIImportedApi
-
whatsSid
public void whatsSid(byte[] array) - Angegeben von:
whatsSidin SchnittstelleIImportedApi
-
processSidWriteJS
public static void processSidWriteJS(double at, int ti, int ad, int va) -
processTimerEndJS
public static void processTimerEndJS(double ed) -
processPrinterJS
-
whatsSidJS
public static void whatsSidJS(byte[] ar, int le)
-