Przeglądaj źródła

toolbox logo looks acceptable now

Thomas Buck 10 miesięcy temu
rodzic
commit
23b118c6d7
2 zmienionych plików z 32 dodań i 7 usunięć
  1. 27
    3
      render.py
  2. 5
    4
      toolbox.svg

+ 27
- 3
render.py Wyświetl plik

@@ -2,6 +2,9 @@
2 2
 
3 3
 # Render image to Oscilloscope XY vector audio
4 4
 #
5
+# https://pypi.org/project/svgpathtools/
6
+# https://dood.al/oscilloscope/
7
+#
5 8
 # ----------------------------------------------------------------------------
6 9
 # Copyright (c) 2024 Thomas Buck (thomas@xythobuz.de)
7 10
 #
@@ -23,6 +26,8 @@ import wave
23 26
 from svgpathtools import svg2paths
24 27
 
25 28
 samplerate = 44100 #192000
29
+volume_percent = 70
30
+path_steps = 10
26 31
 default_duration = 5.0
27 32
 default_outfile = "out.wav"
28 33
 
@@ -48,13 +53,32 @@ def read_image(filename):
48 53
     print("min={} max={}".format(p_min, p_max))
49 54
 
50 55
     data = bytearray()
51
-    for n in range(0, len(points)):
56
+
57
+    def add_point(p):
52 58
         for i in range(0, 2):
53
-            v = points[n][i]
59
+            v = p[i]
54 60
             v -= p_min[i]
55 61
             v /= p_max[i] - p_min[i]
56
-            c = int((v * 2 - 1) * (32767 / 100 * 70))
62
+            if i == 1:
63
+                v = 1 - v
64
+            c = int((v * 2 - 1) * (32767 / 100 * volume_percent))
57 65
             data.extend(c.to_bytes(2, byteorder="little", signed=True))
66
+
67
+    def interpolate(p1, p2, step):
68
+        p = []
69
+        for i in range(0, 2):
70
+            diff = p2[i] - p1[i]
71
+            v = p1[i] + diff * step
72
+            p.append(v)
73
+        return p
74
+
75
+    for n in range(0, len(points) - 1):
76
+        p1 = points[n]
77
+        p2 = points[n + 1]
78
+        for step in range(0, path_steps):
79
+            p = interpolate(p1, p2, step / path_steps)
80
+            add_point(p)
81
+    add_point(points[len(points) - 1])
58 82
     return data
59 83
 
60 84
 def write_waveform(data, filename):

+ 5
- 4
toolbox.svg Wyświetl plik

@@ -23,9 +23,9 @@
23 23
      inkscape:pagecheckerboard="0"
24 24
      inkscape:deskcolor="#d1d1d1"
25 25
      inkscape:document-units="mm"
26
-     inkscape:zoom="9.7401438"
27
-     inkscape:cx="34.291075"
28
-     inkscape:cy="39.732473"
26
+     inkscape:zoom="16"
27
+     inkscape:cx="27.6875"
28
+     inkscape:cy="45.875"
29 29
      inkscape:window-width="1920"
30 30
      inkscape:window-height="1020"
31 31
      inkscape:window-x="0"
@@ -43,6 +43,7 @@
43 43
        inkscape:connector-curvature="0"
44 44
        id="path32"
45 45
        style="fill:none;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:0.0352778;stroke-opacity:1"
46
-       d="m 54.809672,66.488838 -0.0032,-0.0019 -0.0033,0.0019 -0.0032,-0.0057 -9.011829,-5.198633 h -0.0153 l 0.0029,-10.567212 9.035378,-5.20901 9.028924,5.208587 v 4.160979 h -0.01739 l 0.01739,0.03006 -1.862843,1.074597 1.862843,1.074702 -5.64e-4,9.88e-4 5.64e-4,2.82e-4 v 4.202042 h -0.0088 l 0.0088,0.01517 -9.027266,5.207453 -0.0032,0.0057 m 0.897926,-11.088264 v 0 l 0.01475,8.37463 6.246777,-3.580133 v -2.057153 l -1.864043,-1.075267 -1.899073,1.095516 V 55.99825 l 3.763116,-2.170818 v -2.029848 l -7.160824,-4.130957 -7.164416,4.133003 v 8.395441 l 6.19276,3.569109 v -7.281566 l -1.492427,0.863212 -1.871098,-1.079429 5.594315,-3.236454 1.871909,1.079994 -2.231742,1.290637" />
46
+       d="m 54.805794,66.484453 -9.032612,-5.199858 0.0025,-10.567302 9.035378,-5.20901 9.028924,5.208587 v 4.160979 l -1.862843,1.104657 1.862843,1.074702 c -9.33e-4,1.40583 -1.88e-4,2.812388 0,4.218482 l -9.033236,5.209579 m 0.910765,-2.706542 5.99e-4,-0.0022 6.246178,-3.577918 0.0047,-2.060667 -1.864043,-1.075267 -1.899073,1.095516 V 55.99825 l 3.763116,-2.170818 v -2.029848 l -7.160824,-4.130957 -7.164416,4.133003 v 8.395441 l 6.190862,3.564702 v -7.281566 l -1.492427,0.863212 -1.871098,-1.079429 5.594315,-3.236454 1.871909,1.079994 -2.233905,1.290426 0.01604,8.376379"
47
+       sodipodi:nodetypes="cccccccccccccccccccccccccccccc" />
47 48
   </g>
48 49
 </svg>

Ładowanie…
Anuluj
Zapisz