You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+165-21
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,7 @@
1
1
# `synaudio`
2
2
3
-
`synaudio` is a JavaScript library that finds the synchronization point between two similar audio clips.
4
-
* Synchronize two audio clips by finding the sample offset with the [Pearson correlation coefficient](https://en.wikipedia.org/wiki/Pearson_correlation_coefficient).
3
+
`synaudio` is a JavaScript library that finds the synchronization points between two or more similar audio clips.
4
+
* Synchronize two or more audio clips by finding the sample offsets with the [Pearson correlation coefficient](https://en.wikipedia.org/wiki/Pearson_correlation_coefficient).
5
5
* Correlation algorithm implemented as WebAssembly SIMD.
6
6
* Built in Web Worker implementations for concurrency.
7
7
@@ -34,7 +34,11 @@
34
34
});
35
35
```
36
36
37
-
1. Call the `sync`, `syncWorker`, or `syncWorkerConcurrent` method on the instance to find the synchronization point in samples between two audio clips.
37
+
### Sync Two Clips
38
+
39
+
SynAudio can synchronize two clips: one base and one comparison. The comparison clip must be a subset of the base clip in order for there to be a valid match. If you don't know the ordering of the clips, see [Sync Multiple Clips](#sync-multiple-clips)
40
+
41
+
* Call the `sync`, `syncWorker`, or `syncWorkerConcurrent` method on the instance to find the synchronization point in samples between two audio clips.
38
42
39
43
* See the [API](#api) section below for details on these methods.
40
44
@@ -55,17 +59,93 @@
55
59
sampleOffset, // position relative to `base` where `comparison` matches best
56
60
correlation, // covariance coefficient of the match [ ranging -1 (worst) to 1 (best) ]
57
61
} =awaitsynAudio.syncWorkerConcurrent(
58
-
base, // audio data to use a base for the comparison
59
-
comparison, // audio data to compare against the base
60
-
4// number of threads to spawn
62
+
base, // audio data to use a base for the comparison
63
+
comparison, // audio data to compare against the base
64
+
4// number of threads to spawn
65
+
);
66
+
```
67
+
68
+
### Sync Multiple Clips
69
+
70
+
`syncMultiple` will find the best linear match(es) between a set of two or more clips. Internally, SynAudio will determine the correlation of every order combination of each clip and then will find the path(s) in this graph where the correlation is the highest.
71
+
72
+
* Call the `syncMultiple` method on the instance to find the best synchronization path between two or more audio clips.
* The `results` object will contain a two dimensional array of of match groups containing matching clips. Each match group represents an ordered list of matching audio clips where each clip relates to the previous. The sample offset within each match group is relative to the first clip in the series.
107
+
* In the below example, there are two match groups with the first group containing three clips, and the second containing two clips. There was no significant correlation _(no correlation >= `options.correlationThreshold`)_ found between the clips in the two match groups. If a clip were to exist that relates the two groups together, then the result would contain only one match group, and relate all other clips to the first one in sequential order.
108
+
109
+
```js
110
+
// results example
111
+
[
112
+
// first match group (no relation to second group)
113
+
[
114
+
{
115
+
name:"cut_1601425_Mpeg", // first clip in match
116
+
sampleOffset:0,
117
+
},
118
+
{
119
+
name:"cut_2450800_Mpeg",
120
+
correlation:0.9846370220184326,
121
+
sampleOffset:849375, // position where this clip starts relative to the first clip
122
+
},
123
+
{
124
+
name:"cut_2577070_Mpeg",
125
+
correlation:0.9878544973345423,
126
+
sampleOffset:975645, // position where this clip starts relative to the first clip
127
+
},
128
+
],
129
+
// second match group (no relation to first group)
130
+
[
131
+
{
132
+
name:"cut_194648_Mpeg",
133
+
sampleOffset:0,
134
+
},
135
+
{
136
+
name:"cut_287549_Mpeg",
137
+
correlation:0.9885798096656799,
138
+
sampleOffset:92901, // position where this clip starts relative to the first clip
139
+
},
140
+
]
141
+
]
142
+
```
143
+
64
144
## API
65
145
66
146
## `SynAudio`
67
147
68
-
Class that that finds the synchronization point between two similar audio clips.
148
+
Class that that finds the synchronization point between two or more similar audio clips.
69
149
70
150
```js
71
151
newSynAudio({
@@ -79,6 +159,7 @@ new SynAudio({
79
159
declareinterfaceSynAudioOptions {
80
160
correlationSampleSize?:number; // default 11025
81
161
initialGranularity?:number; // default 16
162
+
correlationThreshold?:number; // default 0.5
82
163
}
83
164
```
84
165
*`correlationSampleSize`*optional, defaults to 11025*
0 commit comments