Old School Sound Programming in Python
Asked Answered
B

2

6

A long time ago in a galaxy far away, there were microcomputers which ran BASIC and had simple Sound commands which made the machine beep and hiss in all sorts of weird and wonderful ways.

As well as making some great sounds, it was also very useful as a learning tool because you could hear the results of your code.

I'd love to be able to have the sound functionality of machines like the BBC Micro with its "envelope" command, but without having to use an emulator and learn or relearn all the quirks of the various dialects of BASIC.

I'd also like to avoid having to produce a midi or wav file, but would like to make the sounds directly with the code. I've tried winsound.Beep, but after about 4 notes, the time between the notes seems to go random, and also the functionality is nothing compared to even something like a ZX spectrum.

Does anyone know how to do this with Python?

Briny answered 28/8, 2015 at 8:1 Comment(5)
Have you tried using the system bell escape code (It only has one tone though)?Ingeborgingelbert
Is this previous question similar to what you have in mind? https://mcmap.net/q/1429885/-python-open-raw-audio-data-file/5066845Rumen
The system bell seems the very essence of monotony, unless it can change pitch somehow?Briny
Re the link Scorreia, sadly not what I'm after. I want to avoid reading/writing files and to produce interesting sounds directly from running code.Briny
Although it's only single-channel, winsound.Beep OUGHT to do the trick, but when playing a sequence of notes, the timings are off and notes get missed out, in a different fashiond each time the same code is run. Anyone know how to fix this? The closest to my need so far is pyknon, found via this page: pedrokroger.net/pascals-triangle-soundBriny
B
1

I think the audioop package is the closest you are going to get in python to what you had in the good old days. It's pretty low-level but that's the point. You could use this as the building blocks to create your own retro sound library.

Brag answered 31/8, 2015 at 21:48 Comment(2)
Sounds good, although I was hoping to use sound to help me learn Python as well as having fun. Looks like the fun might have to wait, unless anyone else has done this work already. Someone on a MOOC I'm doing has made some good inroads: codeskulptor.org/#user40_PTiKkUrfBd8jmqn.pyBriny
You can learn the python language in a day. The fun part is learning the libraries, like this one.Brag
D
0

I'ver written and Introduction to Python and NumPy where you learn to create a sine tone and play it back directly with Python.

It's not very fancy, but probably it gets you started.

Decibel answered 16/9, 2015 at 9:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.