|
| 1 | +# Terry Feng - Google Summer of Code 2024 |
| 2 | + |
| 3 | +## Overview |
| 4 | +**Contributor**: Terry Feng ([@terryzfeng](https://github.com/terryzfeng)) <br> |
| 5 | +**Mentors**: Hongchan Choi ([@hoch](https://github.com/hoch)), |
| 6 | +Michael Wilson ([@mjwilson-google](https://github.com/mjwilson-google)) <br> |
| 7 | +**Organization**: Chromium - Web Audio Team <br> |
| 8 | +**Project(s)**: |
| 9 | +1. [Web Audio Test Suite](#web-audio-test-suite) |
| 10 | +2. [Rainfly: An AudioWorklet DSP Playground](#rainfly-an-audioworklet-dsp-playground) |
| 11 | + |
| 12 | +## Description |
| 13 | + |
| 14 | +This summer, I had the pleasure of working with the Chromium Web Audio Team on |
| 15 | +two projects: building a **Web Audio Test Suite** and creating **Rainfly: An AudioWorklet DSP Playground**. |
| 16 | +The Web Audio Test Suite enables Web Audio developers to write performance and |
| 17 | +benchmark tests for Web Audio, executing them locally in an interactive webpage |
| 18 | +or via the Playwright test framework for CI. Rainfly is an online IDE for writing |
| 19 | +and running `AudioWorklet` code in JavaScript and visualizing real-time |
| 20 | +`AudioContext` DSP output for analysis. |
| 21 | + |
| 22 | +## What I Did |
| 23 | + |
| 24 | +### Web Audio Test Suite |
| 25 | + |
| 26 | +GitHub: [Web Audio Test Suite](https://github.com/GoogleChromeLabs/web-audio-samples/tree/main/src/tests/playwright) |
| 27 | + |
| 28 | +1. The Web Audio Test Suite began with researching JavaScript testing frameworks |
| 29 | +for a lightweight solution offering browser JS executing and verification. We |
| 30 | +decided upon the [Playwright](https://playwright.dev) testing framework |
| 31 | +developed by Microsoft. The main reasons I found were: |
| 32 | + - Streamlined E2E testing and browser emulation (Chromium, Canary, Chrome) |
| 33 | + via CLI |
| 34 | + - The ability to write vanilla Web Audio JS and use Hooks and Promises |
| 35 | + to verify test logic |
| 36 | + - Minimal overhead for Web Audio performance benchmarking |
| 37 | + - CI via GitHub Actions |
| 38 | +2. I helped create a custom Web Audio test library (`audit.js`) that sandboxed |
| 39 | +test code for execution timing and evaluation code for logic verification. The |
| 40 | +challenge was to make everything as vanilla as possible while being compatible |
| 41 | +with the Playwright test framework. Challenges that we overcame include: |
| 42 | + - Creating the API with custom global test logic needed for arbitrary |
| 43 | + asynchronous JS execution and Web Audio verification |
| 44 | + - Finding appropriate thresholds for verifying "correct" `float32` samples |
| 45 | + generated by different machines, browsers, and architectures |
| 46 | + - Designing the writing experience of tests to be natural and intuitive for |
| 47 | + future developers |
| 48 | +3. After Playwright CLI testing, I worked with ([@kizjkre](https://github.com/kizjkre)) |
| 49 | +to build an interactive Live Suite webpage allowing for running Web Audio tests |
| 50 | +locally in the browser. |
| 51 | +4. I finally ported all of Web Audio's WPT tests into our Web Audio Test Suite |
| 52 | + |
| 53 | +### Rainfly: An AudioWorklet DSP Playground |
| 54 | + |
| 55 | +GitHub: *In Progress* |
| 56 | + |
| 57 | +1. Rainfly is a modern version of Hongchan's [Canopy](https://hoch.github.io/canopy/) |
| 58 | +project designed specifically for the `AudioWorklet` (AW) DSP paradigm. It aims |
| 59 | +to streamline the development of `AudioWorkletProcessor` DSP code, offering helpful |
| 60 | +visualization and analysis tools. [@kizjkre](https://github.com/kizjkre) and I |
| 61 | +created a [Figma](https://www.figma.com/proto/NrpvA1wwQNoc4hnKTAORIg/Rainfly?node-id=1-2&t=yNQPbNlEnX24i2MJ-0) |
| 62 | +prototype to capture and design ideas for the tools and features that an AW DSP |
| 63 | +playground could offer. |
| 64 | +2. I implemented Rainfly's code editor using [Monaco](https://microsoft.github.io/monaco-editor) |
| 65 | +and handled JS code preprocessing, execution, and sandboxing for |
| 66 | +`AudioWorkletProcessor` and `AudioContext` creation. I additionally created |
| 67 | +various [Svelte](https://svelte.dev) components to control audio host playback. |
| 68 | +3. Rainfly includes an internal AW audio recorder that captures PCM samples and |
| 69 | +streams them for visualization. To ensure this process was efficient and |
| 70 | +seamless for the user, I: |
| 71 | + - JS injected Rainfly's recorder node into the user's code just before |
| 72 | + `context.destination` |
| 73 | + - Efficiently handled real-time writing of millions of `process()` samples at |
| 74 | + audio rate while reading and rendering them using the Canvas API at graphics |
| 75 | + rate. |
| 76 | + |
| 77 | +## Code and PRs |
| 78 | + |
| 79 | +### Merged: |
| 80 | +- [Playwright MVP](https://github.com/GoogleChromeLabs/web-audio-samples/pull/372) |
| 81 | +- [Web Audio Test Suite Documentation](https://github.com/GoogleChromeLabs/web-audio-samples/pull/381) |
| 82 | +- [Port Web Audio Performance Tests from WPT](https://github.com/GoogleChromeLabs/web-audio-samples/pull/384) |
| 83 | + |
| 84 | +### Open PRs: |
| 85 | +- [Rainfly MVP](https://github.com/GoogleChromeLabs/web-audio-samples/pull/395) |
| 86 | + |
| 87 | +## Future Work |
| 88 | +- Web Audio Test Suite: Ensuring that developers are able to effectively write |
| 89 | +tests and benchmark Web Audio performance and functionality. |
| 90 | +- Rainfly: Merging and deploying the current PR and MVP of Rainfly to |
| 91 | +Web Audio Samples repository. |
| 92 | + - Later improvements to add: |
| 93 | + - Improving the visualizer by adding a time axis and sample pop-up on |
| 94 | + hover for numerical feedback |
| 95 | + - Smooth zooming in and out and scrolling left and right in the visualizer |
| 96 | + window |
| 97 | + |
| 98 | +## Reflections and Takeaways |
| 99 | + |
| 100 | +Working with my mentors Hongchan and Michael, I've learned a lot of best |
| 101 | +practices for writing easy-to-read code, communicating effectively during code |
| 102 | +review, and how to build projects effectively while navigating engineering, |
| 103 | +design, and architectural decisions. It was a great experience to practice these |
| 104 | +skills more, and my mentors were really supportive showing me the ropes. |
| 105 | + |
| 106 | +In laying the groundwork for the Web Audio Test Suite, it was challenging and |
| 107 | +quite tedious to spend time considering _all_ the current testing needs of the |
| 108 | +team, finding good solutions to benchmark and analyze the performance of real-time |
| 109 | +audio (this was harder than I thought), and to build a test framework |
| 110 | +flexible enough for future use cases. This required extensive research to implement |
| 111 | +an all-in-one API balancing tools, technologies, and code. However, this project |
| 112 | +was extremely successful and will be beneficial for future Web Audio |
| 113 | +testing |
| 114 | + |
| 115 | +In working on Rainfly, I got the chance to learn and use a JS framework for the |
| 116 | +first time (Svelte), make stylistic and creative UI/UX decisions for a "cute" IDE, |
| 117 | +and implement important AW tooling for writing custom DSP code. This leveraged |
| 118 | +a lot of my skills beyond pure software engineering which was fun, rigorous, |
| 119 | +imaginative, and rewarding. |
| 120 | + |
| 121 | +Overall I'd like to thank my mentors Hongchan Choi and Michael Wilson, my |
| 122 | +fellow summer partner in crime and Web Audio GSoC contributor [@kizjkre](https://github.com/kizjkre), |
| 123 | +and look forward to seeing my project work this summer being used internally |
| 124 | +and externally for Web Audio developers. I hope to continue contributing to the |
| 125 | +Chromium organization and the Web Audio project in the near future! |
0 commit comments