Package client.teavm
Klasse ImportedApiSAB
java.lang.Object
client.teavm.ImportedApiSAB
- Alle implementierten Schnittstellen:
IImportedApi,IImportEventParameters
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 frame: 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) jsControlBuffer[5] → WHATSSID_FLAG_INDEX (WAV ready)
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.
-
Verschachtelte Klassen - Übersicht
Verschachtelte KlassenModifizierer und TypKlasseBeschreibungstatic final classControl buffer contents: One Integer per buffer: sampleBuffer + frameBuffer + MAX_OSCILLOSCOPE_SIDS * gaugeBuffer + whatssidBuffer -
Feldübersicht
FelderModifizierer und TypFeldBeschreibungprivate static final Stringprivate static final Stringprivate static final intVon Schnittstelle geerbte Felder client.teavm.common.parameter.event.IImportEventParameters
ABS_TIME, ADDR, CHIP_NUM, CONTROL_BUFFER, END, ENV_0, ENV_0_TXT, ENV_1, ENV_1_TXT, ENV_2, ENV_2_TXT, EVENT_FRAME, EVENT_FRAME_SAB, EVENT_INIT_CONTROL_BUFFER_SAB, EVENT_INIT_FRAME_BUFFER_SAB, EVENT_INIT_GAUGE_BUFFER_SAB, EVENT_INIT_SAMPLE_BUFFER_SAB, EVENT_INIT_WHATSSID_SAB, EVENT_OSC, EVENT_OSC_SAB, EVENT_PRINTER, EVENT_SAMPLES, EVENT_SAMPLES_SAB, EVENT_SID_WRITE, EVENT_TIMER_END, EVENT_WHATSSID, EVENT_WHATSSID_SAB, FIL, FIL_TXT, FRAME_BUFFER, FRQ_0, FRQ_0_TXT, FRQ_1, FRQ_1_TXT, FRQ_2, FRQ_2_TXT, GAUGE_BUFFER, IMAGE, LEFT, LENGTH, OUTPUT, PIXELS, REL_TIME, RES, RES_TXT, RIGHT, SAMPLE_BUFFER, SID_NUM, TYPE, VALUE, VOL, VOL_TXT, WAV, WAV_0, WAV_0_TXT, WAV_1, WAV_1_TXT, WAV_2, WAV_2_TXT, WHATSSID_BUFFER -
Konstruktorübersicht
Konstruktoren -
Methodenübersicht
Modifizierer und TypMethodeBeschreibungvoidinitFrameBuffer(int maxWidth, int maxHeight) initGaugeBuffer(String type, int chipNum, int pathLength) initSampleBuffer(int chunkFrames, int channels) initWhatsSidBuffer(int wavLength) voidprocessFrame(long absTime, ByteBuffer frameBuffer) voidprocessOsc(int sidNum, long absTime, 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 frq0, String frq0Txt, ByteBuffer frq1, String frq1Txt, ByteBuffer frq2, String frq2Txt, ByteBuffer vol, String volTxt, ByteBuffer res, String resTxt, ByteBuffer fil, String filTxt) voidprocessPrinter(IPaper.Outputs output) voidprocessSamples(long absTime, ByteBuffer sampleBuffer, float[] lookupTable) voidprocessSidWrite(int sidNum, long absTime, int relTime, int addr, int value) voidprocessTimerEnd(double end) voidwhatsSid(ByteBuffer whatsSidBuffer)
-
Felddetails
-
EVENT_TYPE
- Siehe auch:
-
EVENT_DATA
- Siehe auch:
-
WAIT_TIMEOUT
private static final int WAIT_TIMEOUT- Siehe auch:
-
-
Konstruktordetails
-
ImportedApiSAB
public ImportedApiSAB()
-
-
Methodendetails
-
initControlBuffer
public void initControlBuffer()- Angegeben von:
initControlBufferin SchnittstelleIImportedApi
-
initSampleBuffer
- Angegeben von:
initSampleBufferin SchnittstelleIImportedApi
-
initFrameBuffer
- Angegeben von:
initFrameBufferin SchnittstelleIImportedApi
-
initGaugeBuffer
- Angegeben von:
initGaugeBufferin SchnittstelleIImportedApi
-
initWhatsSidBuffer
- Angegeben von:
initWhatsSidBufferin SchnittstelleIImportedApi
-
processSamples
- Angegeben von:
processSamplesin SchnittstelleIImportedApi
-
processFrame
- Angegeben von:
processFramein SchnittstelleIImportedApi
-
processOsc
public void processOsc(int sidNum, long absTime, 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 frq0, 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
-
whatsSid
- Angegeben von:
whatsSidin SchnittstelleIImportedApi
-
processSidWrite
public void processSidWrite(int sidNum, 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
-