Audio - cwtickle/danoniplus-docs GitHub Wiki
English | Japanese
| < Local storage specification | Audio Specification | Velocity change & Motions > |
Audio Specification
- Sound playback in Dancing Onigiri "CW Edition" uses Web Audio API as much as possible to minimize sound playback delay. However, there are cases where the Web Audio API specification does not allow for this. HTML Audio elements are used in some cases.
Patterns that support Web Audio API
- :heavy_check_mark: supported / :x: unsupported (Substitute with HTML Audio)
- To reduce playback delay both locally and remotely, it is faster to encode the music data in base64.
- js, txt format (with encoding) is the data encoded with the music data.
the Dan-Oni-Js music data conversion tool can create text data encoded with music files.
| mp3, ogg format | js, txt format (with encoding) | |
|---|---|---|
| Local file (How to open html directly) | :x: | :heavy_check_mark: |
| Local server (How to set up a server using Xampp) | :heavy_check_mark: | :heavy_check_mark: |
| Remote server (Uploaded and published on the Web) | :heavy_check_mark: | :heavy_check_mark: |
Limitations when using the Audio element in HTML
-
HTML Audio is more limited in functionality than the Web Audio API.
-
:heavy_check_mark: No issue / :warning: Some functions not available / :x: Not available
| Web Audio API | HTML Audio | |
|---|---|---|
| Displacement of chart position due to fade-in | :heavy_check_mark:No misalignment | :warning:May be shifted depending on the sound source |
| Volume setting | :heavy_check_mark:No issue | :heavy_check_mark: (Windows) No issue:x: (Mac / iPad) Always 100% |
| Fade-in volume | :heavy_check_mark:No issue | :heavy_check_mark: (Windows) No issue:x: (Mac / iPad) No fade-in |
| Fade-out volume | :heavy_check_mark:No issue | :heavy_check_mark: (Windows) No issue:x: (Mac / iPad) No fade-out |
| Decimal Adjustment | :heavy_check_mark:valid | :x:invalid |
Comparison
| Item | AudioPlayer Class | Standard Audio Instance |
|---|---|---|
| Internal Implementation | Custom class wrapping Web Audio API's AudioContext/AudioBufferSourceNode | Browser-standard HTMLAudioElement |
| Target Use | Encoded audio sources (.js/.txt, base64) | Standard audio files (URL specified, unencoded) |
| Audio Loading | Calls decodeAudioData via init(_arrayBuffer) to decode the buffer |
Sets URL to .src and waits for loadedmetadata event |
| Playback Start | play(_adjustmentTime): Schedules playback by adding g_scheduleLead + adjustment time to AudioContext.currentTime |
.play() (Standard API, immediate) |
| Stop | pause() stops the AudioBufferSourceNode (stop(0)), and close() destroys the node itself |
.pause() + resets via removeAttribute('src')/.load() |
Seeking (currentTime) |
Setting currentTime only updates _fadeinPosition; requires a restart via pause() -> play() to apply |
Can seek directly as a native property (also fires timeupdate event) |
| Elapsed Time Retrieval | elapsedTime getter: Calculated from the difference between AudioContext.currentTime and _scheduledTime (accounting for playbackRate, g_scheduleLead, and fade-in position) |
.currentTime (Managed by the browser) |
| Loop End & Interval Monitoring | Uses a poll function to monitor elapsedTime because the timeupdate event does not fire (repeatBGM) |
Determines via timeupdate event when currentTime >= musicEnd |
| Mute | Custom implementation switching _gain.gain.value between 0 and the saved value (retains volume via _savedVolume) |
Native .muted property |
| Other Interface Compatibility | Provides stub or custom implementations for addEventListener/removeEventListener/load/dispatchEvent, mimicking the Audio interface |
Native implementation |
Differences in how to start playing on iOS
- In the case of iOS, it is not possible to automatically play a music without user operation. For this reason, a start confirmation button is added just before the start only for iOS.
| < Local storage specification | Audio Specification | Velocity change & Motions > |