pyfxr - a simple synth for games

pyfxr generates tones and noises in fast Cython code, and is intended for use in simple Python computer games and in education. It can generate:

  • Highly configurable noises (the original sfxr)

  • Pure tones with sine, square, saw and triangle waveforms

  • Pluck sounds, like harp or guitar, using the Karplus-Strong algorithm

Sounds can be played with any library that supports the buffer protocol (such as Pygame), or saved to .wav files.

For example, this is a complete program to generate a 1s pluck sound and play it with Pygame:

import pygame.mixer
import time
import pyfxr

# pyfxr generates mono 44kHz sounds so we must set
# Pygame to use this
pygame.mixer.pre_init(44100, channels=1)
pygame.mixer.init()

tone = pyfxr.pluck(duration=1.0, pitch='A4')
pygame.mixer.Sound(buffer=tone).play()

# wait for the sound to finish before exiting
time.sleep(tone.duration)

Changes

0.3.0

  • New: GUI to explore SFX parameters

  • New: some parameters for SFX require positive numbers

  • New: chord() for combining sounds

  • New: simple_chord() for generating harmonic chords from chord names

0.2.0

  • New: SFX, which manages parameters for sfx generation

  • Change: jump(), explosion() etc now return SFX instances.

  • New: GUI now prints code for sounds generated

  • Deprecation: sfx() is now deprecated, use SFX.

  • Fix: bug in handling of arp_mod parameter

0.1.0

Initial release.

Indices and tables