Skip to content

Instantly share code, notes, and snippets.

@dmitriykovalev
Created September 4, 2024 05:06
Show Gist options
  • Select an option

  • Save dmitriykovalev/5d1b4825d04cb344a6f4dda0c2092ce3 to your computer and use it in GitHub Desktop.

Select an option

Save dmitriykovalev/5d1b4825d04cb344a6f4dda0c2092ce3 to your computer and use it in GitHub Desktop.
import math
def print_audio_frames(num_samples, freq_hz, sample_rate_hz, num_channels):
for i in range(num_samples):
a = math.sin(2 * math.pi * freq_hz * i / sample_rate_hz)
print(f'{i // num_channels:4d} => ', end='')
for j in range(num_channels):
value = ((1 << (15 - j)) - 1) * a;
print(f'{int(value):6d}', end='')
print()
print_audio_frames(10, freq_hz=250, sample_rate_hz=48000, num_channels=4)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment