Tutorial: How to Write a Wav File in C

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

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

  • @brandonzhang5808
    @brandonzhang5808 9 หลายเดือนก่อน +45

    This is exactly the topic I wanted to see that was just outside the reach of my motivation/effort balance to look for myself. Thank you good sir! (and bless the algorithm too i guess)

    • @devtails
      @devtails  9 หลายเดือนก่อน +3

      All hail the algorithm 🙇. If there's more you want to know feel free to ask!

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

      @@devtails How do you do stack multiple waves at the same time. Never mind found the Chords video on your channel

  • @gustavobauer6543
    @gustavobauer6543 8 หลายเดือนก่อน +14

    Dude wtf, this is such a cool video, I am now so hyped to play with audio formats, thank you so much
    I was not aware the wav format was that simple

  • @HairyPixels
    @HairyPixels 8 หลายเดือนก่อน +8

    Writing a wav file with pure data. Such a cool idea. Thanks for sharing.

  • @Adrian.Rengle
    @Adrian.Rengle 8 หลายเดือนก่อน +6

    Hi ! Maybe a fclose () at the end ... ? Just saying ...

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

      Yes but the OS can do this for you

    • @Caseofgames
      @Caseofgames 8 หลายเดือนก่อน +2

      @@shadergzBut should you just let it?

    • @shadergz
      @shadergz 8 หลายเดือนก่อน +1

      @@Caseofgames No, you need to be care and free all resource what you use! It's the best pratics ever even if the os can handle it for you

  • @PaulMartin-qt9ux
    @PaulMartin-qt9ux 8 หลายเดือนก่อน

    Awesome video man! I've been wanting to play around with file formats in C and this video scratched that itch.

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

    This would be interesting to see the spectral view of this file too.

  • @JakeBerg777
    @JakeBerg777 9 หลายเดือนก่อน +6

    C is the way to B

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

    Thank you for the outstanding tutorial. It is just what I was looking for. I noticed that you used 256Hz as middle C instead of the customary 261.63Hz. When I tried to use 261.63 in the above program, it gave a really unpleasant output. What could be the reason for that? Thanks in advance :)

  • @mattcargile
    @mattcargile 8 หลายเดือนก่อน +1

    Why did you use strncpy? Why not just do a set of the var?

  • @oracuda
    @oracuda 8 หลายเดือนก่อน +1

    id love to see if you could make a video on modifying the audio tracks stored in a video container format such as webm or mp4

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

    This is very interested, nice man, thanks you for sharing this knowledge

  • @duralikiraz
    @duralikiraz 8 หลายเดือนก่อน +2

    Güzel bir çalışma. Teşekkürler.

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

    Super cool! Thanks for making this :)

  • @x87-64
    @x87-64 8 หลายเดือนก่อน +1

    What about struct padding?

  • @user-zn6es5qq2p
    @user-zn6es5qq2p 5 หลายเดือนก่อน

    Thank you so much for this video!

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

    Great vid man!! Got you a sub.

  • @gocomputing8529
    @gocomputing8529 8 หลายเดือนก่อน +1

    I liked the video because it shows that storing these format is not that hard.
    Two notes though. In minute 4:02 the space was removed when writing fmt. Also, I think you are assuming the endianess, because you are directly writing 16/32 bits integers as they come from the CPU

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

      Yes, I caught the fmt issue after filming and didn't have it in me for a full re-run. Yes, to assuming endianess. My main goal was to focus on the audio format rather than things like this.

  • @AndrewRump
    @AndrewRump 8 หลายเดือนก่อน +6

    One major flaw: The code does not handle big endian vs. small endian numbers, i.e., it will work on some systems but not on others - because the bytes may be swapped

    • @devtails
      @devtails  8 หลายเดือนก่อน +5

      This is correct. My main goal of this video was to demonstrate how the wav format works. I may revisit in the future.

  • @ynav949
    @ynav949 8 หลายเดือนก่อน +7

    now make a wav player

    • @devtails
      @devtails  8 หลายเดือนก่อน +3

      Challenge accepted

  • @test-rj2vl
    @test-rj2vl 8 หลายเดือนก่อน +9

    In future you could write magic numbers like 256.0 and 1000 also into variables. If I quickly want to come back later and look at the code at the end of video I have no idea what they are. If you did float frequency = 256.0 then it would be clear what it is simply by looking at code.

    • @devtails
      @devtails  8 หลายเดือนก่อน +3

      Thanks, I’ll keep this in mind.

    • @basedSkeleton
      @basedSkeleton 8 หลายเดือนก่อน +3

      Or possibly as constants, since you're not going to change them really.

  • @CodeDisease
    @CodeDisease 8 หลายเดือนก่อน +38

    I built a whole synthesizer with lfos and knobs in c++ from scratch without any third party libraries (I built the hardware accelerated GUI from scratch)

    • @delonmeau
      @delonmeau 8 หลายเดือนก่อน +11

      Proof?

    • @swedishpsychopath8795
      @swedishpsychopath8795 8 หลายเดือนก่อน +16

      @@delonmeau He dreamt that he did it. No video proof means bs.

    • @SENTRY456123
      @SENTRY456123 8 หลายเดือนก่อน +2

      Cool! Now I'm gonna steal all of your source code and sell them! 😂

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

      That's cool!

    • @septemberhakurei
      @septemberhakurei 8 หลายเดือนก่อน +6

      git or gtfo 😂😂😂

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

    i am puzzled with one thing they said
    "size of the overall file - 8 bytes, in bytes (32-bit integer)"
    the positinos take 4 BYTES
    32 bit is 4 BYTES
    what DID THEY MEAN "size of overall file - 8 bytes"? does int take up 2 bytes per byte secretly? is int32_t just 4 pointers to ints (2b) 2*4=8?
    and when doing fwrite 10:32, with struct you use 1 for second argument size for &wavh. what does it mean? isn't your strcut's each member 4 bytes long (or can be random). or is struct just an 1 byte pointer to each member?

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

      plus i'm curious, you just directly wrote wav header and buffer into the file, does it mean it's uncompressed?
      edit: oh lol wav fiels are intended to be uncompressed unlike mp3

    • @devtails
      @devtails  8 หลายเดือนก่อน +1

      Interesting, I didn't even notice that on the WAV file format resource. I think that's just an error in the description. 4 bytes or a 32 bit integer is correct.

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

    Excelent video

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

    Nice video, ive tried to recreate this and my code "works" per say, it does make a wav file BUT it has these random spikes everywhere. I've looked at the data thats generated and looked at it when its written but i cant seem to find them while my application doesnt write them to a wav file. I wrote the data in between writing to the wav file to a txt file to check it. I've started to look at a...........
    h e x e d i t o r
    and that shiz is scary af and by scary i mean i dont understand anything when lookimg at it

  • @baladar1353
    @baladar1353 8 หลายเดือนก่อน +1

    It's funny that your video is about writing a WAV file in C, but the video has very low volume.

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

    Anyone doing 2071 as well?

  • @swedishpsychopath8795
    @swedishpsychopath8795 8 หลายเดือนก่อน +3

    I don't think this will work. If it works then it only works accidentally. Sorry! At 4:02 you tried to append a space in the FMT area but vs code "ate" the space. According to the spec you did a bobo. The value should have a trailing NULL and not a trailing SPACE as you tried to do. But you ended up doing a buffer overflow copy (since you specified 4 to strncpy while your value only had 3 characters) and the field may or may not have a null there.

    • @necromeowcer
      @necromeowcer 8 หลายเดือนก่อน +1

      He came back from the future to fix that missing space. VSCode did not actually eat it.
      Although I don't know the ins and outs of WAV player, I don't think most of them care that much about what the fourth character actually is. Some sources said it must be null, others just put a space there. Most WAV players should be able to accommodate both.

    • @swedishpsychopath8795
      @swedishpsychopath8795 8 หลายเดือนก่อน +4

      @@necromeowcer Program outcome can't be left to the spirit world, shamans and good fortune. We must KNOW what we do - and do it correct according to the spec. If he writes code like this and deploys it to the server in a nuclear submarine he can be responsible for randomly executing the subroutine code that initiates the preemptive scorched earth nuclear attack on New York. (there is such a sub-routine in every american submarine built after 1958).

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

      All strings in C are null terminated, so no, this is fine except for concerns about endianness.

    • @swedishpsychopath8795
      @swedishpsychopath8795 8 หลายเดือนก่อน +3

      @@hedgechasing C strings are supposed to be null terminated. If you use %s in printf it will print everyting it finds until it reaches a null terminator. So technically IF there is a null somewhere in the memory space after the address of your string variable THEN the string is null terminated. But this isn't what you normally would want. You want to make a CLEAR length for your string literal / value so it is terminated where YOU want it to be terminated. So in short: you are wrong, and he did an error in his code by copying PAST the length of his string value. ANYTHING may be in the fourth position since the strncpy copied in 4 characters for a string that was only 3 characters wide. So only god knows what was in the 4'th position. But HEY it isn't the end of the world. He did an error and hopefully he now has learned and won't repeat that error again and hopefully you understand your mistake as well. Basically I won - that is what you need to know.

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

    1. Get text editor
    2. Write a program that writes a wav file
    3. Compile it
    4. Run it
    5. .....
    6. Profit
    What is this video about again?

    • @rabbitcreative
      @rabbitcreative 8 หลายเดือนก่อน +3

      > What is this video about again?
      I feel bad for you if all your goals must end in 'profit'.