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

แชร์
ฝัง
  • เผยแพร่เมื่อ 8 ก.ย. 2024
  • How to program a basic wav audio file in c++ from scratch!

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

  • @ferrabacus2980
    @ferrabacus2980  3 ปีที่แล้ว +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 3 ปีที่แล้ว +1

      TH-cam needs your code to enhance the sound reproduction. Thanks for the video.

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

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

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

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

    • @Silveronix232
      @Silveronix232 ปีที่แล้ว +6

      @@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 2 ปีที่แล้ว +26

    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  2 ปีที่แล้ว +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 2 ปีที่แล้ว

      I absolutely agree,

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

      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 2 ปีที่แล้ว +10

    I really really respect this, perfectly explaining confusing concepts.

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

    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 10 หลายเดือนก่อน +1

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

  • @manuellernst3700
    @manuellernst3700 3 ปีที่แล้ว +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  3 ปีที่แล้ว +2

      What an awesome coincidence! Hope it worked out!

  • @vanessaadams3500
    @vanessaadams3500 5 หลายเดือนก่อน +1

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

  • @MO-fg2cm
    @MO-fg2cm 20 ชั่วโมงที่ผ่านมา

    You deserve lot more bud

  • @KarthikRao449
    @KarthikRao449 3 ปีที่แล้ว +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  3 ปีที่แล้ว +1

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

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

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

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

    These videos are really helpful thank you for sharing

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

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

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

    Thanks for the video, it was really helpful!😊

  • @justcurious1940
    @justcurious1940 12 วันที่ผ่านมา

    U are a legend, Thank u, u deserve 1M sub and more.....

  • @JackHeslewood
    @JackHeslewood ปีที่แล้ว +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.

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

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

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

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

    • @perebalsach
      @perebalsach 3 ปีที่แล้ว +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 3 ปีที่แล้ว +2

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

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

      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!

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

    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

  • @AS-kw1ob
    @AS-kw1ob 2 ปีที่แล้ว +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 3 ปีที่แล้ว +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  3 ปีที่แล้ว +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

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

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

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

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

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

    This is fantastic

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

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

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

    good video to understand wav base, thank you

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

    good video! solved alot of questions =D

  • @chrisschuller7055
    @chrisschuller7055 3 ปีที่แล้ว +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  3 ปีที่แล้ว +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.

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

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

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

    Super helpful. Thanks!

  • @davidste60
    @davidste60 3 ปีที่แล้ว +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  3 ปีที่แล้ว +1

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

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

    Thank you, thank you, thank you very much

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

    Cool video

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

    Thank you so much 👋

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

    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?

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

    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 :)

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

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

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

    Thanks!

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

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

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

    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

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

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

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

    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 2 ปีที่แล้ว

    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 2 ปีที่แล้ว

      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.

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

    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.

  • @user-kn8tp7jo3c
    @user-kn8tp7jo3c 6 หลายเดือนก่อน

    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

  • @ayush.kumar.13907
    @ayush.kumar.13907 2 ปีที่แล้ว

    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.

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

      Yeah I noticed this too!

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

    is this for a class? Where do you teach?

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

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

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

    Mong us

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

    How to access the microphone in c++

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

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

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

    OK OK OK OK OK OK

  • @623-x7b
    @623-x7b 3 ปีที่แล้ว +1

    Midi next?

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

    Can we record audio using this?

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

    Can you make me a mod menu for amog us

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

      I don't know too much about mods! Sorry!