diff --git a/addons/ofxEmscripten/libs/html5audio/include/html5audio.h b/addons/ofxEmscripten/libs/html5audio/include/html5audio.h
index 48831961100..9dd55eaa608 100644
--- a/addons/ofxEmscripten/libs/html5audio/include/html5audio.h
+++ b/addons/ofxEmscripten/libs/html5audio/include/html5audio.h
@@ -28,7 +28,7 @@ extern "C"{
extern void html5audio_sound_set_pan(int sound, double pan);
extern void html5audio_sound_free(int sound);
- extern void html5audio_stream_create(int bufferSize, int inputChannels, int outputChannels, float * inbuffer, float * outbuffer, html5audio_stream_callback callback, void * userData);
+ extern void html5audio_stream_create(int audioWorkletNode, int numInputChannels);
extern void html5audio_stream_free();
extern bool html5audio_sound_is_loaded(int sound);
}
diff --git a/addons/ofxEmscripten/libs/html5audio/lib/emscripten/library_audioDeviceSelect.js b/addons/ofxEmscripten/libs/html5audio/lib/emscripten/library_audioDeviceSelect.js
new file mode 100644
index 00000000000..08bfd9147a0
--- /dev/null
+++ b/addons/ofxEmscripten/libs/html5audio/lib/emscripten/library_audioDeviceSelect.js
@@ -0,0 +1,48 @@
+var mediaElement = null;
+
+function getAudioDevices(){
+ var audioInDevices = "";
+ var audioOutDevices = "";
+ if(!navigator.mediaDevices.enumerateDevices){
+ console.log("enumerateDevices() not supported.");
+ }else{
+ navigator.mediaDevices.getUserMedia({audio: true, video: false}).then(s => {
+ navigator.mediaDevices.enumerateDevices().then((devices) => {
+ devices.forEach((device) => {
+ if(device.kind == "audioinput"){
+ audioInDevices = audioInDevices.concat(",", `${device.deviceId}`,",", `${device.label}`);
+ }
+ if(device.kind == "audiooutput"){
+ audioOutDevices = audioOutDevices.concat(",", `${device.groupId}`,",", `${device.label}`);
+ }
+ });
+ Module.loadAudioInDevices(audioInDevices);
+ Module.loadAudioOutDevices(audioOutDevices);
+ })
+ .catch((err) => {
+ console.error(`${err.name}: ${err.message}`);
+ });
+ });
+ }
+}
+
+function selectAudioIn(file){
+ if (navigator.getUserMedia){
+ navigator.getUserMedia(
+ { audio: { deviceId: { exact: file } } },
+ function (audioIn){
+ if(mediaElement){
+ mediaElement.disconnect();
+ }
+ mediaElement = AUDIO.context.createMediaStreamSource(audioIn);
+ mediaElement.connect(AUDIO.stream);
+ },
+ function (error){
+ console.log("error creating audio in",error);
+ });
+ }
+}
+
+function selectAudioOut(file){
+ //AUDIO.context.setSinkId(file);
+}
diff --git a/addons/ofxEmscripten/libs/html5audio/lib/emscripten/library_html5audio.js b/addons/ofxEmscripten/libs/html5audio/lib/emscripten/library_html5audio.js
index 7382243b8c3..18f252a9e6c 100644
--- a/addons/ofxEmscripten/libs/html5audio/lib/emscripten/library_html5audio.js
+++ b/addons/ofxEmscripten/libs/html5audio/lib/emscripten/library_html5audio.js
@@ -24,11 +24,13 @@ var LibraryHTML5Audio = {
}
},
+ html5audio_context_create__deps: ['$emscriptenRegisterAudioObject'],
html5audio_context_create: function () {
try {
// Fix up for prefixing
window.AudioContext = window.AudioContext || window.webkitAudioContext;
- var context = new AudioContext({});
+ var context = new AudioContext({ sampleRate: 44100 });
+ var id = emscriptenRegisterAudioObject(context);
// Fix issue with chrome autoplay policy
document.addEventListener('mousedown', function cb(event) {
@@ -44,7 +46,7 @@ var LibraryHTML5Audio = {
fft.maxDecibels = 0;
fft.minDecibels = -100;
AUDIO.fft = fft;
- return 0;
+ return id;
} catch (e) {
console.log('Web Audio API is not supported in this browser', e);
return -1;
@@ -62,7 +64,11 @@ var LibraryHTML5Audio = {
html5audio_context_spectrum: function (bands, spectrum) {
AUDIO.fft.fftSize = bands * 2;
var spectrumArray = Module.HEAPF32.subarray(spectrum >> 2, (spectrum >> 2) + bands);
- AUDIO.fft.getFloatFrequencyData(spectrumArray);
+ var spectrumArrayCopy = new Float32Array (spectrumArray);
+ AUDIO.fft.getFloatFrequencyData(spectrumArrayCopy);
+ for (let i = 0; i < spectrumArrayCopy.length; i++) {
+ spectrumArray[i] = spectrumArrayCopy[i];
+ }
},
html5audio_context_samplerate: function () {
@@ -201,48 +207,21 @@ var LibraryHTML5Audio = {
}
},
- html5audio_stream_create: function(bufferSize, inputChannels, outputChannels, inbuffer, outbuffer, callback, userData) {
- var stream = AUDIO.context.createScriptProcessor(bufferSize, inputChannels, outputChannels);
- var inbufferArray = Module.HEAPF32.subarray(inbuffer >> 2, (inbuffer >> 2) + bufferSize * inputChannels);
- var outbufferArray = Module.HEAPF32.subarray(outbuffer >> 2, (outbuffer >> 2) + bufferSize * outputChannels);
-
- stream.onaudioprocess = function(event) {
- var i, j, c;
- if (inputChannels > 0) {
- for (c = 0; c < inputChannels; ++c) {
- var inChannel = event.inputBuffer.getChannelData(c);
- for (i = 0, j = c; i < bufferSize; ++i, j += inputChannels) {
- inbufferArray[j] = inChannel[i];
- }
- }
- }
-
- {{{ makeDynCall('viiii', 'callback') }}}(bufferSize, inputChannels, outputChannels, userData);
-
- if (outputChannels > 0) {
- for (c = 0; c < outputChannels; ++c) {
- var outChannel = event.outputBuffer.getChannelData(c);
- for (i = 0, j = c; i < bufferSize; ++i, j += outputChannels) {
- outChannel[i] = outbufferArray[j];
- }
- }
- }
- };
-
- if (inputChannels > 0) {
- navigator.mediaDevices.getUserMedia({ audio: true })
- .then(function (audioIn) {
- var mediaElement = AUDIO.context.createMediaStreamSource(audioIn);
- mediaElement.connect(stream);
- AUDIO.mediaElement = mediaElement;
- })
- .catch(function (error) {
- console.log("Error creating audio in", error);
- });
- }
-
- stream.connect(AUDIO.fft);
- },
+ html5audio_stream_create__deps: ['$emscriptenGetAudioObject'],
+ html5audio_stream_create: function(audioWorkletNode, numInputChannels){
+ var audioWorkletNode = emscriptenGetAudioObject(audioWorkletNode);
+ if(numInputChannels > 0){
+ navigator.mediaDevices.getUserMedia({ audio: true })
+ .then(function (audioIn) {
+ var mediaElement = AUDIO.context.createMediaStreamSource(audioIn);
+ mediaElement.connect(audioWorkletNode);
+ })
+ .catch(function (error) {
+ console.log("Error creating audio in", error);
+ });
+ }
+ audioWorkletNode.connect(AUDIO.fft);
+ },
html5audio_stream_free: function () {
diff --git a/addons/ofxEmscripten/libs/html5video/lib/emscripten/fix-webm-duration.js b/addons/ofxEmscripten/libs/html5video/lib/emscripten/fix-webm-duration.js
new file mode 100644
index 00000000000..0b378c4fdb6
--- /dev/null
+++ b/addons/ofxEmscripten/libs/html5video/lib/emscripten/fix-webm-duration.js
@@ -0,0 +1,513 @@
+(function (name, definition) {
+ if (typeof define === 'function' && define.amd) { // RequireJS / AMD
+ define(definition);
+ } else if (typeof module !== 'undefined' && module.exports) { // CommonJS / Node.js
+ module.exports = definition();
+ } else { // Direct include
+ window.ysFixWebmDuration = definition();
+ }
+})('fix-webm-duration', function () {
+ /*
+ * This is the list of possible WEBM file sections by their IDs.
+ * Possible types: Container, Binary, Uint, Int, String, Float, Date
+ */
+ var sections = {
+ 0xa45dfa3: { name: 'EBML', type: 'Container' },
+ 0x286: { name: 'EBMLVersion', type: 'Uint' },
+ 0x2f7: { name: 'EBMLReadVersion', type: 'Uint' },
+ 0x2f2: { name: 'EBMLMaxIDLength', type: 'Uint' },
+ 0x2f3: { name: 'EBMLMaxSizeLength', type: 'Uint' },
+ 0x282: { name: 'DocType', type: 'String' },
+ 0x287: { name: 'DocTypeVersion', type: 'Uint' },
+ 0x285: { name: 'DocTypeReadVersion', type: 'Uint' },
+ 0x6c: { name: 'Void', type: 'Binary' },
+ 0x3f: { name: 'CRC-32', type: 'Binary' },
+ 0xb538667: { name: 'SignatureSlot', type: 'Container' },
+ 0x3e8a: { name: 'SignatureAlgo', type: 'Uint' },
+ 0x3e9a: { name: 'SignatureHash', type: 'Uint' },
+ 0x3ea5: { name: 'SignaturePublicKey', type: 'Binary' },
+ 0x3eb5: { name: 'Signature', type: 'Binary' },
+ 0x3e5b: { name: 'SignatureElements', type: 'Container' },
+ 0x3e7b: { name: 'SignatureElementList', type: 'Container' },
+ 0x2532: { name: 'SignedElement', type: 'Binary' },
+ 0x8538067: { name: 'Segment', type: 'Container' },
+ 0x14d9b74: { name: 'SeekHead', type: 'Container' },
+ 0xdbb: { name: 'Seek', type: 'Container' },
+ 0x13ab: { name: 'SeekID', type: 'Binary' },
+ 0x13ac: { name: 'SeekPosition', type: 'Uint' },
+ 0x549a966: { name: 'Info', type: 'Container' },
+ 0x33a4: { name: 'SegmentUID', type: 'Binary' },
+ 0x3384: { name: 'SegmentFilename', type: 'String' },
+ 0x1cb923: { name: 'PrevUID', type: 'Binary' },
+ 0x1c83ab: { name: 'PrevFilename', type: 'String' },
+ 0x1eb923: { name: 'NextUID', type: 'Binary' },
+ 0x1e83bb: { name: 'NextFilename', type: 'String' },
+ 0x444: { name: 'SegmentFamily', type: 'Binary' },
+ 0x2924: { name: 'ChapterTranslate', type: 'Container' },
+ 0x29fc: { name: 'ChapterTranslateEditionUID', type: 'Uint' },
+ 0x29bf: { name: 'ChapterTranslateCodec', type: 'Uint' },
+ 0x29a5: { name: 'ChapterTranslateID', type: 'Binary' },
+ 0xad7b1: { name: 'TimecodeScale', type: 'Uint' },
+ 0x489: { name: 'Duration', type: 'Float' },
+ 0x461: { name: 'DateUTC', type: 'Date' },
+ 0x3ba9: { name: 'Title', type: 'String' },
+ 0xd80: { name: 'MuxingApp', type: 'String' },
+ 0x1741: { name: 'WritingApp', type: 'String' },
+ // 0xf43b675: { name: 'Cluster', type: 'Container' },
+ 0x67: { name: 'Timecode', type: 'Uint' },
+ 0x1854: { name: 'SilentTracks', type: 'Container' },
+ 0x18d7: { name: 'SilentTrackNumber', type: 'Uint' },
+ 0x27: { name: 'Position', type: 'Uint' },
+ 0x2b: { name: 'PrevSize', type: 'Uint' },
+ 0x23: { name: 'SimpleBlock', type: 'Binary' },
+ 0x20: { name: 'BlockGroup', type: 'Container' },
+ 0x21: { name: 'Block', type: 'Binary' },
+ 0x22: { name: 'BlockVirtual', type: 'Binary' },
+ 0x35a1: { name: 'BlockAdditions', type: 'Container' },
+ 0x26: { name: 'BlockMore', type: 'Container' },
+ 0x6e: { name: 'BlockAddID', type: 'Uint' },
+ 0x25: { name: 'BlockAdditional', type: 'Binary' },
+ 0x1b: { name: 'BlockDuration', type: 'Uint' },
+ 0x7a: { name: 'ReferencePriority', type: 'Uint' },
+ 0x7b: { name: 'ReferenceBlock', type: 'Int' },
+ 0x7d: { name: 'ReferenceVirtual', type: 'Int' },
+ 0x24: { name: 'CodecState', type: 'Binary' },
+ 0x35a2: { name: 'DiscardPadding', type: 'Int' },
+ 0xe: { name: 'Slices', type: 'Container' },
+ 0x68: { name: 'TimeSlice', type: 'Container' },
+ 0x4c: { name: 'LaceNumber', type: 'Uint' },
+ 0x4d: { name: 'FrameNumber', type: 'Uint' },
+ 0x4b: { name: 'BlockAdditionID', type: 'Uint' },
+ 0x4e: { name: 'Delay', type: 'Uint' },
+ 0x4f: { name: 'SliceDuration', type: 'Uint' },
+ 0x48: { name: 'ReferenceFrame', type: 'Container' },
+ 0x49: { name: 'ReferenceOffset', type: 'Uint' },
+ 0x4a: { name: 'ReferenceTimeCode', type: 'Uint' },
+ 0x2f: { name: 'EncryptedBlock', type: 'Binary' },
+ 0x654ae6b: { name: 'Tracks', type: 'Container' },
+ 0x2e: { name: 'TrackEntry', type: 'Container' },
+ 0x57: { name: 'TrackNumber', type: 'Uint' },
+ 0x33c5: { name: 'TrackUID', type: 'Uint' },
+ 0x3: { name: 'TrackType', type: 'Uint' },
+ 0x39: { name: 'FlagEnabled', type: 'Uint' },
+ 0x8: { name: 'FlagDefault', type: 'Uint' },
+ 0x15aa: { name: 'FlagForced', type: 'Uint' },
+ 0x1c: { name: 'FlagLacing', type: 'Uint' },
+ 0x2de7: { name: 'MinCache', type: 'Uint' },
+ 0x2df8: { name: 'MaxCache', type: 'Uint' },
+ 0x3e383: { name: 'DefaultDuration', type: 'Uint' },
+ 0x34e7a: { name: 'DefaultDecodedFieldDuration', type: 'Uint' },
+ 0x3314f: { name: 'TrackTimecodeScale', type: 'Float' },
+ 0x137f: { name: 'TrackOffset', type: 'Int' },
+ 0x15ee: { name: 'MaxBlockAdditionID', type: 'Uint' },
+ 0x136e: { name: 'Name', type: 'String' },
+ 0x2b59c: { name: 'Language', type: 'String' },
+ 0x6: { name: 'CodecID', type: 'String' },
+ 0x23a2: { name: 'CodecPrivate', type: 'Binary' },
+ 0x58688: { name: 'CodecName', type: 'String' },
+ 0x3446: { name: 'AttachmentLink', type: 'Uint' },
+ 0x1a9697: { name: 'CodecSettings', type: 'String' },
+ 0x1b4040: { name: 'CodecInfoURL', type: 'String' },
+ 0x6b240: { name: 'CodecDownloadURL', type: 'String' },
+ 0x2a: { name: 'CodecDecodeAll', type: 'Uint' },
+ 0x2fab: { name: 'TrackOverlay', type: 'Uint' },
+ 0x16aa: { name: 'CodecDelay', type: 'Uint' },
+ 0x16bb: { name: 'SeekPreRoll', type: 'Uint' },
+ 0x2624: { name: 'TrackTranslate', type: 'Container' },
+ 0x26fc: { name: 'TrackTranslateEditionUID', type: 'Uint' },
+ 0x26bf: { name: 'TrackTranslateCodec', type: 'Uint' },
+ 0x26a5: { name: 'TrackTranslateTrackID', type: 'Binary' },
+ 0x60: { name: 'Video', type: 'Container' },
+ 0x1a: { name: 'FlagInterlaced', type: 'Uint' },
+ 0x13b8: { name: 'StereoMode', type: 'Uint' },
+ 0x13c0: { name: 'AlphaMode', type: 'Uint' },
+ 0x13b9: { name: 'OldStereoMode', type: 'Uint' },
+ 0x30: { name: 'PixelWidth', type: 'Uint' },
+ 0x3a: { name: 'PixelHeight', type: 'Uint' },
+ 0x14aa: { name: 'PixelCropBottom', type: 'Uint' },
+ 0x14bb: { name: 'PixelCropTop', type: 'Uint' },
+ 0x14cc: { name: 'PixelCropLeft', type: 'Uint' },
+ 0x14dd: { name: 'PixelCropRight', type: 'Uint' },
+ 0x14b0: { name: 'DisplayWidth', type: 'Uint' },
+ 0x14ba: { name: 'DisplayHeight', type: 'Uint' },
+ 0x14b2: { name: 'DisplayUnit', type: 'Uint' },
+ 0x14b3: { name: 'AspectRatioType', type: 'Uint' },
+ 0xeb524: { name: 'ColourSpace', type: 'Binary' },
+ 0xfb523: { name: 'GammaValue', type: 'Float' },
+ 0x383e3: { name: 'FrameRate', type: 'Float' },
+ 0x61: { name: 'Audio', type: 'Container' },
+ 0x35: { name: 'SamplingFrequency', type: 'Float' },
+ 0x38b5: { name: 'OutputSamplingFrequency', type: 'Float' },
+ 0x1f: { name: 'Channels', type: 'Uint' },
+ 0x3d7b: { name: 'ChannelPositions', type: 'Binary' },
+ 0x2264: { name: 'BitDepth', type: 'Uint' },
+ 0x62: { name: 'TrackOperation', type: 'Container' },
+ 0x63: { name: 'TrackCombinePlanes', type: 'Container' },
+ 0x64: { name: 'TrackPlane', type: 'Container' },
+ 0x65: { name: 'TrackPlaneUID', type: 'Uint' },
+ 0x66: { name: 'TrackPlaneType', type: 'Uint' },
+ 0x69: { name: 'TrackJoinBlocks', type: 'Container' },
+ 0x6d: { name: 'TrackJoinUID', type: 'Uint' },
+ 0x40: { name: 'TrickTrackUID', type: 'Uint' },
+ 0x41: { name: 'TrickTrackSegmentUID', type: 'Binary' },
+ 0x46: { name: 'TrickTrackFlag', type: 'Uint' },
+ 0x47: { name: 'TrickMasterTrackUID', type: 'Uint' },
+ 0x44: { name: 'TrickMasterTrackSegmentUID', type: 'Binary' },
+ 0x2d80: { name: 'ContentEncodings', type: 'Container' },
+ 0x2240: { name: 'ContentEncoding', type: 'Container' },
+ 0x1031: { name: 'ContentEncodingOrder', type: 'Uint' },
+ 0x1032: { name: 'ContentEncodingScope', type: 'Uint' },
+ 0x1033: { name: 'ContentEncodingType', type: 'Uint' },
+ 0x1034: { name: 'ContentCompression', type: 'Container' },
+ 0x254: { name: 'ContentCompAlgo', type: 'Uint' },
+ 0x255: { name: 'ContentCompSettings', type: 'Binary' },
+ 0x1035: { name: 'ContentEncryption', type: 'Container' },
+ 0x7e1: { name: 'ContentEncAlgo', type: 'Uint' },
+ 0x7e2: { name: 'ContentEncKeyID', type: 'Binary' },
+ 0x7e3: { name: 'ContentSignature', type: 'Binary' },
+ 0x7e4: { name: 'ContentSigKeyID', type: 'Binary' },
+ 0x7e5: { name: 'ContentSigAlgo', type: 'Uint' },
+ 0x7e6: { name: 'ContentSigHashAlgo', type: 'Uint' },
+ 0xc53bb6b: { name: 'Cues', type: 'Container' },
+ 0x3b: { name: 'CuePoint', type: 'Container' },
+ 0x33: { name: 'CueTime', type: 'Uint' },
+ 0x37: { name: 'CueTrackPositions', type: 'Container' },
+ 0x77: { name: 'CueTrack', type: 'Uint' },
+ 0x71: { name: 'CueClusterPosition', type: 'Uint' },
+ 0x70: { name: 'CueRelativePosition', type: 'Uint' },
+ 0x32: { name: 'CueDuration', type: 'Uint' },
+ 0x1378: { name: 'CueBlockNumber', type: 'Uint' },
+ 0x6a: { name: 'CueCodecState', type: 'Uint' },
+ 0x5b: { name: 'CueReference', type: 'Container' },
+ 0x16: { name: 'CueRefTime', type: 'Uint' },
+ 0x17: { name: 'CueRefCluster', type: 'Uint' },
+ 0x135f: { name: 'CueRefNumber', type: 'Uint' },
+ 0x6b: { name: 'CueRefCodecState', type: 'Uint' },
+ 0x941a469: { name: 'Attachments', type: 'Container' },
+ 0x21a7: { name: 'AttachedFile', type: 'Container' },
+ 0x67e: { name: 'FileDescription', type: 'String' },
+ 0x66e: { name: 'FileName', type: 'String' },
+ 0x660: { name: 'FileMimeType', type: 'String' },
+ 0x65c: { name: 'FileData', type: 'Binary' },
+ 0x6ae: { name: 'FileUID', type: 'Uint' },
+ 0x675: { name: 'FileReferral', type: 'Binary' },
+ 0x661: { name: 'FileUsedStartTime', type: 'Uint' },
+ 0x662: { name: 'FileUsedEndTime', type: 'Uint' },
+ 0x43a770: { name: 'Chapters', type: 'Container' },
+ 0x5b9: { name: 'EditionEntry', type: 'Container' },
+ 0x5bc: { name: 'EditionUID', type: 'Uint' },
+ 0x5bd: { name: 'EditionFlagHidden', type: 'Uint' },
+ 0x5db: { name: 'EditionFlagDefault', type: 'Uint' },
+ 0x5dd: { name: 'EditionFlagOrdered', type: 'Uint' },
+ 0x36: { name: 'ChapterAtom', type: 'Container' },
+ 0x33c4: { name: 'ChapterUID', type: 'Uint' },
+ 0x1654: { name: 'ChapterStringUID', type: 'String' },
+ 0x11: { name: 'ChapterTimeStart', type: 'Uint' },
+ 0x12: { name: 'ChapterTimeEnd', type: 'Uint' },
+ 0x18: { name: 'ChapterFlagHidden', type: 'Uint' },
+ 0x598: { name: 'ChapterFlagEnabled', type: 'Uint' },
+ 0x2e67: { name: 'ChapterSegmentUID', type: 'Binary' },
+ 0x2ebc: { name: 'ChapterSegmentEditionUID', type: 'Uint' },
+ 0x23c3: { name: 'ChapterPhysicalEquiv', type: 'Uint' },
+ 0xf: { name: 'ChapterTrack', type: 'Container' },
+ 0x9: { name: 'ChapterTrackNumber', type: 'Uint' },
+ 0x0: { name: 'ChapterDisplay', type: 'Container' },
+ 0x5: { name: 'ChapString', type: 'String' },
+ 0x37c: { name: 'ChapLanguage', type: 'String' },
+ 0x37e: { name: 'ChapCountry', type: 'String' },
+ 0x2944: { name: 'ChapProcess', type: 'Container' },
+ 0x2955: { name: 'ChapProcessCodecID', type: 'Uint' },
+ 0x50d: { name: 'ChapProcessPrivate', type: 'Binary' },
+ 0x2911: { name: 'ChapProcessCommand', type: 'Container' },
+ 0x2922: { name: 'ChapProcessTime', type: 'Uint' },
+ 0x2933: { name: 'ChapProcessData', type: 'Binary' },
+ 0x254c367: { name: 'Tags', type: 'Container' },
+ 0x3373: { name: 'Tag', type: 'Container' },
+ 0x23c0: { name: 'Targets', type: 'Container' },
+ 0x28ca: { name: 'TargetTypeValue', type: 'Uint' },
+ 0x23ca: { name: 'TargetType', type: 'String' },
+ 0x23c5: { name: 'TagTrackUID', type: 'Uint' },
+ 0x23c9: { name: 'TagEditionUID', type: 'Uint' },
+ 0x23c4: { name: 'TagChapterUID', type: 'Uint' },
+ 0x23c6: { name: 'TagAttachmentUID', type: 'Uint' },
+ 0x27c8: { name: 'SimpleTag', type: 'Container' },
+ 0x5a3: { name: 'TagName', type: 'String' },
+ 0x47a: { name: 'TagLanguage', type: 'String' },
+ 0x484: { name: 'TagDefault', type: 'Uint' },
+ 0x487: { name: 'TagString', type: 'String' },
+ 0x485: { name: 'TagBinary', type: 'Binary' }
+ };
+
+ function doInherit(newClass, baseClass) {
+ newClass.prototype = Object.create(baseClass.prototype);
+ newClass.prototype.constructor = newClass;
+ }
+
+ function WebmBase(name, type) {
+ this.name = name || 'Unknown';
+ this.type = type || 'Unknown';
+ }
+ WebmBase.prototype.updateBySource = function() { };
+ WebmBase.prototype.setSource = function(source) {
+ this.source = source;
+ this.updateBySource();
+ };
+ WebmBase.prototype.updateByData = function() { };
+ WebmBase.prototype.setData = function(data) {
+ this.data = data;
+ this.updateByData();
+ };
+
+ function WebmUint(name, type) {
+ WebmBase.call(this, name, type || 'Uint');
+ }
+ doInherit(WebmUint, WebmBase);
+ function padHex(hex) {
+ return hex.length % 2 === 1 ? '0' + hex : hex;
+ }
+ WebmUint.prototype.updateBySource = function() {
+ // use hex representation of a number instead of number value
+ this.data = '';
+ for (var i = 0; i < this.source.length; i++) {
+ var hex = this.source[i].toString(16);
+ this.data += padHex(hex);
+ }
+ };
+ WebmUint.prototype.updateByData = function() {
+ var length = this.data.length / 2;
+ this.source = new Uint8Array(length);
+ for (var i = 0; i < length; i++) {
+ var hex = this.data.substr(i * 2, 2);
+ this.source[i] = parseInt(hex, 16);
+ }
+ };
+ WebmUint.prototype.getValue = function() {
+ return parseInt(this.data, 16);
+ };
+ WebmUint.prototype.setValue = function(value) {
+ this.setData(padHex(value.toString(16)));
+ };
+
+ function WebmFloat(name, type) {
+ WebmBase.call(this, name, type || 'Float');
+ }
+ doInherit(WebmFloat, WebmBase);
+ WebmFloat.prototype.getFloatArrayType = function() {
+ return this.source && this.source.length === 4 ? Float32Array : Float64Array;
+ };
+ WebmFloat.prototype.updateBySource = function() {
+ var byteArray = this.source.reverse();
+ var floatArrayType = this.getFloatArrayType();
+ var floatArray = new floatArrayType(byteArray.buffer);
+ this.data = floatArray[0];
+ };
+ WebmFloat.prototype.updateByData = function() {
+ var floatArrayType = this.getFloatArrayType();
+ var floatArray = new floatArrayType([ this.data ]);
+ var byteArray = new Uint8Array(floatArray.buffer);
+ this.source = byteArray.reverse();
+ };
+ WebmFloat.prototype.getValue = function() {
+ return this.data;
+ };
+ WebmFloat.prototype.setValue = function(value) {
+ this.setData(value);
+ };
+
+ function WebmContainer(name, type) {
+ WebmBase.call(this, name, type || 'Container');
+ }
+ doInherit(WebmContainer, WebmBase);
+ WebmContainer.prototype.readByte = function() {
+ return this.source[this.offset++];
+ };
+ WebmContainer.prototype.readUint = function() {
+ var firstByte = this.readByte();
+ var bytes = 8 - firstByte.toString(2).length;
+ var value = firstByte - (1 << (7 - bytes));
+ for (var i = 0; i < bytes; i++) {
+ // don't use bit operators to support x86
+ value *= 256;
+ value += this.readByte();
+ }
+ return value;
+ };
+ WebmContainer.prototype.updateBySource = function() {
+ this.data = [];
+ for (this.offset = 0; this.offset < this.source.length; this.offset = end) {
+ var id = this.readUint();
+ var len = this.readUint();
+ var end = Math.min(this.offset + len, this.source.length);
+ var data = this.source.slice(this.offset, end);
+
+ var info = sections[id] || { name: 'Unknown', type: 'Unknown' };
+ var ctr = WebmBase;
+ switch (info.type) {
+ case 'Container':
+ ctr = WebmContainer;
+ break;
+ case 'Uint':
+ ctr = WebmUint;
+ break;
+ case 'Float':
+ ctr = WebmFloat;
+ break;
+ }
+ var section = new ctr(info.name, info.type);
+ section.setSource(data);
+ this.data.push({
+ id: id,
+ idHex: id.toString(16),
+ data: section
+ });
+ }
+ };
+ WebmContainer.prototype.writeUint = function(x, draft) {
+ for (var bytes = 1, flag = 0x80; x >= flag && bytes < 8; bytes++, flag *= 0x80) { }
+
+ if (!draft) {
+ var value = flag + x;
+ for (var i = bytes - 1; i >= 0; i--) {
+ // don't use bit operators to support x86
+ var c = value % 256;
+ this.source[this.offset + i] = c;
+ value = (value - c) / 256;
+ }
+ }
+
+ this.offset += bytes;
+ };
+ WebmContainer.prototype.writeSections = function(draft) {
+ this.offset = 0;
+ for (var i = 0; i < this.data.length; i++) {
+ var section = this.data[i],
+ content = section.data.source,
+ contentLength = content.length;
+ this.writeUint(section.id, draft);
+ this.writeUint(contentLength, draft);
+ if (!draft) {
+ this.source.set(content, this.offset);
+ }
+ this.offset += contentLength;
+ }
+ return this.offset;
+ };
+ WebmContainer.prototype.updateByData = function() {
+ // run without accessing this.source to determine total length - need to know it to create Uint8Array
+ var length = this.writeSections('draft');
+ this.source = new Uint8Array(length);
+ // now really write data
+ this.writeSections();
+ };
+ WebmContainer.prototype.getSectionById = function(id) {
+ for (var i = 0; i < this.data.length; i++) {
+ var section = this.data[i];
+ if (section.id === id) {
+ return section.data;
+ }
+ }
+ return null;
+ };
+
+ function WebmFile(source) {
+ WebmContainer.call(this, 'File', 'File');
+ this.setSource(source);
+ }
+ doInherit(WebmFile, WebmContainer);
+ WebmFile.prototype.fixDuration = function(duration, options) {
+ var logger = options && options.logger;
+ if (logger === undefined) {
+ logger = function(message) {
+ console.log(message);
+ };
+ } else if (!logger) {
+ logger = function() { };
+ }
+
+ var segmentSection = this.getSectionById(0x8538067);
+ if (!segmentSection) {
+ logger('[fix-webm-duration] Segment section is missing');
+ return false;
+ }
+
+ var infoSection = segmentSection.getSectionById(0x549a966);
+ if (!infoSection) {
+ logger('[fix-webm-duration] Info section is missing');
+ return false;
+ }
+
+ var timeScaleSection = infoSection.getSectionById(0xad7b1);
+ if (!timeScaleSection) {
+ logger('[fix-webm-duration] TimecodeScale section is missing');
+ return false;
+ }
+
+ var durationSection = infoSection.getSectionById(0x489);
+ if (durationSection) {
+ if (durationSection.getValue() <= 0) {
+ logger('[fix-webm-duration] Duration section is present, but the value is empty');
+ durationSection.setValue(duration);
+ } else {
+ logger('[fix-webm-duration] Duration section is present');
+ return false;
+ }
+ } else {
+ logger('[fix-webm-duration] Duration section is missing');
+ // append Duration section
+ durationSection = new WebmFloat('Duration', 'Float');
+ durationSection.setValue(duration);
+ infoSection.data.push({
+ id: 0x489,
+ data: durationSection
+ });
+ }
+
+ // set default time scale to 1 millisecond (1000000 nanoseconds)
+ timeScaleSection.setValue(1000000);
+ infoSection.updateByData();
+ segmentSection.updateByData();
+ this.updateByData();
+
+ return true;
+ };
+ WebmFile.prototype.toBlob = function(mimeType) {
+ return new Blob([ this.source.buffer ], { type: mimeType || 'video/webm' });
+ };
+
+ function fixWebmDuration(blob, duration, callback, options) {
+ // The callback may be omitted - then the third argument is options
+ if (typeof callback === "object") {
+ options = callback;
+ callback = undefined;
+ }
+
+ if (!callback) {
+ return new Promise(function(resolve) {
+ fixWebmDuration(blob, duration, resolve, options);
+ });
+ }
+
+ try {
+ var reader = new FileReader();
+ reader.onloadend = function() {
+ try {
+ var file = new WebmFile(new Uint8Array(reader.result));
+ if (file.fixDuration(duration, options)) {
+ blob = file.toBlob(blob.type);
+ }
+ } catch (ex) {
+ // ignore
+ }
+ callback(blob);
+ };
+ reader.readAsArrayBuffer(blob);
+ } catch (ex) {
+ callback(blob);
+ }
+ }
+
+ // Support AMD import default
+ fixWebmDuration.default = fixWebmDuration;
+
+ return fixWebmDuration;
+});
diff --git a/addons/ofxEmscripten/libs/html5video/lib/emscripten/recordVideo.js b/addons/ofxEmscripten/libs/html5video/lib/emscripten/recordVideo.js
new file mode 100644
index 00000000000..743a67fc8bb
--- /dev/null
+++ b/addons/ofxEmscripten/libs/html5video/lib/emscripten/recordVideo.js
@@ -0,0 +1,117 @@
+drawTexture__deps = ['$GL'];
+var stream;
+var mediaParts;
+var startTime;
+var mediaRecorder;
+var data;
+var fb;
+var canvas2 = document.createElement('canvas');
+var context2 = canvas2.getContext('2d');
+var videoTypes = ["webm", "ogg", "mp4", "x-matroska"];
+var audioTypes = ["webm", "ogg", "mp3", "x-matroska"];
+var codecs = ["should-not-be-supported","vp9", "vp9.0", "vp8", "vp8.0", "avc1", "av1", "h265", "h.265", "h264", "h.264", "pcm", "opus", "aac", "mpeg", "mp4a"];
+
+function recordVideo(isRecording, textureID) {
+ if (isRecording) {
+ mediaParts = [];
+ if (typeof textureID != 'undefined') {
+ stream = canvas2.captureStream(30);
+ var texture = GL.textures[textureID];
+
+ // make a framebuffer
+ fb = GLctx.createFramebuffer();
+
+ // make this the current frame buffer
+ GLctx.bindFramebuffer(GLctx.FRAMEBUFFER, fb);
+
+ // attach the texture to the framebuffer.
+ GLctx.framebufferTexture2D(
+ GLctx.FRAMEBUFFER, GLctx.COLOR_ATTACHMENT0,
+ GLctx.TEXTURE_2D, texture, 0);
+
+ // Unbind the framebuffer
+ GLctx.bindFramebuffer(GLctx.FRAMEBUFFER, null);
+ } else {
+ stream = canvas.captureStream(30);
+ }
+ var supportedVideos = getSupportedMimeTypes("video", videoTypes, codecs);
+ var supportedAudios = getSupportedMimeTypes("audio", audioTypes, codecs);
+
+ console.log('-- Top supported Video : ', supportedVideos[0])
+ console.log('-- Top supported Audio : ', supportedAudios[0])
+ console.log('-- All supported Videos : ', supportedVideos)
+ console.log('-- All supported Audios : ', supportedAudios)
+
+ var audioCodec = supportedAudios[0].split("codecs=")[1];
+ var mimeType = supportedVideos[0] + "," + audioCodec;
+ console.log("-- MIME type : ", mimeType);
+ stream.addTrack(AUDIO.contextStream.stream.getAudioTracks()[0]);
+ mediaRecorder = new MediaRecorder(stream, {
+ audioBitsPerSecond : 128000, // 128 kbps
+ videoBitsPerSecond: 10000000, // 4x the default quality from 2.5Mbps to 10Mbps
+ mimeType: mimeType
+ });
+ mediaRecorder.onstop = function() {
+ var duration = Date.now() - startTime;
+ var buggyBlob = new Blob(mediaParts, { type: mimeType });
+ ysFixWebmDuration(buggyBlob, duration, function(fixedBlob) {
+ downloadBlob(fixedBlob);
+ });
+ };
+ mediaRecorder.ondataavailable = function(event) {
+ var data = event.data;
+ if (data && data.size > 0) {
+ mediaParts.push(data);
+ }
+ };
+ mediaRecorder.start();
+ startTime = Date.now();
+ } else {
+ mediaRecorder.stop();
+ }
+}
+
+function downloadBlob(blob) {
+ var url = URL.createObjectURL(blob);
+ var tag = document.createElement('a');
+ tag.href = url;
+ tag.download = 'Video.mp4';
+ document.body.appendChild(tag);
+ tag.click();
+ document.body.removeChild(tag);
+}
+
+function drawTexture(textureWidth, textureHeight) {
+ // make this the current frame buffer
+ GLctx.bindFramebuffer(GLctx.FRAMEBUFFER, fb);
+
+ // read the pixels
+ if (canvas2.width != textureWidth || canvas2.height != textureHeight) {
+ canvas2.width = textureWidth;
+ canvas2.height = textureHeight;
+ data = new Uint8Array(textureWidth * textureHeight * 4);
+ }
+ GLctx.readPixels(0, 0, textureWidth, textureHeight, GLctx.RGBA, GLctx.UNSIGNED_BYTE, data);
+
+ // Unbind the framebuffer
+ GLctx.bindFramebuffer(GLctx.FRAMEBUFFER, null);
+ var imageData = new ImageData(new Uint8ClampedArray(data.buffer), textureWidth, textureHeight);
+ context2.putImageData(imageData, 0, 0);
+}
+
+function getSupportedMimeTypes(media, types, codecs) {
+ var isSupported = MediaRecorder.isTypeSupported;
+ var supported = [];
+ types.forEach((type) => {
+ var mimeType = `${media}/${type}`;
+ codecs.forEach((codec) => [
+ `${mimeType};codecs=${codec}`,
+ ].forEach(variation => {
+ if(isSupported(variation))
+ supported.push(variation);
+ }));
+ if (isSupported(mimeType))
+ supported.push(mimeType);
+ });
+ return supported;
+};
diff --git a/addons/ofxEmscripten/src/ofxEmscriptenSoundStream.cpp b/addons/ofxEmscripten/src/ofxEmscriptenSoundStream.cpp
index 54e8edf951e..7aee8fcd476 100644
--- a/addons/ofxEmscripten/src/ofxEmscriptenSoundStream.cpp
+++ b/addons/ofxEmscripten/src/ofxEmscriptenSoundStream.cpp
@@ -6,17 +6,64 @@
*/
#include "ofxEmscriptenSoundStream.h"
-// #include "html5audio.h"
#include "ofBaseApp.h"
#include "ofLog.h"
+#include "html5audio.h"
+#include "emscripten/webaudio.h"
using namespace std;
+EM_BOOL ProcessAudio(int numInputs, const AudioSampleFrame *inputs, int numOutputs, AudioSampleFrame *outputs, int numParams, const AudioParamFrame *params, void *userData) {
+ ofxEmscriptenSoundStream * stream = (ofxEmscriptenSoundStream *)userData;
+ ++stream->audioProcessedCount;
+ if (stream->settings.numInputChannels > 0 && stream->settings.inCallback) {
+ stream->settings.inCallback(stream->inbuffer);
+ for (int o = 0; o < numInputs; ++o) {
+ for (int i = 0; i < 128; ++i) {
+ for (int ch = 0; ch < inputs[o].numberOfChannels; ++ch) {
+ stream->inbuffer[i * inputs[o].numberOfChannels + ch] = inputs[o].data[ch * 128 + i];
+ }
+ }
+ }
+ }
+ if (stream->settings.numOutputChannels > 0 && stream->settings.outCallback) {
+ stream->settings.outCallback(stream->outbuffer);
+ for (int o = 0; o < numOutputs; ++o) {
+ for (int i = 0; i < 128; ++i) {
+ for (int ch = 0; ch < outputs[o].numberOfChannels; ++ch) {
+ outputs[o].data[ch * 128 + i] = stream->outbuffer[i * outputs[o].numberOfChannels + ch];
+ }
+ }
+ }
+ }
+ return EM_TRUE;
+}
+
+void AudioWorkletProcessorCreated(EMSCRIPTEN_WEBAUDIO_T audioContext, EM_BOOL success, void *userData) {
+ if (!success) return;
+ ofxEmscriptenSoundStream * stream = (ofxEmscriptenSoundStream *)userData;
+ int outputChannelCounts[1] = { static_cast(stream->settings.numOutputChannels) };
+ EmscriptenAudioWorkletNodeCreateOptions options = {
+ .numberOfInputs = 1,
+ .numberOfOutputs = 1,
+ .outputChannelCounts = outputChannelCounts
+ };
+ EMSCRIPTEN_AUDIO_WORKLET_NODE_T audioWorklet = emscripten_create_wasm_audio_worklet_node(audioContext, "audio-processor", &options, &ProcessAudio, userData);
+ html5audio_stream_create(audioWorklet, stream->settings.numInputChannels);
+}
+
+void WebAudioWorkletThreadInitialized(EMSCRIPTEN_WEBAUDIO_T audioContext, EM_BOOL success, void *userData) {
+ if (!success) return;
+ WebAudioWorkletProcessorCreateOptions opts = {
+ .name = "audio-processor",
+ };
+ emscripten_create_wasm_audio_worklet_processor_async(audioContext, &opts, AudioWorkletProcessorCreated, userData);
+}
+
int ofxEmscriptenAudioContext();
ofxEmscriptenSoundStream::ofxEmscriptenSoundStream()
:context(ofxEmscriptenAudioContext())
-,tickCount(0)
{
}
@@ -26,15 +73,16 @@ ofxEmscriptenSoundStream::~ofxEmscriptenSoundStream() {
}
std::vector ofxEmscriptenSoundStream::getDeviceList(ofSoundDevice::Api api) const{
- //html5audio_list_devices();
+ html5audio_list_devices();
return vector();
}
bool ofxEmscriptenSoundStream::setup(const ofSoundStreamSettings & settings) {
inbuffer.allocate(settings.bufferSize, settings.numInputChannels);
outbuffer.allocate(settings.bufferSize, settings.numOutputChannels);
+ audioProcessedCount = 0;
this->settings = settings;
- //html5audio_stream_create(settings.bufferSize,settings.numInputChannels,settings.numOutputChannels,inbuffer.getBuffer().data(),outbuffer.getBuffer().data(),&audio_cb,this);
+ emscripten_start_wasm_audio_worklet_thread_async(context, wasmAudioWorkletStack, sizeof(wasmAudioWorkletStack), WebAudioWorkletThreadInitialized, this);
return true;
}
@@ -55,19 +103,19 @@ ofSoundDevice ofxEmscriptenSoundStream::getOutDevice() const{
}
void ofxEmscriptenSoundStream::start() {
- //html5audio_context_start();
+ html5audio_context_start();
}
void ofxEmscriptenSoundStream::stop() {
- //html5audio_context_stop();
+ html5audio_context_stop();
}
void ofxEmscriptenSoundStream::close() {
- //html5audio_stream_free();
+ html5audio_stream_free();
}
uint64_t ofxEmscriptenSoundStream::getTickCount() const{
- return tickCount;
+ return audioProcessedCount;
}
int ofxEmscriptenSoundStream::getNumInputChannels() const{
@@ -79,20 +127,9 @@ int ofxEmscriptenSoundStream::getNumOutputChannels() const{
}
int ofxEmscriptenSoundStream::getSampleRate() const{
- return 0;//html5audio_context_samplerate();
+ return html5audio_context_samplerate();
}
int ofxEmscriptenSoundStream::getBufferSize() const{
return settings.bufferSize;
}
-
-void ofxEmscriptenSoundStream::audio_cb( int bufferSize, int inputChannels, int outputChannels, void * userData){
- ofxEmscriptenSoundStream * stream = (ofxEmscriptenSoundStream*) userData;
- stream->audioCB(bufferSize,inputChannels,outputChannels);
-}
-
-void ofxEmscriptenSoundStream::audioCB(int bufferSize, int inputChannels, int outputChannels){
- if(inputChannels>0 && settings.inCallback) settings.inCallback(inbuffer);
- if(outputChannels>0 && settings.outCallback) settings.outCallback(outbuffer);
- tickCount++;
-}
diff --git a/addons/ofxEmscripten/src/ofxEmscriptenSoundStream.h b/addons/ofxEmscripten/src/ofxEmscriptenSoundStream.h
index 73943c8a14d..8d0976e92a5 100644
--- a/addons/ofxEmscripten/src/ofxEmscriptenSoundStream.h
+++ b/addons/ofxEmscripten/src/ofxEmscriptenSoundStream.h
@@ -32,13 +32,12 @@ class ofxEmscriptenSoundStream: public ofBaseSoundStream {
int getNumOutputChannels() const;
int getSampleRate() const;
int getBufferSize() const;
-
-private:
- static void audio_cb(int bufferSize, int inputChannels, int outputChannels, void * userData);
- void audioCB(int bufferSize, int inputChannels, int outputChannels);
- int context;
- unsigned long long tickCount;
ofSoundStreamSettings settings;
ofSoundBuffer inbuffer;
ofSoundBuffer outbuffer;
+ int audioProcessedCount;
+
+private:
+ int context;
+ uint8_t wasmAudioWorkletStack[4096 * 4];
};
diff --git a/examples/gl/glInfoExample/src/ofApp.cpp b/examples/gl/glInfoExample/src/ofApp.cpp
index bf2dd5a75f3..45dfc57e2a1 100644
--- a/examples/gl/glInfoExample/src/ofApp.cpp
+++ b/examples/gl/glInfoExample/src/ofApp.cpp
@@ -90,35 +90,36 @@ print_extension_list(char *ext)
static void
print_limits(void)
{
-
static const struct token_name openglLimits[] = {
- { 1, GL_MAX_ATTRIB_STACK_DEPTH, "GL_MAX_ATTRIB_STACK_DEPTH" },
- { 1, GL_MAX_CLIENT_ATTRIB_STACK_DEPTH, "GL_MAX_CLIENT_ATTRIB_STACK_DEPTH" },
- { 1, GL_MAX_CLIP_PLANES, "GL_MAX_CLIP_PLANES" },
- { 1, GL_MAX_COLOR_MATRIX_STACK_DEPTH, "GL_MAX_COLOR_MATRIX_STACK_DEPTH" },
+ #ifndef TARGET_EMSCRIPTEN
+ { 1, GL_MAX_ATTRIB_STACK_DEPTH, "GL_MAX_ATTRIB_STACK_DEPTH" },
+ { 1, GL_MAX_CLIENT_ATTRIB_STACK_DEPTH, "GL_MAX_CLIENT_ATTRIB_STACK_DEPTH" },
+ { 1, GL_MAX_CLIP_PLANES, "GL_MAX_CLIP_PLANES" },
+ { 1, GL_MAX_COLOR_MATRIX_STACK_DEPTH, "GL_MAX_COLOR_MATRIX_STACK_DEPTH" },
+ { 1, GL_MAX_EVAL_ORDER, "GL_MAX_EVAL_ORDER" },
+ { 1, GL_MAX_LIGHTS, "GL_MAX_LIGHTS" },
+ { 1, GL_MAX_LIST_NESTING, "GL_MAX_LIST_NESTING" },
+ { 1, GL_MAX_MODELVIEW_STACK_DEPTH, "GL_MAX_MODELVIEW_STACK_DEPTH" },
+ { 1, GL_MAX_NAME_STACK_DEPTH, "GL_MAX_NAME_STACK_DEPTH" },
+ { 1, GL_MAX_PIXEL_MAP_TABLE, "GL_MAX_PIXEL_MAP_TABLE" },
+ { 1, GL_MAX_PROJECTION_STACK_DEPTH, "GL_MAX_PROJECTION_STACK_DEPTH" },
+ { 1, GL_MAX_TEXTURE_STACK_DEPTH, "GL_MAX_TEXTURE_STACK_DEPTH" },
+ { 1, GL_MAX_RECTANGLE_TEXTURE_SIZE_NV, "GL_MAX_RECTANGLE_TEXTURE_SIZE_NV" },
+ { 1, GL_MAX_TEXTURE_UNITS_ARB, "GL_MAX_TEXTURE_UNITS_ARB" },
+ { 2, GL_SMOOTH_LINE_WIDTH_RANGE, "GL_SMOOTH_LINE_WIDTH_RANGE" },
+ { 2, GL_SMOOTH_POINT_SIZE_RANGE, "GL_SMOOTH_POINT_SIZE_RANGE" },
+ #endif
{ 1, GL_MAX_ELEMENTS_VERTICES, "GL_MAX_ELEMENTS_VERTICES" },
{ 1, GL_MAX_ELEMENTS_INDICES, "GL_MAX_ELEMENTS_INDICES" },
- { 1, GL_MAX_EVAL_ORDER, "GL_MAX_EVAL_ORDER" },
- { 1, GL_MAX_LIGHTS, "GL_MAX_LIGHTS" },
- { 1, GL_MAX_LIST_NESTING, "GL_MAX_LIST_NESTING" },
- { 1, GL_MAX_MODELVIEW_STACK_DEPTH, "GL_MAX_MODELVIEW_STACK_DEPTH" },
- { 1, GL_MAX_NAME_STACK_DEPTH, "GL_MAX_NAME_STACK_DEPTH" },
- { 1, GL_MAX_PIXEL_MAP_TABLE, "GL_MAX_PIXEL_MAP_TABLE" },
- { 1, GL_MAX_PROJECTION_STACK_DEPTH, "GL_MAX_PROJECTION_STACK_DEPTH" },
- { 1, GL_MAX_TEXTURE_STACK_DEPTH, "GL_MAX_TEXTURE_STACK_DEPTH" },
{ 1, GL_MAX_TEXTURE_SIZE, "GL_MAX_TEXTURE_SIZE" },
{ 1, GL_MAX_3D_TEXTURE_SIZE, "GL_MAX_3D_TEXTURE_SIZE" },
{ 1, GL_MAX_CUBE_MAP_TEXTURE_SIZE_ARB, "GL_MAX_CUBE_MAP_TEXTURE_SIZE_ARB" },
- { 1, GL_MAX_RECTANGLE_TEXTURE_SIZE_NV, "GL_MAX_RECTANGLE_TEXTURE_SIZE_NV" },
{ 1, GL_NUM_COMPRESSED_TEXTURE_FORMATS_ARB, "GL_NUM_COMPRESSED_TEXTURE_FORMATS_ARB" },
- { 1, GL_MAX_TEXTURE_UNITS_ARB, "GL_MAX_TEXTURE_UNITS_ARB" },
{ 1, GL_MAX_TEXTURE_LOD_BIAS_EXT, "GL_MAX_TEXTURE_LOD_BIAS_EXT" },
{ 1, GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, "GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT" },
{ 2, GL_MAX_VIEWPORT_DIMS, "GL_MAX_VIEWPORT_DIMS" },
{ 2, GL_ALIASED_LINE_WIDTH_RANGE, "GL_ALIASED_LINE_WIDTH_RANGE" },
- { 2, GL_SMOOTH_LINE_WIDTH_RANGE, "GL_SMOOTH_LINE_WIDTH_RANGE" },
{ 2, GL_ALIASED_POINT_SIZE_RANGE, "GL_ALIASED_POINT_SIZE_RANGE" },
- { 2, GL_SMOOTH_POINT_SIZE_RANGE, "GL_SMOOTH_POINT_SIZE_RANGE" },
{ 0, (GLenum) 0, NULL }
};
GLint i, max[2];
@@ -135,7 +136,6 @@ print_limits(void)
}
void printShaderLimits(){
-
static const struct token_name lll[] = {
{ 1, GL_MAX_VERTEX_ATTRIBS, "GL_MAX_VERTEX_ATTRIBS" },
{ 1, GL_MAX_VERTEX_UNIFORM_COMPONENTS, "GL_MAX_VERTEX_UNIFORM_COMPONENTS" },
@@ -160,7 +160,6 @@ void printShaderLimits(){
void printGLInfo(){
-
char *version = NULL;
char *vendor = NULL;
char *renderer = NULL;
@@ -173,14 +172,11 @@ void printGLInfo(){
renderer = (char*)glGetString(GL_RENDERER);
cout << "version=" << version << "\nvendor=" << vendor << "\nrenderer=" << renderer << "\n";
-
}
//--------------------------------------------------------------
void ofApp::setup(){
-
-
info.version = (char*)glGetString(GL_VERSION);
info.vendor = (char*)glGetString(GL_VENDOR);
info.renderer = (char*)glGetString(GL_RENDERER);
@@ -203,8 +199,9 @@ void ofApp::setup(){
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &info.maxTextureSize);
glGetIntegerv(GL_MAX_VIEWPORT_DIMS, info.maxDimensions);
- glGetIntegerv(GL_MAX_LIGHTS, &info.maxLights);
-
+ #ifndef TARGET_EMSCRIPTEN
+ glGetIntegerv(GL_MAX_LIGHTS, &info.maxLights);
+ #endif
}
//--------------------------------------------------------------
@@ -214,7 +211,6 @@ void ofApp::update(){
//--------------------------------------------------------------
void ofApp::draw(){
-
string output = "";
string pointSprites = ((info.bPointSpritesSupported == true) ? "yes" : "no");
@@ -238,24 +234,22 @@ void ofApp::draw(){
ofDrawBitmapStringHighlight(output, 20, 20);
ofDrawBitmapStringHighlight("press ' ' to load full report", 20, 220, ofColor::magenta, ofColor::white);
-
}
//--------------------------------------------------------------
void ofApp::keyPressed(int key){
-
if (key == ' '){
// todo: rewrite this with ofLog:
+
+ #ifndef TARGET_EMSCRIPTEN
+ FILE *fp;
- FILE *fp;
-
-
- if((fp=freopen(ofToDataPath("openglReport.txt").c_str(), "w" ,stdout))==NULL) {
- cout << "Cannot open file.\n";
- return;
- }
-
+ if((fp=freopen(ofToDataPath("openglReport.txt").c_str(), "w" ,stdout))==NULL) {
+ cout << "Cannot open file.\n";
+ return;
+ }
+ #endif
cout << "-------------------------------------------------\n";
cout << "opengl info\n";
@@ -296,20 +290,22 @@ void ofApp::keyPressed(int key){
printGlewInfo();
-
- fclose(fp);
-
- #ifdef TARGET_WIN32
- string command = "start " + ofToString(ofToDataPath("openglReport.txt").c_str());
- #elif defined(TARGET_LINUX)
- string command = "xdg-open " + ofToString(ofToDataPath("openglReport.txt").c_str());
- #else
- string command = "open " + ofToString(ofToDataPath("openglReport.txt").c_str());
+
+ #ifndef TARGET_EMSCRIPTEN
+ fclose(fp);
+
+ #ifdef TARGET_WIN32
+ string command = "start " + ofToString(ofToDataPath("openglReport.txt").c_str());
+ #elif defined(TARGET_LINUX)
+ string command = "xdg-open " + ofToString(ofToDataPath("openglReport.txt").c_str());
+ #else
+ string command = "open " + ofToString(ofToDataPath("openglReport.txt").c_str());
+ #endif
+
+ if (0 != system(command.c_str())){
+ ofLogWarning() << "Command " << command.c_str() << " did not return 0. Something may have gone wrong.";
+ }
#endif
-
- if (0 != system(command.c_str())){
- ofLogWarning() << "Command " << command.c_str() << " did not return 0. Something may have gone wrong.";
- }
}
}
diff --git a/examples/sound/audioInputExample/src/ofApp.cpp b/examples/sound/audioInputExample/src/ofApp.cpp
index 72da4ece7e6..4546a7ed342 100644
--- a/examples/sound/audioInputExample/src/ofApp.cpp
+++ b/examples/sound/audioInputExample/src/ofApp.cpp
@@ -9,9 +9,10 @@ void ofApp::setup(){
soundStream.printDeviceList();
- int bufferSize = 512;
+ int bufferSize = 128;
-
+ left.assign(bufferSize, 0.0);
+ right.assign(bufferSize, 0.0);
volHistory.assign(400, 0.0);
bufferCounter = 0;
@@ -27,16 +28,14 @@ void ofApp::setup(){
// settings.device = devices[4];
// you can also get devices for an specific api
- // auto devices = soundStream.getDeviceList(ofSoundDevice::Api::PULSE);
+ // auto devices = soundStream.getDevicesByApi(ofSoundDevice::Api::PULSE);
// settings.device = devices[0];
// or get the default device for an specific api:
// settings.api = ofSoundDevice::Api::PULSE;
// or by name
-
auto devices = soundStream.getMatchingDevices("default");
-
if(!devices.empty()){
settings.setInDevice(devices[0]);
}
@@ -45,18 +44,14 @@ void ofApp::setup(){
settings.sampleRate = 44100;
#ifdef TARGET_EMSCRIPTEN
settings.numOutputChannels = 2;
+ settings.numInputChannels = 2;
#else
settings.numOutputChannels = 0;
+ settings.numInputChannels = 1;
#endif
- settings.numInputChannels = 1;
settings.bufferSize = bufferSize;
soundStream.setup(settings);
- bufferSize = soundStream.getBufferSize();
-
- left.assign(bufferSize, 0.0);
- right.assign(bufferSize, 0.0);
-
}
//--------------------------------------------------------------
@@ -98,7 +93,7 @@ void ofApp::draw(){
ofBeginShape();
for (unsigned int i = 0; i < left.size(); i++){
- ofVertex(i*2, 100 -left[i]*180.0f);
+ ofVertex(i*4, 100 -left[i]*180.0f);
}
ofEndShape(false);
@@ -121,7 +116,7 @@ void ofApp::draw(){
ofBeginShape();
for (unsigned int i = 0; i < right.size(); i++){
- ofVertex(i*2, 100 -right[i]*180.0f);
+ ofVertex(i*4, 100 -right[i]*180.0f);
}
ofEndShape(false);
@@ -173,8 +168,8 @@ void ofApp::audioIn(ofSoundBuffer & input){
//lets go through each sample and calculate the root mean square which is a rough way to calculate volume
for (size_t i = 0; i < input.getNumFrames(); i++){
- left[i] = input[i]*0.5;
- right[i] = input[i]*0.5;
+ left[i] = input[i*2]*0.5;
+ right[i] = input[i*2+1]*0.5;
curVol += left[i] * left[i];
curVol += right[i] * right[i];
diff --git a/examples/sound/audioOutputExample/src/ofApp.cpp b/examples/sound/audioOutputExample/src/ofApp.cpp
index 3d8037a559d..d957e2263bd 100644
--- a/examples/sound/audioOutputExample/src/ofApp.cpp
+++ b/examples/sound/audioOutputExample/src/ofApp.cpp
@@ -5,7 +5,7 @@ void ofApp::setup(){
ofBackground(34, 34, 34);
- int bufferSize = 512;
+ int bufferSize = 128;
sampleRate = 44100;
phase = 0;
phaseAdder = 0.0f;
@@ -41,22 +41,15 @@ void ofApp::setup(){
// settings.setOutDevice(devices[0]);
// }
-
+#ifdef TARGET_LINUX
// Latest linux versions default to the HDMI output
// this usually fixes that. Also check the list of available
// devices if sound doesn't work
-
- //settings.setApi(ofSoundDevice::MS_ASIO);
- //settings.setApi(ofSoundDevice::MS_WASAPI);
- //settings.setApi(ofSoundDevice::MS_DS);
-
auto devices = soundStream.getMatchingDevices("default");
if(!devices.empty()){
settings.setOutDevice(devices[0]);
}
-
-
-
+#endif
settings.setOutListener(this);
settings.sampleRate = sampleRate;
@@ -149,10 +142,10 @@ void ofApp::draw(){
void ofApp::keyPressed (int key){
if (key == '-' || key == '_' ){
volume -= 0.05;
- volume = std::max(volume, 0.f);
+ volume = MAX(volume, 0);
} else if (key == '+' || key == '=' ){
volume += 0.05;
- volume = std::min(volume, 1.f);
+ volume = MIN(volume, 1);
}
if( key == 's' ){
@@ -177,7 +170,7 @@ void ofApp::mouseMoved(int x, int y ){
float height = (float)ofGetHeight();
float heightPct = ((height-y) / height);
targetFrequency = 2000.0f * heightPct;
- phaseAdderTarget = (targetFrequency / (float) sampleRate) * glm::two_pi();
+ phaseAdderTarget = (targetFrequency / (float) sampleRate) * TWO_PI;
}
//--------------------------------------------------------------
@@ -219,9 +212,9 @@ void ofApp::audioOut(ofSoundBuffer & buffer){
float rightScale = pan;
// sin (n) seems to have trouble when n is very large, so we
- // keep phase in the range of 0-glm::two_pi() like this:
- while (phase > glm::two_pi()){
- phase -= glm::two_pi();
+ // keep phase in the range of 0-TWO_PI like this:
+ while (phase > TWO_PI){
+ phase -= TWO_PI;
}
if ( bNoise == true){
diff --git a/examples/sound/soundBufferExample/src/ofApp.cpp b/examples/sound/soundBufferExample/src/ofApp.cpp
index 7448678a1cb..5df14af22a9 100644
--- a/examples/sound/soundBufferExample/src/ofApp.cpp
+++ b/examples/sound/soundBufferExample/src/ofApp.cpp
@@ -12,7 +12,7 @@ void ofApp::setup(){
ofSoundStreamSettings settings;
settings.numOutputChannels = 2;
settings.sampleRate = 44100;
- settings.bufferSize = 512;
+ settings.bufferSize = 128;
settings.numBuffers = 4;
settings.setOutListener(this);
soundStream.setup(settings);
@@ -59,8 +59,8 @@ void ofApp::audioOut(ofSoundBuffer &outBuffer) {
float frequency = 172.5;
// mapping frequencies from Hz into full oscillations of sin() (two pi)
- float wavePhaseStep = (frequency / outBuffer.getSampleRate()) * glm::two_pi();
- float pulsePhaseStep = (0.5 / outBuffer.getSampleRate()) * glm::two_pi();
+ float wavePhaseStep = (frequency / outBuffer.getSampleRate()) * TWO_PI;
+ float pulsePhaseStep = (0.5 / outBuffer.getSampleRate()) * TWO_PI;
// this loop builds a buffer of audio containing 3 sine waves at different
// frequencies, and pulses the volume of each sine wave individually. In
@@ -69,14 +69,14 @@ void ofApp::audioOut(ofSoundBuffer &outBuffer) {
for(size_t i = 0; i < outBuffer.getNumFrames(); i++) {
// build up a chord out of sine waves at 3 different frequencies
- float sampleLow = std::sin(wavePhase);
- float sampleMid = std::sin(wavePhase * 1.5);
- float sampleHi = std::sin(wavePhase * 2.0);
+ float sampleLow = sin(wavePhase);
+ float sampleMid = sin(wavePhase * 1.5);
+ float sampleHi = sin(wavePhase * 2.0);
// pulse each sample's volume
- sampleLow *= std::sin(pulsePhase);
- sampleMid *= std::sin(pulsePhase * 1.04);
- sampleHi *= std::sin(pulsePhase * 1.09);
+ sampleLow *= sin(pulsePhase);
+ sampleMid *= sin(pulsePhase * 1.04);
+ sampleHi *= sin(pulsePhase * 1.09);
float fullSample = (sampleLow + sampleMid + sampleHi);
diff --git a/libs/openFrameworksCompiled/project/emscripten/config.emscripten.default.mk b/libs/openFrameworksCompiled/project/emscripten/config.emscripten.default.mk
index 1c633c942da..12a8a40b2b1 100644
--- a/libs/openFrameworksCompiled/project/emscripten/config.emscripten.default.mk
+++ b/libs/openFrameworksCompiled/project/emscripten/config.emscripten.default.mk
@@ -131,11 +131,15 @@ PLATFORM_LDFLAGS += -s AUTO_JS_LIBRARIES=1
PLATFORM_LDFLAGS += -s VERBOSE=1
PLATFORM_LDFLAGS += $(PLATFORM_PTHREAD)
+PLATFORM_LDFLAGS += -s AUDIO_WORKLET=1 -s WASM_WORKERS=1 -s ENVIRONMENT="web,worker" -s WEBAUDIO_DEBUG=1
PLATFORM_LDFLAGS += --js-library $(OF_ADDONS_PATH)/ofxEmscripten/libs/html5video/lib/emscripten/library_html5video.js
+PLATFORM_LDFLAGS += --pre-js $(OF_ADDONS_PATH)/ofxEmscripten/libs/html5video/lib/emscripten/recordVideo.js
+PLATFORM_LDFLAGS += --pre-js $(OF_ADDONS_PATH)/ofxEmscripten/libs/html5video/lib/emscripten/fix-webm-duration.js
+PLATFORM_LDFLAGS += --post-js $(OF_ADDONS_PATH)/ofxEmscripten/libs/html5audio/lib/emscripten/library_audioDeviceSelect.js
# PLATFORM_LDFLAGS += --js-library $(OF_ADDONS_PATH)/ofxEmscripten/libs/html5audio/lib/emscripten/library_html5audio.js
-PLATFORM_LDFLAGS += -s MAIN_MODULE=1 -DEMCC_FORCE_STDLIBS=1
+PLATFORM_LDFLAGS += -s MAIN_MODULE=2 -DEMCC_FORCE_STDLIBS=1
PLATFORM_LDFLAGS += -s EXPORT_ALL=1
PLATFORM_LDFLAGS += -s NO_DYNAMIC_EXECUTION=1
PLATFORM_LDFLAGS += -s ABORT_ON_WASM_EXCEPTIONS=0
diff --git a/scripts/templates/emscripten/src/main.cpp b/scripts/templates/emscripten/src/main.cpp
index cfcb6b0bd66..d888dda20c1 100644
--- a/scripts/templates/emscripten/src/main.cpp
+++ b/scripts/templates/emscripten/src/main.cpp
@@ -16,7 +16,7 @@ int main( ){
#endif
//Use ofGLFWWindowSettings for more options like multi-monitor fullscreen
- tofGLWindowSettings settings;
+ ofGLWindowSettings settings;
settings.setSize(1024, 768);
settings.windowMode = OF_WINDOW; //can also be OF_FULLSCREEN