|
12 | 12 |
|
13 | 13 |
|
14 | 14 | def visualize_horizontal_left_to_right( |
15 | | - stream, chunk, rate, alpha, bar_count, window, smoothed_fft): |
| 15 | + stream, chunk, rate, alpha, window, smoothed_fft, stop_event): |
16 | 16 | # Initialize smoothed FFT with zeros |
17 | 17 | smoothed_fft = np.zeros(chunk // 2 + 1) |
18 | 18 |
|
19 | | - while True: |
| 19 | + while not stop_event.is_set(): |
20 | 20 | data = stream.read_data() |
21 | 21 | if data is None: |
22 | 22 | continue |
@@ -44,53 +44,3 @@ def visualize_horizontal_left_to_right( |
44 | 44 | print('\n'.join(frame_buffer), end='', flush=True) |
45 | 45 |
|
46 | 46 | time.sleep(0.1) # control frame rate |
47 | | - |
48 | | - |
49 | | -# def visualize_horizontal( |
50 | | -# stream, chunk, rate, alpha, bar_count, window, smoothed_fft): |
51 | | -# """ |
52 | | -# Visualizes audio data in a vertical bar chart from bottom to top. |
53 | | -# """ |
54 | | -# rows, cols = os.get_terminal_size() # Get terminal size dynamically |
55 | | -# bar_count = rows # Assume bar_count should use all available rows |
56 | | - |
57 | | -# while True: |
58 | | -# data = stream.read_data() |
59 | | -# if data is None: |
60 | | -# break |
61 | | -# data = np.frombuffer(data, dtype=np.int16) |
62 | | -# data = data.reshape(-1, 2).mean(axis=1) # Average two channels |
63 | | - |
64 | | -# windowed_data = data * window |
65 | | -# fft = np.abs(np.fft.fft(windowed_data).real) |
66 | | -# [:len(windowed_data) // 2] |
67 | | - |
68 | | -# smoothed_fft = alpha * smoothed_fft + (1 - alpha) * fft |
69 | | -# max_fft = max(np.max(smoothed_fft), 1) # Normalize the max value |
70 | | - |
71 | | -# indices = np.logspace(0, np.log10(len(smoothed_fft)), |
72 | | -# num=bar_count + 1, |
73 | | -# endpoint=True, base=10).astype(int) |
74 | | -# indices = np.unique(np.clip(indices, 0, len(smoothed_fft) - 1)) |
75 | | - |
76 | | -# current_frame = {} |
77 | | -# for i in range(len(indices) - 1): |
78 | | -# bar_values = smoothed_fft[indices[i]:indices[i + 1]] |
79 | | -# bar_value = np.average(bar_values, weights=np.linspace( |
80 | | -# 1, 0.1, num=len(bar_values))) if bar_values.size > 0 else 0 |
81 | | -# num_chars = int((bar_value / max_fft) * cols) |
82 | | - |
83 | | -# for j in range(cols - num_chars, cols): |
84 | | -# current_frame[(i, j)] = '█' |
85 | | - |
86 | | -# frame_buffer = [' ' * rows for _ in range(cols)] |
87 | | -# for x in range(cols): # Iterate over each bar |
88 | | -# for y in range(rows): # Iterate over each character in the bar |
89 | | -# if (x, y) in current_frame: |
90 | | -# frame_buffer[x] = frame_buffer[x][:y] + \ |
91 | | -# current_frame[(x, y)] + frame_buffer[x][y+1:] |
92 | | - |
93 | | -# os.system('cls' if os.name == 'nt' else 'clear') |
94 | | -# print('\n'.join(frame_buffer), end="", flush=True) |
95 | | - |
96 | | -# time.sleep(0.1) |
0 commit comments