Python Forum
How can I make music with python/pygame?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How can I make music with python/pygame?
#7
Python and Pygame are both written in C, not C++. You can make C extensions, but there is probably no point unless you find a library in C or want to speed up python (which is not the issue).

Did you check and use some of the software i linked to? I would bet that at least one of those creates music files in which pygame could play. You dont always have to make it 100% in python. For example when i make a game i use Tiled to create the map layout files. These files are interpreted by pyTMX and drawn to the screen by pygame. I could do the same with pygame alone, but is much faster to do with Tiled.

In your situation, there is no option to create music in Pygame (as far as i am aware of). So you must use another software to create your files.

Googling around more i found this which has a lot of links to things to try. Things like pyo or PySyth look promising. But again if your making a game, you dont really need all this, you only need the final output file to play with pygame. I would not worry yet about whether pygame can play it or not, i would first worry about creating the files. You can always convert them to another format later. You can use whatever advanced software there is to produce the file giving you all the amenities of making music.

I checked out pysynth as i thought it was kinda neat.
>>> import pysynth as ps
Piano key frequencies (for equal temperament):
Key number	Scientific name	Frequency (Hz)
         1	             A0	         27.50
         2	            A#0	         29.14
         3	             B0	         30.87
         4	             C1	         32.70
         5	            C#1	         34.65
         6	             D1	         36.71
         7	            D#1	         38.89
         8	             E1	         41.20
         9	             F1	         43.65
        10	            F#1	         46.25
        11	             G1	         49.00
        12	            G#1	         51.91
        13	             A1	         55.00
        14	            A#1	         58.27
        15	             B1	         61.74
        16	             C2	         65.41
        17	            C#2	         69.30
        18	             D2	         73.42
        19	            D#2	         77.78
        20	             E2	         82.41
        21	             F2	         87.31
        22	            F#2	         92.50
        23	             G2	         98.00
        24	            G#2	        103.83
        25	             A2	        110.00
        26	            A#2	        116.54
        27	             B2	        123.47
        28	             C3	        130.81
        29	            C#3	        138.59
        30	             D3	        146.83
        31	            D#3	        155.56
        32	             E3	        164.81
        33	             F3	        174.61
        34	            F#3	        185.00
        35	             G3	        196.00
        36	            G#3	        207.65
        37	             A3	        220.00
        38	            A#3	        233.08
        39	             B3	        246.94
        40	             C4	        261.63
        41	            C#4	        277.18
        42	             D4	        293.66
        43	            D#4	        311.13
        44	             E4	        329.63
        45	             F4	        349.23
        46	            F#4	        369.99
        47	             G4	        392.00
        48	            G#4	        415.30
        49	             A4	        440.00
        50	            A#4	        466.16
        51	             B4	        493.88
        52	             C5	        523.25
        53	            C#5	        554.37
        54	             D5	        587.33
        55	            D#5	        622.25
        56	             E5	        659.26
        57	             F5	        698.46
        58	            F#5	        739.99
        59	             G5	        783.99
        60	            G#5	        830.61
        61	             A5	        880.00
        62	            A#5	        932.33
        63	             B5	        987.77
        64	             C6	       1046.50
        65	            C#6	       1108.73
        66	             D6	       1174.66
        67	            D#6	       1244.51
        68	             E6	       1318.51
        69	             F6	       1396.91
        70	            F#6	       1479.98
        71	             G6	       1567.98
        72	            G#6	       1661.22
        73	             A6	       1760.00
        74	            A#6	       1864.66
        75	             B6	       1975.53
        76	             C7	       2093.00
        77	            C#7	       2217.46
        78	             D7	       2349.32
        79	            D#7	       2489.02
        80	             E7	       2637.02
        81	             F7	       2793.83
        82	            F#7	       2959.96
        83	             G7	       3135.96
        84	            G#7	       3322.44
        85	             A7	       3520.00
        86	            A#7	       3729.31
        87	             B7	       3951.07
        88	             C8	       4186.01
>>> test = (('c', 4), ('e', 4), ('g', 4), ('c5', -2), ('e6', 8), ('d#6', 2))
>>> ps.make_wav(test, fn = "test.wav")
Writing to file test.wav
[1/6]	
[5/6]	

>>> exit()

metulburr@ubuntu:~$ vlc test.wav
VLC media player 2.2.2 Weatherwax (revision 2.2.2-0-g6259d80)
Recommended Tutorials:
Reply


Messages In This Thread
RE: How can I make music with python/pygame? - by metulburr - Sep-24-2019, 12:08 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to make enemy chase me in pygame? Jan_97 3 4,700 Nov-23-2021, 05:08 PM
Last Post: Jan_97
  How to make an image move in relation to another in PYGAME CompleteNewb 1 2,401 Nov-10-2021, 03:38 PM
Last Post: metulburr
  [PyGame] How to loop music with pygame finndude 2 4,152 Nov-09-2021, 10:54 AM
Last Post: metulburr
  cant make a door automatically close a few seconds after i open it in pygame cooImanreebro 2 2,343 Dec-15-2020, 08:40 PM
Last Post: michael1789
  Trying to make boundries for the pygame bluewing101 2 2,136 Mar-23-2020, 01:35 AM
Last Post: Windspar
  Problem with music - Pygame.error GaseBall 1 3,298 Nov-28-2019, 07:46 PM
Last Post: SheeppOSU

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020