How to make a Simple Sound Synthesizer in Python

แชร์
ฝัง
  • เผยแพร่เมื่อ 16 ก.ค. 2024
  • A simple sound synthesizer made with Pygame and Numpy in Python.
    github.com/FinFetChannel/Pyth...
    0:00 Cringe Intro
    0:33 What is a sound wave
    1:28 Generating a digital signal
    3:24 Generating a sample for each note in a piano keyboard
    4:43 Keyboard input
    5:18 Displaying the notes on the screen
    6:08 Generating square and triangular waves
    7:22 Saving a sound sequence
    8:15 Replaying the text file
    9:10 Creating sound tracks
    10:13 Exporting a track to a wav file
  • วิทยาศาสตร์และเทคโนโลยี

ความคิดเห็น • 49

  • @ajtheprogrammer6500
    @ajtheprogrammer6500 2 ปีที่แล้ว +3

    I just thought and programmed this before 7 days now I got where was my mistake. Thnx for figuring it out bro.

  • @mlphyzix
    @mlphyzix 2 ปีที่แล้ว +3

    fantastic resource, thank you!

  • @EvaTruve
    @EvaTruve หลายเดือนก่อน

    I like the explanation. Thanks!

  • @ramachandranmn1
    @ramachandranmn1 ปีที่แล้ว +2

    Really wonderful...thanks dear....

  • @arnielarson186
    @arnielarson186 6 หลายเดือนก่อน

    Very cool vidio. I've done a couple quick programs in pygame and am interested in a variety of audio stuff. Great short video!

  • @SkyFly19853
    @SkyFly19853 2 ปีที่แล้ว +2

    Nice...
    Good for video game development...
    ✅✅✅✅✅

  • @kyuchumimo
    @kyuchumimo 2 ปีที่แล้ว +7

    It's incredible how you have managed to do things in pygame that seem impossible, you simply leave me speechless.

    • @FinFET
      @FinFET  2 ปีที่แล้ว +2

      Maybe I should make a speech synthesizer then xD

    • @kyuchumimo
      @kyuchumimo 2 ปีที่แล้ว +2

      @@FinFET Good idea

  • @temporallabsol9531
    @temporallabsol9531 2 ปีที่แล้ว +3

    Thank you bruv.

  • @iandwyer6658
    @iandwyer6658 ปีที่แล้ว +2

    Love this video! Another idea for ideal square waves, maybe try using a unitstep for the period of the tone and have it adjusted by a duty cycle ratio. The general square is u[n]-u[n-N], where the full period is 2x N for a 50% duty cycle where N is the period the signal is high for; easy in MATLAB but Ive never tried python, hence why Im watching this. Im not sure how to make it cyclical without it blocking the program though as you worked around with clipping the high gain sin waves, but you could map the input to a loop where as long as youre pressing the key it keeps increasing the n of the series use a modulus to repeat the series to make it cyclical. Thank you for this great video, I needed it for a school project. Also, you can make a triangle by convolving 2 squares, but you need to watch the length since convolution is length1+length2-1 so you would need to double your frequency... or you could just define your sequences as I suggested with the unitstep

    • @FinFET
      @FinFET  ปีที่แล้ว

      interesting, haven't thought about that, thanks for the suggestions!

  • @luna134fd
    @luna134fd 2 ปีที่แล้ว +3

    Is very good 👏👏

  • @ClauArumihs
    @ClauArumihs 2 ปีที่แล้ว +3

    I enjoyed the intro, ahahaha

    • @FinFET
      @FinFET  2 ปีที่แล้ว

      🙈

  • @SolathPrime
    @SolathPrime 2 ปีที่แล้ว +7

    Well normal people play music only OG's programme it

  • @JuanGabrielOyolaCardona
    @JuanGabrielOyolaCardona 2 ปีที่แล้ว +1

    Great thanks for sharing 😃🇨🇴

  • @cees5288
    @cees5288 ปีที่แล้ว +3

    Can I use part of this code for an open source synthesizer (will cite ofc)? Also, if you still peruse this comments section can you explain why the pygame mixer cannot interpret 32bit or 64bit arrays to make sin waves? Every time I try to generate a sine wave with a 32 or 64 bit array I get noise. Struggling with the math behind it. Would also welcome some resources to understand this better in a more basic way.

    • @FinFET
      @FinFET  ปีที่แล้ว +2

      No problem, you are free to use it as you may please.
      I think it is just what is supported by pygame at the moment, wih 8 bit and 16 bit sound www.pygame.org/docs/ref/sndarray.html

    • @cees5288
      @cees5288 ปีที่แล้ว

      @@FinFET Thank you!

  • @victorsantosjobs
    @victorsantosjobs ปีที่แล้ว

    Great 😃!!

  • @maverickivmoleko2821
    @maverickivmoleko2821 ปีที่แล้ว +3

    This is really cool. Is there a way to make it play like a guitar?

    • @FinFET
      @FinFET  ปีที่แล้ว +2

      You coul try to build a Soundwave similar sounding to a guitar or use samples, which in the future I wanna explore

  • @GabrielPerboni
    @GabrielPerboni ปีที่แล้ว +3

    Hi! I worked for a long time as a musician, but today I don't have the physical ability to do that anymore (I'm going blind), so I spend a lot of time at home. I tried to learn programming through C++ because I wanted to create a synth to suit my needs, but it was too much for my head (: So I'm trying Python and I'm understanding it quite well (for now)... I'm making good progress!
    I liked your work, but the math part I understood approximately -6%!!! Is this possible? (:
    Anyway, I was wondering if you could point me to some basic study material, indicate some direction to get to the point where I can program my own synth from scratch.
    Thank you for your attention and kindness on sharing your work.

    • @FinFET
      @FinFET  ปีที่แล้ว +1

      Hello, I glossed over most details about the physics and math behind it, but there is plenty material available, found this one very helpful: th-cam.com/play/PLbqhA-NKGP6B6V_AiS-jbvSzdd7nbwwCw.html

  • @honeysstar
    @honeysstar 3 หลายเดือนก่อน

    Hey, I'm trying to do this now for my class project since I think it would be really cool to work with, but I keep repeatedly getting an error back. The error says: ValueError: Array depth must match number of mixer channels
    I've copied your code exactly and it still won't work. Do you have any ideas as to why this may not be working?

  • @michele709
    @michele709 ปีที่แล้ว +1

    I have a question. What is the RIGHT way to produce a waveform? Also how can you make it so that it doesn’t produce aliasing?
    If you read from a table you need to “filter” the table to avoid aliasing. How?

    • @FinFET
      @FinFET  ปีที่แล้ว

      I think you would need to upsample the data from your table first, to the same sample rate, depends on the type of wave, but you could use some kind of regression or fourier analisys

    • @michele709
      @michele709 ปีที่แล้ว

      @@FinFET let me see if i’m getting it right. you are suggesting to have a table with few points and to interpolate between them? You have any advide on “how to block only aliased frequencies”?

    • @FinFET
      @FinFET  ปีที่แล้ว +1

      @@michele709 I thought you already had a table, if you are generating the signal from scratch, like in this video, then you could use fourier transform to dampen the frequencies you don't want. there is numpy.fft.fft() and numpy.fft.ifft() yo could use for that

    • @michele709
      @michele709 ปีที่แล้ว

      @@FinFET i do already have a table. I would like to set some functions or algorithms on the table so that i can control the number of harmonics with a variable (the variable would represent the number of harmonics which are strictly under nyquist frequency). Is there a way to “filter” the table “directly” in the time domain?

    • @michele709
      @michele709 ปีที่แล้ว

      Eventually I found a way via integration of the band limited impulse train tou can get all of the basic analog shapes withous aliasing. Including the square wave with control over the duty cycle.

  • @somdasantigas7849
    @somdasantigas7849 2 ปีที่แล้ว +2

    👍

  • @fustibal
    @fustibal ปีที่แล้ว +1

    How can we use ChatGPT for sound making, at least in theory?

    • @FinFET
      @FinFET  ปีที่แล้ว

      interesting, I asked chatgpt how i could generate sounds that sound similar to an electric guitar and it suggested adding some overtones to the base note, wasn't great but it is something

  • @tatazinhogame9240
    @tatazinhogame9240 ปีที่แล้ว +2

    1:28 Porquê o seu Audacity esta em português?

    • @FinFET
      @FinFET  ปีที่แล้ว +1

      Fui descoberto kkkk,
      geralmente o pessoal pega pelo sotaque heheh
      tenho um canal em português tbm: th-cam.com/channels/NiIkQpZoNUAGHErIrMe9Iw.html

    • @supermalavox
      @supermalavox ปีที่แล้ว +2

      @@FinFET, vou ter de estudar mais "má temática". Sempre tento entender essa questão de ondas e freqüências de som, mas me atrapalho com tanta multiplicação envolvida! Risos. Pode ser que até 2010 (oops, já passou, né?) eu consiga fazer um audiojogo com sons estilo 8-bits.
      Quanto ao teu sotaque, lembrei de um amigo meu falando pra não me confundir "2" com "chew" quando eu estava aprendendo Inglês. Acho que o fato de usar leitor de telas (e ter uma voz sintetizada falando no meu ouvido tudo que eu preciso ler o tempo todo) me ajuda nisso! Risos.
      Enfim, valeu pelo vídeo!

  • @freewheelburning8834
    @freewheelburning8834 2 ปีที่แล้ว +1

    I tried this code in Pycharm with no errors but no sound why?

    • @FinFET
      @FinFET  2 ปีที่แล้ว +1

      Any specific Timecode? Does it work outside pycharm? Sorry, it is a bit har to help without seeing your code

    • @freewheelburning8834
      @freewheelburning8834 2 ปีที่แล้ว

      @@FinFET well the code is exactly the same as the one you presented thats about as useful as I can be lol

    • @freewheelburning8834
      @freewheelburning8834 2 ปีที่แล้ว

      @@FinFET i will try vs code and see if it works there

    • @FinFET
      @FinFET  2 ปีที่แล้ว +1

      @@freewheelburning8834 you could try with idle or the command prompt

    • @freewheelburning8834
      @freewheelburning8834 2 ปีที่แล้ว +1

      @@FinFET yes it works in VS, now Im curious why it doesnt work in pch

  • @SkyFly19853
    @SkyFly19853 2 ปีที่แล้ว +1

    Btw, Jim Carrey is one of my favorite comedians...
    😏