White Noise Generator in C

แชร์
ฝัง
  • เผยแพร่เมื่อ 23 พ.ย. 2024

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

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

    Hi, loving the channel!
    I do think I spotted a mistake in how your buffer interpolation works, and I think it contributes pretty significantly to the roughness of the audio. You were setting the intermediate value to '(next - current) * a', which means that for every new value you start interpolating from 0, giving you really harsh sawtooth patterns.
    Probably 'current * (1-a) + next * a' will work better.

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

    I just looked at your code on github and what you are producing is actually brown noise. Which is good, because actual white noise is quite unpleasant to listen to! White noise is basically the raw output of any good PRNG, while brown noise is integrated white noise. This type of noise is weighted so that higher frequencies get progressively more attenuated (the formula is -6 dB/octave). The name comes from Brownian motion and it's spectrally similar to the type of noise you are subjected to inside a jet.

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

    I don't understand why so many people enjoy listening to white noise. If I want something in the background I listen to music or videos.
    After 40:00 mark I'm pretty sure you are actually wanting pink noise. That's why the video was more pleasant than the random noise and that's why people don't just listen to static TV.

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

      It can be distracting if you’re trying to focus on actual work. I don’t listen to white noise, but I listen to a lot of music with no lyrics because that is significantly less distracting for me.

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

      I've found that i can hear people pretty clearly even if there's loud music or people talking around, but as soon as white noise is involved, i become completely unable to hear or think for that matter. i imagine others would want to chase that numbing experience.

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

      For some people an harmonically rich constant droning sound can be very soothing and enjoyable to listen to without being distracting and can even help focus for people with adhd for exemple, although i agree that white noise isn't the best choice for that.I absolutely understand how it can be the exact opposite for lots of people; I know its weird but hair dryers sound absolutely work that way for me, almost puts me in a trance/flow kind of state of mind. Lots of eastern religious/trad music work that way like carnatic music for example, there is definitively something to it in terms of psychoacoustics but effects are different for everyone.

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

    I would look into low pass filter algorithms. I think averaging values over a random sample buffer would also work.

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

    You are at one step to generate rain sound.
    I would love to add this feature to whine.

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

    Smoothing the signal can be achieved by convolution with a 1D gaussian kernel, the higher the gaussian variance the lower the frequency will be.
    en.wikipedia.org/wiki/Gaussian_blur

  • @Mr.Exquisite
    @Mr.Exquisite 3 ปีที่แล้ว +14

    I would recommend to implemend a simple digital low pass filter: en.wikipedia.org/wiki/Low-pass_filter#Discrete-time_realization
    It could look like: `output += (random() - output)/constant`

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

    casting result from rand function to sint16 should give you range from -32k to 32k as well.

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

    commenting white at 43:00ish. Recently implemented frequency clamped noise clip generator using inverse fourier transform

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

    Turns out the rigorous definition of white noise, is complicated? Like, if you look at the wikipedia article for "white noise analysis" it is quite something.

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

    Maybe I missed something, but 1/1/x == x.
    You have, "FREQ = 48000; SAMPLE_DT = 1/FREQ; GEN_STEP = 1/SAMPLE_DT';"
    It seems that GEN_STEP = FREQ, and therefore "1.0f / (6.0f * SAMPLE_DT)" would reduce to 6.0f / FREQ.
    Correct me if I'm wrong.

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

    Nobody:....
    Tsoding Daily: Lemme code a white noise generator in C😂

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

    I remember I implemented one called linear congruential generator from Byte magazine for a school project

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

    I think that the sounds generated by the SDL are more like squared than sine

  • @lanceang795
    @lanceang795 3 ปีที่แล้ว

    Thanks for the code that I totally didn’t copy and paste

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

    This is awesome. Kind of sounds like rain?

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

    U make so cozy videos.

  • @Andrei-zc1be
    @Andrei-zc1be 3 ปีที่แล้ว +1

    Triggered by shell build

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

    Can someone tell me why they casted the void pointer to void? What does this do?

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

      To suppress the compiler's warning about unused variable. So technically I'm using it, but without any side effect. :)

  • @cyberjet5946
    @cyberjet5946 3 ปีที่แล้ว

    > 150 sounds like a rocket engine burning

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

    move to youtube from twitch?

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

    Trigger warning, here is some nerd porn;
    If you really want an efficient "is number even" you should go for the "n & 1 != 0" instead. However, in 100/100 of the time any decent up to date c++ compiler will know that this is what you really want to do, instead of the slow modulo operator, if you do an optimized build (-O1 and above)

    • @voytechj
      @voytechj 3 ปีที่แล้ว

      @CharacterX first bit in integer shows if number is even. You can use logic "and" in case your compiler is not smart enough to recognize "i%2==0" pattern.

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

      "if (n&1)" is enough to check for odd numbers, the "!=0" is redundant. If 0, then it's even.

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

      Compiler do this (and much more) optimizations since more then 60 years. If your compiler doesn't, throw it away and get a compiler which was not written by a novice compiler writer.
      There really is no point in doing those "clever low level optimizations" by yourself. Any decent compiler knows them and some additional ones you never heared of. Write clear code which expresses what you want to do at the concept level and leave those bit fiddlings to the compiler. That is: Unless that bit fiddeling is really what you want to do, because from the perspective of the concept level it is all about bit fiddeling (happens eg. in microcontroller programming). But if the algorithm calls for some computation, then by all means write it as computation in the code. The Compiler will figure it out and optimize it to bit fiddeling, if it is possible to do so (If it isn't, it most always means you got the wrong data type. With respect to that you should think about what "unsigned" enables the compiler to do while "signed" does not)
      Seriously: Optimizing eg. multiplications with fixed numbers and transform them into shift/add sequences is trivial. Every student of compiler construction learns this in his freshman year. There is no point in "optimizing" such things by yourself. The same goes for division and/or modulo division. Your optimization is something you forget about and will fail miserable if sometimes in the future the fixed number changes. The compiler however will not miss the change and generate another optimized machine code version tailored to the new fixed number. Plus: the compiler knows about your CPU and takes it resources into account. Some CPU's do have special instructions for multiplication or addition with small numbers (eg. the AVR-microcontroller) and the compiler will use those if it is faster. Compilers use data flow analysis to figure out what rearranging computations eg. does to register allocation and will find a sequence which minimizes register reallocation and/or pipeline stalls.
      Let the Compiler do the work for you! Compilers are smarter then 95% of all C programmers when it comes to possible low evel optimizations. Actually unless you are very good in assembler programming, compiler usually beat assembler programmers also. Concentrate on the algorithm and do algorithmic optimizations but leave the bit fiddling to the compiler.

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

      @@kallewirsch2263 you should have probably read my comment in its entirety.
      On O0 - the compiler, by definition, does no optimizations.

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

      @@simonfarre4907
      I apologize for making it look like my comment was a reply to you. Surely I noticed the last sentence in your posting.
      The comment was ment to be addressed to the legions of novice programmer out there, who seem to think such optimizations are a sign of cleverness and good programming skills. They are not.
      Once again: I apologize for using your posting as an anchor place.

  • @33ordie
    @33ordie 3 ปีที่แล้ว

    nice !!

  • @sleepking669
    @sleepking669 3 ปีที่แล้ว

    have you ever thought of doing ASMR? Your voice is super relaxing :)

  • @هلالمجيد-ظ3ك
    @هلالمجيد-ظ3ك 2 ปีที่แล้ว

    What kind of linux does he use?

  • @ashish_prajapati_tr
    @ashish_prajapati_tr 3 ปีที่แล้ว

    yo👍

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

    Are you okay dude? You listen to white noise?

  • @somMelon
    @somMelon 3 ปีที่แล้ว

    7:03 you could have called it Karen