ziqiangao commited on
Commit
ece5f12
·
verified ·
1 Parent(s): d5c5640

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -26
app.py CHANGED
@@ -19,32 +19,11 @@ import numpy as np
19
 
20
  path = "" # Update with your path
21
 
22
- # Cross-correlation function
23
- def cross_correlation(x, y):
24
- """
25
- Compute the cross-correlation of two signals.
26
- """
27
- n = len(x)
28
- correlation = np.correlate(x - np.mean(x), y - np.mean(y), mode='valid') / (n * np.std(x) * np.std(y))
29
- return correlation
30
-
31
- # Modified getTrigger function using cross-correlation
32
- def getTrigger(ad, a, ref_length=100, max=1024):
33
- """
34
- Find the trigger point in the audio signal using waveform correlation.
35
- """
36
- ref_signal = a[ad:ad + ref_length] # Reference signal segment
37
-
38
- max_corr = 0
39
- best_idx = ad
40
- for i in range(ad, ad+ref_length+max):
41
- #print(f"{i}, \t{ad},\t {len(a) - ref_length}")
42
- corr = cross_correlation(ref_signal, a[i:i + ref_length])
43
- if corr > max_corr:
44
- max_corr = corr
45
- best_idx = i
46
-
47
- return best_idx
48
 
49
  def getRenderCords(ta: list, idx: int, res: int = 1024, size: tuple = (1280, 720)) -> list:
50
  i = idx - res // 2
 
19
 
20
  path = "" # Update with your path
21
 
22
+ def getTrigger(ad: int, a: list, max: int = 1024) -> int:
23
+ i = ad
24
+ while not (a[i] < 128 and not a[i + 2] < 128 or i - ad > max):
25
+ i += 1
26
+ return i
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27
 
28
  def getRenderCords(ta: list, idx: int, res: int = 1024, size: tuple = (1280, 720)) -> list:
29
  i = idx - res // 2