-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor oscilloscope; infrastructure for vectorscope
- Loading branch information
Showing
7 changed files
with
70 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
todo.txt | ||
__pycache__ | ||
__pycache__ | ||
imgs | ||
*.mp4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import pygame | ||
|
||
class Oscilloscope: | ||
|
||
def __init__(self, screen, width, height, x, y, max_amp): | ||
self.screen = screen | ||
self.width = width | ||
self.height = height | ||
self.x = x | ||
self.y = y | ||
self.max_amp = max_amp | ||
|
||
def draw(self, window: list): | ||
for i, amp in enumerate(window): | ||
half_win = len(window) / 2 | ||
x = ((i - half_win) / half_win) * self.width + self.x | ||
y = (amp / self.max_amp * self.height) + self.y | ||
pygame.draw.circle(self.screen, pygame.Color(255, 255, 255), (x, y), 1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import pygame | ||
|
||
class Vectorscope: | ||
def __init__(self, screen, width, height, x, y, max_amp): | ||
self.screen = screen | ||
self.width = width | ||
self.height = height | ||
self.x = x | ||
self.y = y | ||
self.max_amp = max_amp | ||
|
||
def draw(self, left_samples, right_samples, resolution): | ||
# x is determined by proportion of magnitude on left/right | ||
# i.e. 100% of signal left = max on left axis | ||
# y is determined by ??? - needs more experimentation | ||
pass | ||
|
||
def samples_to_hsla(samples: list) -> pygame.Color: | ||
color: pygame.Color = pygame.Color(0, 0, 0) | ||
window = signal.windows.blackmanharris(10000) | ||
|
||
resample = signal.resample(samples, 10000) | ||
chunk_fft = np.abs(scipy.fft.fft(np.multiply(resample, window))) | ||
freq = np.argmax(chunk_fft[1:]) + 1 | ||
|
||
if freq > 10000 or freq < 24: | ||
return color | ||
|
||
# formula adapted from https://en.wikipedia.org/wiki/Piano_key_frequencies | ||
hue: int = math.ceil(41.9 * math.log(freq / 440, 2) + 171.11) | ||
# saturation = rms(samples) |