Skip to content

Instantly share code, notes, and snippets.

@salexkidd
Created November 15, 2016 12:04
Show Gist options
  • Save salexkidd/4c841bbba002ba3a1b396881e3b208d8 to your computer and use it in GitHub Desktop.
Save salexkidd/4c841bbba002ba3a1b396881e3b208d8 to your computer and use it in GitHub Desktop.
PC98 pipo
"""
PC98 PiPo!
======================
# setup and PiPo!
require pygame(sudo or virtualenv)
```
$ pip install pygame
```
$ python pc98.py
thx: https://gist.github.com/ohsqueezy/6540433
"""
from array import array
from time import sleep
import pygame
from pygame.mixer import Sound, get_init, pre_init
class Note(Sound):
def __init__(self, frequency, volume=.1):
self.frequency = frequency
Sound.__init__(self, self.build_samples())
self.set_volume(volume)
def build_samples(self):
period = int(round(get_init()[0] / self.frequency))
samples = array("h", [0] * period)
amplitude = 2 ** (abs(get_init()[1]) - 1) - 1
for time in range(period):
if time < period / 2:
samples[time] = amplitude
else:
samples[time] = -amplitude
return samples
if __name__ == "__main__":
pre_init(44100, -16, 1, 1024)
pygame.init()
Note(2000).play(100)
sleep(0.1)
Note(1000).play(80)
sleep(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment