C++ Wav Audio Programming From Scratch - 4.2 - Mini Lab

Sdílet
Vložit
  • čas přidán 8. 04. 2021
  • How to program a basic wav audio file in c++ from scratch!

Komentáře • 77

  • @ferrabacus2980
    @ferrabacus2980  Před 3 lety +17

    The audio sound is fairly faint, if you can't hear the sound that was created, let me know and I'll post a single clip with the audio again!

    • @yolamontalvan9502
      @yolamontalvan9502 Před 2 lety +1

      CZcams needs your code to enhance the sound reproduction. Thanks for the video.

    • @chopov11
      @chopov11 Před 2 lety

      Can’t hear the audio. But i will code it myself and see haha

    • @DanielBrosman08211986
      @DanielBrosman08211986 Před 2 lety

      Blblabla I cant hear you Speak louder or get a new microphone, This has been so unprofessional

    • @silveronix1535
      @silveronix1535 Před rokem +4

      @@DanielBrosman08211986 this guy is helping a lot of people with his video and you just come crying about the volume? Don't you know how to turn the volume up or something?

  • @ovi1326
    @ovi1326 Před 2 lety +23

    This channel is criminally underrated. I like how you go out of your way to not use uint16_t and uint32_t so they don't scare off the beginners and also just define a bunch of std::strings in the global scope, yet this is a tutorial on binary files and audio generarion which there are not that many beginner-friendly resources on these. Great video.

    • @ferrabacus2980
      @ferrabacus2980  Před 2 lety +7

      I really appreciate your comment, it means a lot. I’m hoping I can keep those same qualities in some of the upcoming videos I have planned!

    • @gijahara5345
      @gijahara5345 Před 2 lety

      I absolutely agree,

    • @skilz8098
      @skilz8098 Před rokem

      This is just the source code to generate - write audio to a file. Try writing the program that opens an audio file, parses it, reads in the audio data, processes it (compression/decompression, handle codecs, encryption/decryption, etc, ...) and then sends it to the hardware through proper system channels and ports to be played back by your audio/speaker device(s). Then once you're able to play the audio file, you need to be able to pause it, play it in a loop, stop it, etc... Then write the software to dynamically manipulate or alter the sound being played through various filters and effects. So in some regards, this is still just the beginning, and this is being done in C++. Try doing this in direct assembly :) But, yes I can agree with your statement, there are so few beginner friendly resources on these semi-advanced topics.

  • @gijahara5345
    @gijahara5345 Před 2 lety +10

    I really really respect this, perfectly explaining confusing concepts.

  • @FatalNight199
    @FatalNight199 Před 3 měsíci

    beautiful, what a perfect video. One week ago, I was finally diving in this programming universe just for fun, and now I casually find this video of you putting in practice a lot of things I read in cplusplus this days. Thank u very much, really.

  • @mohsenir69
    @mohsenir69 Před 7 měsíci +1

    This is the kind of programming tutorial I need, Thanks for your great video

  • @vanessaadams3500
    @vanessaadams3500 Před měsícem

    This is one of the best videos on this subject that I have found so far!

  • @sabanadminolmayan8265

    That was unbeliavable helpful. I watched it with lot of pause. Extreme good explanations.

  • @chillydill4703
    @chillydill4703 Před rokem +1

    What a fantastic channel. Thank you for doing this kind of stuff!

  • @JackHeslewood
    @JackHeslewood Před rokem +1

    Thank you so much! Can't wait to binge watch the rest of this course. I'm learning C currently however the syntax used here is easily recognisable so it was very helpful.

  • @KarthikRao449
    @KarthikRao449 Před 3 lety +3

    Wonderful video. This is the first video of the channel I have seen. For sure will see the other lessons. Good stuff, keep at it and many Thanks.

    • @ferrabacus2980
      @ferrabacus2980  Před 3 lety +1

      Thank you! I'm glad to see you are enjoying it!

  • @maximdanilov6562
    @maximdanilov6562 Před 2 dny

    Thanks for the video, it was really helpful!😊

  • @manuellernst3700
    @manuellernst3700 Před 2 lety +4

    I've just tried to do the same thing using fstream a week ago and couldn't do it due to my little experience. Now having this video is this month's most awesome coincidence! I'll make an edit once I try it

    • @ferrabacus2980
      @ferrabacus2980  Před 2 lety +2

      What an awesome coincidence! Hope it worked out!

  • @TobyAdd
    @TobyAdd Před 11 měsíci

    good video to understand wav base, thank you

  • @xyvler3041
    @xyvler3041 Před 3 lety +4

    These videos are really helpful thank you for sharing

  • @LogicEu
    @LogicEu Před 2 lety +2

    This is incredible, thank you, this video is super helpful

  • @Harshu_awni
    @Harshu_awni Před 2 měsíci

    Hey bro thanks for your content I just found what I am looking for 😊😊

  • @spamfilter32
    @spamfilter32 Před 2 lety

    For those who are unable to hear anything, check your matching parentheses. I had this problem and discovered I was missing a matching parentheses after 'sample_rate' in the formula for assigning 'value', line 65; fixed the amplitude problem.
    it hasn't caused any problems yet, but on line 74 I get a compiler warning about a stack overflow from 8 byte conversion to 4 byte with the "-4"
    as an addition, I created a Pan struct to control the left and right amplitudes and then used that to create a Crossfader, and a fade out, and how to play back to back notes. Next step is to create an ADSR envelop, and then to start abstracting it all out into classes to make more readable code. Future steps will be to create the ability to play 2 notes simultaneously, and then to create an instrument class where each instrument will have a group of harmonic's and overtones and then when I call the instrument, I will feed it the fundamental frequency and the duration to play it, and the class will create the complex wave. Final step will be to add live playback ability

  • @mikelong3444
    @mikelong3444 Před rokem +1

    This is fantastic

  • @matsredman7640
    @matsredman7640 Před 11 měsíci

    Super helpful. Thanks!

  • @oneday374
    @oneday374 Před rokem

    Thank you so much 👋

  • @AS-kw1ob
    @AS-kw1ob Před rokem +1

    This is really nice. I would love to see the opposite way. Reading the data of a wav file and of a mp3 file. I try to compare audio files, that would help me a lot.

  • @nilsdrees9228
    @nilsdrees9228 Před 3 lety +9

    Good video!
    Any particular reason why you used std::string over char* ?
    Also, the way you structured the code makes it really easy to outsource the header variables into a nice header struct, this video is very helpful and makes it easy to do further experiments!

    • @ferrabacus2980
      @ferrabacus2980  Před 3 lety +4

      Hey Nils, thank you for the feedback! I've been trying to use the modern c++ features when I can. I personally like the ability to use the builtin functions with std::string and the relational operators for comparison. However, I think that choice comes down to which one you are more comfortable with for most programs.
      That is awesome, glad to see you experiment with it! I wanted to put that in a header for the video but it was already so long! haha

  • @dobcs3236
    @dobcs3236 Před rokem

    Thank you, thank you, thank you very much

  • @kb3khs
    @kb3khs Před rokem

    Generating wave audio is fun. Recording wave audio is difficult and OS dependent. I'd love a video on recording audio.

  • @perebalsach
    @perebalsach Před 3 lety +4

    Thanks for this one!! Would be nice to have more c++ audio content. Is hard to find tbh!

    • @ferrabacus2980
      @ferrabacus2980  Před 3 lety +1

      I completely agree, is there any specific c++ audio content you would want to see?

    • @perebalsach
      @perebalsach Před 3 lety +6

      @@ferrabacus2980 What about mixing sounds? Displaying a sounds waves (imgui?) Principles of a sound engine or how to tackle a sound engine?
      Maybe is too much or the complexity is quite big. But for example doing a sound engine series would be really nice. There is no content available, so you have an opportunity here :)

    • @perebalsach
      @perebalsach Před 3 lety +2

      @@ferrabacus2980 what about sound fx, like a reverb, echo, distortion,... That couls be really nice too 😊

    • @chopov11
      @chopov11 Před 2 lety

      I agree, would like to see some dsp videos using c++. Audio effects such as distortion, reverb or eq as Pere mentioned on this comment thread. Please Keep up the videos they are super helpful!

  • @Allition1337
    @Allition1337 Před 2 lety +2

    good video! solved alot of questions =D

  • @xyvler3041
    @xyvler3041 Před 3 lety +1

    Cool video

  • @mustafaserhatbeyazay3912

    Nice video ,i am curious about getting a voice Signal (Analog input) from a mic and transform analog into to binary with cpp

  • @chopov11
    @chopov11 Před 2 lety

    Your video was so amazing!!! Please if you are looking for a teaching job come teach c++ at Columbia our current teacher is horrible😂😂

  • @jeordanisfiguereo7592
    @jeordanisfiguereo7592 Před 3 lety +1

    Thanks!

  • @ayushdave9939
    @ayushdave9939 Před 2 lety

    Well, I had to increase the chanel1 and chanel2 value times 500 and it gave me a simple increasing high pitch sound which was interesting though. But I was really looking forward to that bell sound and Yeah the wave form was strangely very minute like I figured it out somehow that I had to increase some value but it was kinda unexpected. Still thanks though, guess my first audio program was a simple high pitch strange sound which if increased a lot could be very sharp or unhearable(you could see it on the decibal scale of Audacity. haha). Thanks again :)

  • @davidste60
    @davidste60 Před 2 lety +3

    Good video. I think subchunk1_size is literally what it says though, the format chunk is 16 bytes, not counting the subchunk1_id and subchunk1_size values. So nothing to do with the bits per sample (except by coincidence in this case).

    • @ferrabacus2980
      @ferrabacus2980  Před 2 lety +1

      Thanks David, I don’t know how I messed that up in the video. Thanks for pointing that out!

  • @chrisschuller7055
    @chrisschuller7055 Před 2 lety +2

    Very good video. The channels are not exactly doing what you intended because of the "amplitude" variable. Should be divided by two instead of the "channel1" in order to get the correct output.

    • @ferrabacus2980
      @ferrabacus2980  Před 2 lety +1

      Thanks Chris! That is a really good point. I plan to redo this with GUI soon, and will make sure to fix that. Thank you.

  • @matthewhurin945
    @matthewhurin945 Před rokem

    I was playing with SSTV recently and I wanted to see if I could program something of the sort. I;m just starting and have no idea how to read a wav file but here are some changes I made
    I have
    8000 bitrate and 1 channel
    const int duration = 2;
    const int hz = 100;
    const int max_amplitude = 32760;
    const double frequency = 1000;
    //160 datapoints becasue 8000 bits per second, for 2 seconds, divided by 100 values per second = 160
    float data[160] = { 1.1, 1.3, 1.4 ,1.5,1.7,1.3,1.2,1.2,1.1,1.6,1.6,1.9,1.8,1.3,1.2,1,1.1, 1.3, 1.4 ,1.5,1.7,1.3,1.2,1.2,1.1,1.6,1.6,1.9,1.8,1.3,1.2,1,1.1, 1.3, 1.4 ,1.5,1.7,1.3,1.2,1.2,1.1,1.6,1.6,1.9,1.8,1.3,1.2,1, 1.1, 1.3, 1.4 ,1.5,1.7,1.3,1.2,1.2,1.1,1.6,1.6,1.9,1.8,1.3,1.2,1, 1.1, 1.3, 1.4 ,1.5,1.7,1.3,1.2,1.2,1.1,1.6,1.6,1.9,1.8,1.3,1.2,1, 1.1, 1.3, 1.4 ,1.5,1.7,1.3,1.2,1.2,1.1,1.6,1.6,1.9,1.8,1.3,1.2,1, 1.1, 1.3, 1.4 ,1.5,1.7,1.3,1.2,1.2,1.1,1.6,1.6,1.9,1.8,1.3,1.2,1, 1.1, 1.3, 1.4 ,1.5,1.7,1.3,1.2,1.2,1.1,1.6,1.6,1.9,1.8,1.3,1.2,1, 1.1, 1.3, 1.4 ,1.5,1.7,1.3,1.2,1.2,1.1,1.6,1.6,1.9,1.8,1.3,1.2,1, 1.1, 1.3, 1.4 ,1.5,1.7,1.3,1.2,1.2,1.1,1.6,1.6,1.9,1.8,1.3,1.2,1};
    for (int i = 0; i < sample_rate * duration; i++) {
    int asdf= round(i / hz);
    double amplitude = 20000;
    double value = sin((2 * 3.14 * i * frequency * data[asdf]) / sample_rate);
    double channel1 = amplitude * value;
    write_as_bytes(wav, channel1, 2);
    }
    It creates a constant amp changing frequency file

  • @nkumar8174
    @nkumar8174 Před 2 měsíci

    Hi, this is truly a master class. I need help and please let me know, how can I contact you. Thank you

  • @supergeorgem3599
    @supergeorgem3599 Před rokem

    Dear Mr. Ferrabacus,
    I have a question, some of my students came here and watched your very explanatory video to complete a task that I proposed to them. If you had to rate them, what would be the percentage you would assign from 0% to 100%?
    By the way, where does the name of your profile come from?
    Thanks in advance.

  • @missq4024
    @missq4024 Před 2 lety

    In this video, you have manually created the shape of the sound wave, I am searching for a tool that is able to activate my microphone I/O to record WAV audio. I use Mac OS as well, anyone has ideas on how can I accomplish that? There are a few tutorials online.

    • @firstnamelastname-oy7es
      @firstnamelastname-oy7es Před 2 lety

      what about a program called audacity? It can record audio from a microphone into a file, you should be able to save it in a wav file.

  • @nicholas3895
    @nicholas3895 Před 3 měsíci

    I'm a beginner, could you please help me?
    I understood that at the beginning of the WAV file we have a series of bytes that represent the info of the file and each info has to occupy a specific size in bytes. "Num channels" for example is represented as an INT in the program, but it can't be seen as an INT in the WAV file because it would occupy 4 bytes and not 2, so you convert it with the function write_as_bytes(), but to be honest i didn't understand it at all due to my lack of knowledge. Could you please explain it to me in a simple way?

  • @basboerboom9328
    @basboerboom9328 Před 7 měsíci

    Can't you use a short instead of an int for the 2 byte formats?

  • @ayush.kumar.13907
    @ayush.kumar.13907 Před 2 lety

    the WAV format image lists some sections being stored in little endian and some in big endian, how is your program dealing with that? you seem to have used the default endianness for all the sections.

  • @sean8190
    @sean8190 Před 2 lety +1

    is this for a class? Where do you teach?

    • @ferrabacus2980
      @ferrabacus2980  Před 2 lety +2

      Hey Pean, I do teach CS but not comfortable saying where. I make these videos for CZcams because I want to see if the ideas I believe in for teaching CS are actually good ideas.

  • @andzejkopytko6694
    @andzejkopytko6694 Před 2 lety

    Veeery good explantation, keep it up :) Btw you follow wrong practicies, like 'using namespace std;'. Don't worry, i'm just saying ;) Have a good day.

  • @gacrux6681
    @gacrux6681 Před měsícem

    Can we record audio using this?

  • @user-kn8tp7jo3c
    @user-kn8tp7jo3c Před 3 měsíci

    do you have a github with this file? i typed it over but there isn't any data written to my test.wav
    (edit): i missed "(" in line 65. great tutorial btw

  • @xyvler3041
    @xyvler3041 Před 3 lety +3

    Mong us

  • @SLguitarGuy
    @SLguitarGuy Před 3 lety

    How to access the microphone in c++

    • @ferrabacus2980
      @ferrabacus2980  Před 3 lety

      I'm currently working on some stuff, I'll see how I can fit this into that!

  • @rterminatu
    @rterminatu Před 2 lety +1

    Midi next?

  • @xyvler3041
    @xyvler3041 Před 3 lety +1

    Can you make me a mod menu for amog us