@open-artifact/motion-audio 0.0.0-stage → 0.12.0-rc.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/NOTICE +5 -0
- package/README.md +5 -2
- package/package.json +38 -4
- package/src/index.d.ts +46 -0
- package/src/index.js +25 -0
- package/src/keepalive.d.ts +10 -0
- package/src/keepalive.js +49 -0
- package/src/loudness.d.ts +32 -0
- package/src/loudness.js +108 -0
- package/src/midi.d.ts +16 -0
- package/src/midi.js +179 -0
- package/src/mixer.d.ts +29 -0
- package/src/mixer.js +70 -0
- package/src/narration/captions.d.ts +24 -0
- package/src/narration/captions.js +45 -0
- package/src/narration/decode.d.ts +25 -0
- package/src/narration/decode.js +72 -0
- package/src/narration/duck.d.ts +20 -0
- package/src/narration/duck.js +34 -0
- package/src/narration/limits.d.ts +23 -0
- package/src/narration/limits.js +16 -0
- package/src/narration/peaks.d.ts +14 -0
- package/src/narration/peaks.js +27 -0
- package/src/narration/plan.d.ts +12 -0
- package/src/narration/plan.js +31 -0
- package/src/narration/speech.d.ts +31 -0
- package/src/narration/speech.js +24 -0
- package/src/offline.d.ts +79 -0
- package/src/offline.js +257 -0
- package/src/playback-clock.d.ts +39 -0
- package/src/playback-clock.js +90 -0
- package/src/played-score.d.ts +28 -0
- package/src/played-score.js +31 -0
- package/src/player.d.ts +47 -0
- package/src/player.js +237 -0
- package/src/reverb.d.ts +10 -0
- package/src/reverb.js +38 -0
- package/src/scheduler.d.ts +29 -0
- package/src/scheduler.js +64 -0
- package/src/session.d.ts +24 -0
- package/src/session.js +133 -0
- package/src/synth/drums.d.ts +4 -0
- package/src/synth/drums.js +97 -0
- package/src/synth/envelope.d.ts +26 -0
- package/src/synth/envelope.js +39 -0
- package/src/synth/fx.d.ts +9 -0
- package/src/synth/fx.js +131 -0
- package/src/synth/nodes.d.ts +22 -0
- package/src/synth/nodes.js +63 -0
- package/src/synth/noise.d.ts +6 -0
- package/src/synth/noise.js +31 -0
- package/src/synth/patches.d.ts +5 -0
- package/src/synth/patches.js +119 -0
- package/src/synth/presets.d.ts +32 -0
- package/src/synth/presets.js +136 -0
- package/src/synth/schedule.d.ts +5 -0
- package/src/synth/schedule.js +25 -0
- package/src/synth/voice.d.ts +35 -0
- package/src/synth/voice.js +52 -0
- package/src/timeline.d.ts +25 -0
- package/src/timeline.js +49 -0
- package/src/wave.d.ts +17 -0
- package/src/wave.js +111 -0
- package/src/window.d.ts +32 -0
- package/src/window.js +59 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/NOTICE
ADDED
package/README.md
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @open-artifact/motion-audio
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The Motion type's sound: the score synthesizer and mixer (WebAudio), narration playback with ducking, loudness normalization, scheduling and offline rendering for export, and the score as a MIDI file.
|
|
4
|
+
|
|
5
|
+
Part of [Open Artifact](https://github.com/JimLiu/open-artifact): slide decks, design canvases and whiteboards an agent makes
|
|
6
|
+
and you view, edit and comment on in one local page. Source: [`packages/motion-audio`](https://github.com/JimLiu/open-artifact/tree/main/packages/motion-audio).
|
package/package.json
CHANGED
|
@@ -1,6 +1,40 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@open-artifact/motion-audio",
|
|
3
|
-
"version": "0.0.0
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.12.0-rc.0",
|
|
4
|
+
"description": "The Motion type's sound: the score synthesizer and mixer (WebAudio), narration playback with ducking, loudness normalization, scheduling and offline rendering for export, and the score as a MIDI file.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": {
|
|
8
|
+
"types": "./src/index.d.ts",
|
|
9
|
+
"default": "./src/index.js"
|
|
10
|
+
},
|
|
11
|
+
"./package.json": "./package.json"
|
|
12
|
+
},
|
|
13
|
+
"files": [
|
|
14
|
+
"src",
|
|
15
|
+
"LICENSE",
|
|
16
|
+
"NOTICE"
|
|
17
|
+
],
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"@open-artifact/motion-core": "0.12.0-rc.0"
|
|
20
|
+
},
|
|
21
|
+
"license": "Apache-2.0",
|
|
22
|
+
"author": {
|
|
23
|
+
"name": "Jim Liu 宝玉",
|
|
24
|
+
"url": "https://github.com/JimLiu"
|
|
25
|
+
},
|
|
26
|
+
"homepage": "https://github.com/JimLiu/open-artifact#readme",
|
|
27
|
+
"repository": {
|
|
28
|
+
"type": "git",
|
|
29
|
+
"url": "git+https://github.com/JimLiu/open-artifact.git",
|
|
30
|
+
"directory": "packages/motion-audio"
|
|
31
|
+
},
|
|
32
|
+
"bugs": {
|
|
33
|
+
"url": "https://github.com/JimLiu/open-artifact/issues"
|
|
34
|
+
},
|
|
35
|
+
"publishConfig": {
|
|
36
|
+
"access": "public",
|
|
37
|
+
"tag": "next"
|
|
38
|
+
},
|
|
39
|
+
"gitHead": "ac158a48a1e61fbbdd71f0f6e33ee9bdb24fd35f"
|
|
40
|
+
}
|
package/src/index.d.ts
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
export { identityTimeline, segmentTimeline } from './timeline.ts';
|
|
2
|
+
export type { FilmTimeline, TimelineSegment } from './timeline.ts';
|
|
3
|
+
export { MAX_EVENT_SECONDS, SILENT_MASTER, playScore } from './played-score.ts';
|
|
4
|
+
export type { PlayedScore, PlayedSound } from './played-score.ts';
|
|
5
|
+
export { DRUM_ALIASES, DRUM_PRESETS, FX_ALIASES, FX_PRESETS, PATCH_ALIASES, PATCH_PRESETS, resolvePatch, ringSeconds, soundExtent, } from './synth/presets.ts';
|
|
6
|
+
export type { PatchPreset, ResolvedPatch } from './synth/presets.ts';
|
|
7
|
+
export { MAX_SOUND_SECONDS, decibelsToGain, midiToFrequency, readVoiceSettings, velocityToGain, voiceGain, voiceOf } from './synth/voice.ts';
|
|
8
|
+
export type { Sound, Voice, VoiceSettings } from './synth/voice.ts';
|
|
9
|
+
export { adsrEnd, adsrLevelAt, adsrReleaseAt } from './synth/envelope.ts';
|
|
10
|
+
export type { AdsrShape, DecayShape } from './synth/envelope.ts';
|
|
11
|
+
export { seededRandom } from './synth/noise.ts';
|
|
12
|
+
export { scheduleSound } from './synth/schedule.ts';
|
|
13
|
+
export type { VoiceBus, VoiceOutput } from './synth/nodes.ts';
|
|
14
|
+
export { createMasterBus, fadeLevel, masterGain, softClipCurve } from './mixer.ts';
|
|
15
|
+
export type { MasterBus } from './mixer.ts';
|
|
16
|
+
export { REVERB_SECONDS, reverbImpulseSamples } from './reverb.ts';
|
|
17
|
+
export { createScoreSession } from './session.ts';
|
|
18
|
+
export type { ScoreSession, SessionOptions } from './session.ts';
|
|
19
|
+
export { DEFAULT_TARGET_LUFS, MAX_NORMALIZATION_DB, MAX_NORMALIZED_PEAK, loudnessGain, measureIntegratedLoudness, sampleLevels, } from './loudness.ts';
|
|
20
|
+
export type { AudioLevel, LoudnessMeasurement, PcmSource } from './loudness.ts';
|
|
21
|
+
export { encodePcmWave, interleave, parsePcmWave } from './wave.ts';
|
|
22
|
+
export type { PcmWave } from './wave.ts';
|
|
23
|
+
export { DEFAULT_MIDI_TITLE, MIDI_TICKS_PER_BEAT, toMidi } from './midi.ts';
|
|
24
|
+
export type { MidiOptions } from './midi.ts';
|
|
25
|
+
export { LOOKAHEAD_SECONDS, SCHEDULER_INTERVAL_MS, START_DELAY_SECONDS, contextTimeOf, dueSounds, firstHeard, heardFrom, lookaheadHorizon, passOrigin, playTimeAt, } from './window.ts';
|
|
26
|
+
export { startScorePass } from './scheduler.ts';
|
|
27
|
+
export type { ScorePass, ScorePassOptions, SchedulerTimers } from './scheduler.ts';
|
|
28
|
+
export { DEFAULT_NARRATION_LIMITS } from './narration/limits.ts';
|
|
29
|
+
export type { NarrationLimits } from './narration/limits.ts';
|
|
30
|
+
export { clipCaption, planNarration } from './narration/plan.ts';
|
|
31
|
+
export type { NarrationPlan } from './narration/plan.ts';
|
|
32
|
+
export { DUCK_ATTACK_SECONDS, DUCK_RELEASE_SECONDS, duckEnvelope, sampleEnvelope } from './narration/duck.ts';
|
|
33
|
+
export type { DuckPoint } from './narration/duck.ts';
|
|
34
|
+
export { voicePeaks } from './narration/peaks.ts';
|
|
35
|
+
export { placeSpeech } from './narration/speech.ts';
|
|
36
|
+
export type { DecodedNarration, Speech, SpeechClip, TakeIssue } from './narration/speech.ts';
|
|
37
|
+
export { decodeNarration, judgeTakeBytes, judgeTakeSeconds } from './narration/decode.ts';
|
|
38
|
+
export type { DecodeOptions, TakeDecoder } from './narration/decode.ts';
|
|
39
|
+
export { captionCues, cueAt, voiceoverLines } from './narration/captions.ts';
|
|
40
|
+
export type { CaptionCue, VoiceoverLine } from './narration/captions.ts';
|
|
41
|
+
export { DEFAULT_SAMPLE_RATE, filmSound, knownScoreGain, measureScoreGain, measureSpeechGain, renderFilmAudio, } from './offline.ts';
|
|
42
|
+
export type { FilmAudioRender, FilmSound, FilmSoundInput, RenderOptions } from './offline.ts';
|
|
43
|
+
export { audioClockSource, createVisibleClock, wallClockSource } from './playback-clock.ts';
|
|
44
|
+
export type { PlaybackTimeSource, VisibleClock } from './playback-clock.ts';
|
|
45
|
+
export { FilmSoundPlayer } from './player.ts';
|
|
46
|
+
export type { FilmSoundPlayerOptions, SoundPlayerState } from './player.ts';
|
package/src/index.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export { identityTimeline, segmentTimeline } from "./timeline.js";
|
|
2
|
+
export { MAX_EVENT_SECONDS, SILENT_MASTER, playScore } from "./played-score.js";
|
|
3
|
+
export { DRUM_ALIASES, DRUM_PRESETS, FX_ALIASES, FX_PRESETS, PATCH_ALIASES, PATCH_PRESETS, resolvePatch, ringSeconds, soundExtent, } from "./synth/presets.js";
|
|
4
|
+
export { MAX_SOUND_SECONDS, decibelsToGain, midiToFrequency, readVoiceSettings, velocityToGain, voiceGain, voiceOf } from "./synth/voice.js";
|
|
5
|
+
export { adsrEnd, adsrLevelAt, adsrReleaseAt } from "./synth/envelope.js";
|
|
6
|
+
export { seededRandom } from "./synth/noise.js";
|
|
7
|
+
export { scheduleSound } from "./synth/schedule.js";
|
|
8
|
+
export { createMasterBus, fadeLevel, masterGain, softClipCurve } from "./mixer.js";
|
|
9
|
+
export { REVERB_SECONDS, reverbImpulseSamples } from "./reverb.js";
|
|
10
|
+
export { createScoreSession } from "./session.js";
|
|
11
|
+
export { DEFAULT_TARGET_LUFS, MAX_NORMALIZATION_DB, MAX_NORMALIZED_PEAK, loudnessGain, measureIntegratedLoudness, sampleLevels, } from "./loudness.js";
|
|
12
|
+
export { encodePcmWave, interleave, parsePcmWave } from "./wave.js";
|
|
13
|
+
export { DEFAULT_MIDI_TITLE, MIDI_TICKS_PER_BEAT, toMidi } from "./midi.js";
|
|
14
|
+
export { LOOKAHEAD_SECONDS, SCHEDULER_INTERVAL_MS, START_DELAY_SECONDS, contextTimeOf, dueSounds, firstHeard, heardFrom, lookaheadHorizon, passOrigin, playTimeAt, } from "./window.js";
|
|
15
|
+
export { startScorePass } from "./scheduler.js";
|
|
16
|
+
export { DEFAULT_NARRATION_LIMITS } from "./narration/limits.js";
|
|
17
|
+
export { clipCaption, planNarration } from "./narration/plan.js";
|
|
18
|
+
export { DUCK_ATTACK_SECONDS, DUCK_RELEASE_SECONDS, duckEnvelope, sampleEnvelope } from "./narration/duck.js";
|
|
19
|
+
export { voicePeaks } from "./narration/peaks.js";
|
|
20
|
+
export { placeSpeech } from "./narration/speech.js";
|
|
21
|
+
export { decodeNarration, judgeTakeBytes, judgeTakeSeconds } from "./narration/decode.js";
|
|
22
|
+
export { captionCues, cueAt, voiceoverLines } from "./narration/captions.js";
|
|
23
|
+
export { DEFAULT_SAMPLE_RATE, filmSound, knownScoreGain, measureScoreGain, measureSpeechGain, renderFilmAudio, } from "./offline.js";
|
|
24
|
+
export { audioClockSource, createVisibleClock, wallClockSource } from "./playback-clock.js";
|
|
25
|
+
export { FilmSoundPlayer } from "./player.js";
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* On iPhone and iPad, WebAudio follows the ring/silent switch unless a media element plays too. A looped half second of
|
|
3
|
+
* silence in an audio element, playing while sound should be heard and the page is in view, keeps the film audible.
|
|
4
|
+
*/
|
|
5
|
+
export interface AudioKeepalive {
|
|
6
|
+
set(audible: boolean): void;
|
|
7
|
+
dispose(): void;
|
|
8
|
+
}
|
|
9
|
+
export declare function isAppleTouchDevice(): boolean;
|
|
10
|
+
export declare function createAudioKeepalive(context: BaseAudioContext): AudioKeepalive | null;
|
package/src/keepalive.js
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { encodePcmWave } from "./wave.js";
|
|
2
|
+
export function isAppleTouchDevice() {
|
|
3
|
+
return (typeof navigator !== 'undefined' &&
|
|
4
|
+
(/iPad|iPhone|iPod/.test(navigator.userAgent) || (navigator.platform === 'MacIntel' && navigator.maxTouchPoints > 1)));
|
|
5
|
+
}
|
|
6
|
+
export function createAudioKeepalive(context) {
|
|
7
|
+
if (!isAppleTouchDevice() || typeof Audio === 'undefined' || typeof document === 'undefined')
|
|
8
|
+
return null;
|
|
9
|
+
let element = null;
|
|
10
|
+
let url = '';
|
|
11
|
+
let wanted = false;
|
|
12
|
+
const elementFor = () => {
|
|
13
|
+
if (element !== null)
|
|
14
|
+
return element;
|
|
15
|
+
const silence = context.createBuffer(1, Math.round(context.sampleRate / 2), context.sampleRate);
|
|
16
|
+
url = URL.createObjectURL(new Blob([encodePcmWave(silence)], { type: 'audio/wav' }));
|
|
17
|
+
element = new Audio(url);
|
|
18
|
+
element.loop = true;
|
|
19
|
+
element.disableRemotePlayback = true;
|
|
20
|
+
return element;
|
|
21
|
+
};
|
|
22
|
+
const update = () => {
|
|
23
|
+
if (wanted && !document.hidden) {
|
|
24
|
+
const playing = elementFor();
|
|
25
|
+
if (playing.paused)
|
|
26
|
+
playing.play().catch(() => undefined);
|
|
27
|
+
}
|
|
28
|
+
else if (element !== null && !element.paused)
|
|
29
|
+
element.pause();
|
|
30
|
+
};
|
|
31
|
+
document.addEventListener('visibilitychange', update);
|
|
32
|
+
return {
|
|
33
|
+
set(audible) {
|
|
34
|
+
wanted = audible;
|
|
35
|
+
update();
|
|
36
|
+
},
|
|
37
|
+
dispose() {
|
|
38
|
+
document.removeEventListener('visibilitychange', update);
|
|
39
|
+
wanted = false;
|
|
40
|
+
if (element === null)
|
|
41
|
+
return;
|
|
42
|
+
element.pause();
|
|
43
|
+
element.removeAttribute('src');
|
|
44
|
+
element.load();
|
|
45
|
+
URL.revokeObjectURL(url);
|
|
46
|
+
element = null;
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/** The parts of a decoded buffer the meter and the PCM writers read, so plain arrays can stand in for one. */
|
|
2
|
+
export type PcmSource = Pick<AudioBuffer, 'sampleRate' | 'length' | 'numberOfChannels' | 'getChannelData'>;
|
|
3
|
+
export interface LoudnessMeasurement {
|
|
4
|
+
/** Integrated loudness (BS.1770, gated); −Infinity for silence. */
|
|
5
|
+
readonly lufs: number;
|
|
6
|
+
/** The largest sample, as a gain. */
|
|
7
|
+
readonly peak: number;
|
|
8
|
+
}
|
|
9
|
+
export declare const DEFAULT_TARGET_LUFS = -16;
|
|
10
|
+
/** No target is louder than this. */
|
|
11
|
+
export declare const LOUDEST_TARGET_LUFS = -6;
|
|
12
|
+
/** Normalization raises a quiet score by this much at most. */
|
|
13
|
+
export declare const MAX_NORMALIZATION_DB = 14;
|
|
14
|
+
/** Nor so far that its peak passes this; the limiter and clipper take what is over full scale. */
|
|
15
|
+
export declare const MAX_NORMALIZED_PEAK = 2.5;
|
|
16
|
+
/** Nor lowers it below this gain. */
|
|
17
|
+
export declare const LEAST_NORMALIZATION_GAIN = 0.05;
|
|
18
|
+
/** Integrated loudness over 400 ms blocks every 100 ms, gated at −70 LUFS and then 10 LU under the mean. */
|
|
19
|
+
export declare function measureIntegratedLoudness(buffer: PcmSource): LoudnessMeasurement;
|
|
20
|
+
/**
|
|
21
|
+
* The gain that brings a measured sound to `target` LUFS (the default when undefined, none when null), within the
|
|
22
|
+
* normalization's bounds and the peak's room.
|
|
23
|
+
*/
|
|
24
|
+
export declare function loudnessGain(measurement: LoudnessMeasurement, target: number | null | undefined): number;
|
|
25
|
+
export interface AudioLevel {
|
|
26
|
+
/** Seconds from the buffer's start. */
|
|
27
|
+
readonly t: number;
|
|
28
|
+
readonly peak: number;
|
|
29
|
+
readonly rms: number;
|
|
30
|
+
}
|
|
31
|
+
/** Peak and RMS over every `intervalSeconds`, across all channels. */
|
|
32
|
+
export declare function sampleLevels(buffer: PcmSource, intervalSeconds?: number): AudioLevel[];
|
package/src/loudness.js
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
export const DEFAULT_TARGET_LUFS = -16;
|
|
2
|
+
/** No target is louder than this. */
|
|
3
|
+
export const LOUDEST_TARGET_LUFS = -6;
|
|
4
|
+
/** Normalization raises a quiet score by this much at most. */
|
|
5
|
+
export const MAX_NORMALIZATION_DB = 14;
|
|
6
|
+
/** Nor so far that its peak passes this; the limiter and clipper take what is over full scale. */
|
|
7
|
+
export const MAX_NORMALIZED_PEAK = 2.5;
|
|
8
|
+
/** Nor lowers it below this gain. */
|
|
9
|
+
export const LEAST_NORMALIZATION_GAIN = 0.05;
|
|
10
|
+
/** K-weighting's two biquads (high shelf, then high pass) as b0, b1, b2, a1, a2, for 48 kHz. */
|
|
11
|
+
const SHELF = [1.53512485958697, -2.69169618940638, 1.19839281085285, -1.69065929318241, 0.73248077421585];
|
|
12
|
+
const HIGH_PASS = [1, -2, 1, -1.99004745483398, 0.99007225036621];
|
|
13
|
+
const BLOCK_SECONDS = 0.4;
|
|
14
|
+
const STEP_SECONDS = 0.1;
|
|
15
|
+
const ABSOLUTE_GATE_LUFS = -70;
|
|
16
|
+
const RELATIVE_GATE_LU = 10;
|
|
17
|
+
const energyLufs = (energy) => -0.691 + 10 * Math.log10(Math.max(energy, 1e-12));
|
|
18
|
+
const mean = (values) => values.reduce((sum, value) => sum + value, 0) / Math.max(1, values.length);
|
|
19
|
+
/** Integrated loudness over 400 ms blocks every 100 ms, gated at −70 LUFS and then 10 LU under the mean. */
|
|
20
|
+
export function measureIntegratedLoudness(buffer) {
|
|
21
|
+
const blockFrames = Math.round(BLOCK_SECONDS * buffer.sampleRate);
|
|
22
|
+
const stepFrames = Math.round(STEP_SECONDS * buffer.sampleRate);
|
|
23
|
+
const blockCount = Math.max(0, Math.floor((buffer.length - blockFrames) / stepFrames) + 1);
|
|
24
|
+
const blockEnergies = new Float64Array(blockCount);
|
|
25
|
+
const energyAtBlockStart = new Float64Array(blockCount);
|
|
26
|
+
const [s0, s1, s2, sa1, sa2] = SHELF;
|
|
27
|
+
const [h0, h1, h2, ha1, ha2] = HIGH_PASS;
|
|
28
|
+
let peak = 0;
|
|
29
|
+
for (let channel = 0; channel < buffer.numberOfChannels; channel++) {
|
|
30
|
+
const samples = buffer.getChannelData(channel);
|
|
31
|
+
let shelfIn1 = 0;
|
|
32
|
+
let shelfIn2 = 0;
|
|
33
|
+
let shelfOut1 = 0;
|
|
34
|
+
let shelfOut2 = 0;
|
|
35
|
+
let passIn1 = 0;
|
|
36
|
+
let passIn2 = 0;
|
|
37
|
+
let passOut1 = 0;
|
|
38
|
+
let passOut2 = 0;
|
|
39
|
+
let energy = 0;
|
|
40
|
+
let nextStart = 0;
|
|
41
|
+
let nextEnd = 0;
|
|
42
|
+
for (let frame = 0; frame < samples.length; frame++) {
|
|
43
|
+
if (nextStart < blockCount && frame === nextStart * stepFrames)
|
|
44
|
+
energyAtBlockStart[nextStart++] = energy;
|
|
45
|
+
const sample = samples[frame];
|
|
46
|
+
const size = Math.abs(sample);
|
|
47
|
+
if (size > peak)
|
|
48
|
+
peak = size;
|
|
49
|
+
const shelved = s0 * sample + s1 * shelfIn1 + s2 * shelfIn2 - sa1 * shelfOut1 - sa2 * shelfOut2;
|
|
50
|
+
shelfIn2 = shelfIn1;
|
|
51
|
+
shelfIn1 = sample;
|
|
52
|
+
shelfOut2 = shelfOut1;
|
|
53
|
+
shelfOut1 = shelved;
|
|
54
|
+
// The filters run in single precision between stages, as a Float32 pipeline would.
|
|
55
|
+
const shelvedSingle = Math.fround(shelved);
|
|
56
|
+
const passed = h0 * shelvedSingle + h1 * passIn1 + h2 * passIn2 - ha1 * passOut1 - ha2 * passOut2;
|
|
57
|
+
passIn2 = passIn1;
|
|
58
|
+
passIn1 = shelvedSingle;
|
|
59
|
+
passOut2 = passOut1;
|
|
60
|
+
passOut1 = passed;
|
|
61
|
+
const weighted = Math.fround(passed);
|
|
62
|
+
energy += weighted * weighted;
|
|
63
|
+
if (nextEnd < blockCount && frame + 1 === nextEnd * stepFrames + blockFrames) {
|
|
64
|
+
blockEnergies[nextEnd] += (energy - energyAtBlockStart[nextEnd]) / blockFrames;
|
|
65
|
+
nextEnd++;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
const loudBlocks = Array.from(blockEnergies).filter((energy) => energyLufs(energy) > ABSOLUTE_GATE_LUFS);
|
|
70
|
+
if (loudBlocks.length === 0)
|
|
71
|
+
return { lufs: -Infinity, peak };
|
|
72
|
+
const relativeGate = energyLufs(mean(loudBlocks)) - RELATIVE_GATE_LU;
|
|
73
|
+
const gated = loudBlocks.filter((energy) => energyLufs(energy) > relativeGate);
|
|
74
|
+
return { lufs: energyLufs(mean(gated)), peak };
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* The gain that brings a measured sound to `target` LUFS (the default when undefined, none when null), within the
|
|
78
|
+
* normalization's bounds and the peak's room.
|
|
79
|
+
*/
|
|
80
|
+
export function loudnessGain(measurement, target) {
|
|
81
|
+
if (target === null || !Number.isFinite(measurement.lufs))
|
|
82
|
+
return 1;
|
|
83
|
+
const wanted = Math.pow(10, (Math.min(LOUDEST_TARGET_LUFS, target ?? DEFAULT_TARGET_LUFS) - measurement.lufs) / 20);
|
|
84
|
+
const peakRoom = measurement.peak > 0 ? MAX_NORMALIZED_PEAK / measurement.peak : Infinity;
|
|
85
|
+
return Math.max(LEAST_NORMALIZATION_GAIN, Math.min(wanted, Math.pow(10, MAX_NORMALIZATION_DB / 20), peakRoom));
|
|
86
|
+
}
|
|
87
|
+
/** Peak and RMS over every `intervalSeconds`, across all channels. */
|
|
88
|
+
export function sampleLevels(buffer, intervalSeconds = 0.5) {
|
|
89
|
+
const channels = Array.from({ length: buffer.numberOfChannels }, (_unused, index) => buffer.getChannelData(index));
|
|
90
|
+
const intervalFrames = Math.max(1, Math.round(buffer.sampleRate * intervalSeconds));
|
|
91
|
+
const levels = [];
|
|
92
|
+
for (let start = 0; start < buffer.length; start += intervalFrames) {
|
|
93
|
+
const end = Math.min(buffer.length, start + intervalFrames);
|
|
94
|
+
let peak = 0;
|
|
95
|
+
let squares = 0;
|
|
96
|
+
let count = 0;
|
|
97
|
+
for (const samples of channels) {
|
|
98
|
+
for (let frame = start; frame < end; frame++) {
|
|
99
|
+
const sample = samples[frame] ?? 0;
|
|
100
|
+
peak = Math.max(peak, Math.abs(sample));
|
|
101
|
+
squares += sample * sample;
|
|
102
|
+
count++;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
levels.push({ t: start / buffer.sampleRate, peak, rms: Math.sqrt(squares / Math.max(1, count)) });
|
|
106
|
+
}
|
|
107
|
+
return levels;
|
|
108
|
+
}
|
package/src/midi.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A score as a Standard MIDI File (format 1, 480 ticks a beat): a conductor
|
|
3
|
+
* track with the tempo and where film time 0 falls, a track per patch with
|
|
4
|
+
* its General MIDI program, and the drums and effects on channel 10.
|
|
5
|
+
* Bells play as the notes they ring; a reverse swell lands where it is first
|
|
6
|
+
* heard. The score's tempo sets the beat, so its bars line up in a DAW.
|
|
7
|
+
*/
|
|
8
|
+
import type { ScoreData } from '@open-artifact/motion-core';
|
|
9
|
+
export declare const MIDI_TICKS_PER_BEAT = 480;
|
|
10
|
+
export declare const DEFAULT_MIDI_TITLE = "animation score";
|
|
11
|
+
export interface MidiOptions {
|
|
12
|
+
/** The conductor track's name (default "animation score"). */
|
|
13
|
+
title?: string;
|
|
14
|
+
}
|
|
15
|
+
/** The score as a Standard MIDI File. */
|
|
16
|
+
export declare function toMidi(score: ScoreData, options?: MidiOptions): Uint8Array<ArrayBuffer>;
|