Commit graph

65 commits

Author SHA1 Message Date
Fabian 497f618cab Merge branch 'wasm' into master 2021-01-03 02:07:20 -06:00
copy 82809ff85e Fix for recent versions of closure compiler 2019-07-03 20:23:39 -03:00
Ernest Wong 8b570936d2 Use alternative if AudioBuffer#copyToChannel is unavailable
Fixes #286

Safari 12 does not support AudioBuffer#copyToChannel yet.
2019-05-18 13:17:29 -05:00
Ernest Wong f6ae3ea58a AudioNode .connect chaining not implemented in Safari 2018-06-23 13:02:03 -06:00
Ernest Wong 155fb90ff1 Audio worklet needs its own DEBUG in debug mode
..as the audio worklet will have its own scope. In the compiled version,
the if(DEBUG) is removed so no problems showed up. However, in the debug
version, the browser will complain that DEBUG is not defined.
2018-06-04 11:52:38 -05:00
Ernest Wong 5f622f1853 Speaker fix typo (channel got neglected in mixer-volume)
It's always a fascinating find when you put your code through a linter
(jshint in this case - it warned about an unused variable).
2018-06-04 11:52:38 -05:00
Ernest Wong 2f1b06ccc5 Tidyup: semicolon 2018-04-08 14:38:24 -07:00
Ernest Wong d1ac093a68 Fix: incorrect optional integer argument logic 2018-04-08 14:38:24 -07:00
Ernest Wong 804e567458 Minor: inline param types over type casts 2018-04-08 14:38:24 -07:00
Ernest Wong 3dd7079be7 Fix comment typo + remove redundant cached state 2018-04-08 14:38:24 -07:00
Ernest Wong 8742a183aa Remove unecessary type casting 2018-04-08 14:38:24 -07:00
Ernest Wong 2939681b8b Use Reflect API over ES6 Class for audio worklet
The ES5 representation of ES6 classes generated by the Closure Compiler
isn't compatible with Audio Worklets. By using Reflect.construct to
create the inheritance relationship instead of the ES6 class syntax, the
worklet code can now be fed into the compiler.
2018-04-08 14:38:24 -07:00
Ernest Wong bd791d2339 Call mixer_reset, pcspeaker.start at known times 2018-04-08 14:38:24 -07:00
Ernest Wong 8aa4a7c8a7 Replace magic strings enums with integer constants 2018-04-08 14:38:24 -07:00
Ernest Wong f8b027951c Reuse empty buffer in speaker DAC worklet 2018-04-08 14:38:24 -07:00
Ernest Wong f9d8f72529 Minor: replace type casts with inline declarations 2018-04-08 14:38:24 -07:00
Ernest Wong 5c7d9069b4 Revoke worklet object URL after loaded 2018-04-08 14:38:24 -07:00
Ernest Wong 749e612815 Fix duplicated node_gain in speaker dac debugger 2018-04-08 14:38:24 -07:00
Ernest Wong 0fc48f81d3 Share and reuse download() function 2018-04-08 14:38:24 -07:00
Ernest Wong 2c982a6645 Minor: tidy up 2018-04-08 14:38:24 -07:00
Ernest Wong a2a0adafca Use dbg_* within speaker.js 2018-04-08 14:38:24 -07:00
Ernest Wong e8848af308 Fix closure type-casting positions 2018-04-08 14:38:24 -07:00
Ernest Wong 02be6d7a3a Tidy up: remove redundant code, add asserts, rename 2018-04-08 14:38:24 -07:00
Ernest Wong 82e3839501 Fix worklet buffer queuing calculation, and check NaN
Fixes certain cases that causes the entire audio graph to crash.

Now audio works very well on Chrome with no pops or clicks.
2018-04-08 14:38:24 -07:00
Ernest Wong 8c20f02cc4 Add WorkletDAC to mixer immediately via output node 2018-04-08 14:38:24 -07:00
Ernest Wong bfc781f875 Separate DAC debug code, add debug code to worklet 2018-04-08 14:38:24 -07:00
Ernest Wong 3a7efe32b3 Add method of logging for audio worklet 2018-04-08 14:38:24 -07:00
Ernest Wong cec0670361 Implement speaker worklet
The pipeline for audio data when using the worklet now becomes:

 ________  request (4)  _____  request (3)  ______  request (2)  _________  request (1)  _________
|        |<------------|     |<------------|      |<------------|         |<------------|         |
| Memory |             | DMA |             | SB16 |             | Speaker |             | Worklet |
|________|------------>|_____|------------>|______|------------>|_________|------------>|_________|
            reply (5)           reply (6)            reply (7)               reply (8)

The responsibilities of the worklet is to:
 - Queue data at appropriate times (initiated by requests).
 - Convert the data from emulated sample rate to the web browser's
   sample rate.
 - Ultimately transfer the data into the Audio Rendering Thread.
2018-04-08 14:38:24 -07:00
Ernest Wong a7bb33e34c Minor: newlines 2018-04-08 14:38:24 -07:00
Ernest Wong 5721d5dae1 Revert "Reycle speaker AudioBuffers"
This reverts commit 3224a08568.
Memory profiles don't seem to show any significant improvement for the
added complexity.
2018-04-08 14:38:24 -07:00
Ernest Wong c6f9603c46 Reycle speaker AudioBuffers 2018-04-08 14:38:24 -07:00
Ernest Wong a0ddd56737 Minimise number of AudioNodes
Noticably improves performance in Chrome. This commit clumps several
GainNodes together, and avoids unecessary channel splitting and merging.
2018-04-08 14:38:24 -07:00
Ernest Wong cb3fd14901 Use compiler type casting instead of array hack 2018-04-08 14:38:24 -07:00
Ernest Wong 5b6e1d7a88 Make "both" consistent in speaker mixer API 2018-04-08 14:38:24 -07:00
Ernest Wong e52c48c101 Fix speaker mixer connect/disconnect channel logic 2018-04-08 14:38:24 -07:00
Ernest Wong 2de9ffac15 Fix speaker low-sample-rate converter
Previous code assumed rate_ratio = 2
2018-04-08 14:38:24 -07:00
Ernest Wong 7438f93b6d Refactor SpeakerAdapter
There were too many things happening under the same umbrella.
2018-04-08 14:38:24 -07:00
Ernest Wong d30d32f2e9 Add speaker debugging tools 2018-04-08 14:38:24 -07:00
Ernest Wong 41f313b7c5 Ensure sample rate is not too low
Some web browsers e.g. Firefox has yet to implement sample rate
conversion for rates less than 8000, and they are not required to by the
web standards
2018-04-08 14:38:24 -07:00
Ernest Wong 49482bf72c Fix: speaker queue - setTimeout is in milliseconds 2018-04-08 14:38:24 -07:00
Ernest Wong 43c3aa4842 Simplify: let speaker_adapter drive all timings
Previously:
 _____         ______         _________
|     | .->-. |      | .->-. |         |
| DMA | |   | | SB16 | |   | | Speaker |
|_____| '-<-' |______| '-<-' |_________|

- Speaker adapter regularly requests sb16.js to send audio samples
  immediately, until enough samples gets scheduled.

- SB16 continuously pulls data from DMA independently from Speaker until
  enough samples gets buffered.

- Due to timing issues, SB16 may not have enough data to reply to
  Speaker when Speaker asks for them.

Now:
 _____         ______         _________
|     | .->---|      |--->-. |         |
| DMA | |     | SB16 |     | | Speaker |
|_____| '-<---|______|---<-' |_________|

- Speaker still regularly requests SB16 to prepare new audio, but no
  longer expects a reply immediately.

- SB16 uses Speaker's requests to time its transfers from DMA
2018-04-08 14:38:24 -07:00
Ernest Wong 6d2c9f6c24 Use audiobuffers instead of scriptprocessor (speaker)
Fixes sample rate conversion problem.
Introduces new timing problems: to be fixed by letting speaker drive the
timings for dma.
Todo: reuse audio buffers - keep them in a pool.
2018-04-08 14:38:24 -07:00
Ernest Wong 3021bb5716 Tidy: typo in comment 2018-04-08 14:38:24 -07:00
Ernest Wong 40a1c3c70d Implement sb16 mixer chip + tidy up 2018-04-08 14:38:24 -07:00
Ernest Wong 4e0ffaa319 Reduce pcspeaker volume 2018-02-18 12:14:39 -06:00
Ernest Wong fe132cca62 Mute pcspeaker when emulator is paused 2018-02-18 12:14:39 -06:00
Ernest Wong 6e1908fe33 Clip pcspeaker frequency - ensure finite value
Non-finite values lead to exceptions, and values outside AudioParam's
nominal ranges lead to noisy warnings.
2018-02-18 12:14:39 -06:00
Ernest Wong 9fa0fcd9b2 Reduce audio processor overhead when paused
First attempt: when pausing, clear the output buffers once using .fill(0)
during the onaudioprocess event, and set a flag so that it doesn't
have to continuously .fill(0) the buffers when paused.

Problem with first attempt: It appears that performing .fill(0) once does
not guarantee clearing all the buffer that is given to the onaudioprocess
event, probably because the output buffers given are a subarray of a larger
buffer.

In this second attempt, we simply disconnect the processor node from the
destination node, and reconnect them when unpaused.
2017-12-16 22:51:40 -06:00
Ernest Wong 326ab8cf07 Schedule audio values instead of the .value setter
This is about the use of Web Audio API in the speaker adapter.

- Removes the compiler deprecation warning about removed dezippering.
  See https://www.chromestatus.com/feature/5287995770929152
- Setting the parameter using .value can be ignored if other automation
  events are scheduled.
  See https://developer.mozilla.org/en-US/docs/Web/API/AudioParam
2017-12-16 22:51:40 -06:00
Ernest Wong a185fd13bc Tidy up: spacing, quotes, and line length.
- Space before ? in ternary operators
- Double quotes ' -> "
- Line length of 100
2017-12-16 22:51:40 -06:00