What is 440 Hz sound? There are many types of waves at 440 Hz: sine, saw, square, etc. You can have a flute playing A, and that too can count.
Assuming you need a sine wave, it looks like you can create a sound object using pygame.sndarray.samples
. (I have not tested this). You can create patterns with:
samples = [math.sin(2.0 * math.pi * frequency * t / sample_rate) for t in xrange(0, duration_in_samples)]
This, I hope, is the basic sinusoidal material. frequency
- the desired frequency, Hz. sample_rate
- the number of samples / sec in the generated sound: a typical value is 44100 Hz. duration_in_samples
- audio length. (5 * 44100 == 5 seconds if your sound has a sampling frequency of 44100 Hz.)
It looks like you might have to convert the samples
to numpy.array
before moving on to pygame.sndarray.samples
. The docs show that the sound should match the format returned by pygame.mixer.get_init
, so configure the samples
accordingly, but this is the main idea. ( mixer.get_init
will tell you the sample_rate
variable sample_rate
and whether you need to consider stereo, and if you need to adjust the wave amplitude or shift it.)
Make samples
an integer of wavelengths and it should loop.
source share