This was solved by changing the buffer from int16_t to int8_t since I was trying to write 8bit audio.
I'm trying to fill a buffer for a mono wave file with two different frequencies but failing at it. I'm using CLion in Ubuntu 18.04.
I know, the buffer size is equal to duration*sample_rate so I'm creating a int16_t vector with that size. I tried filling it with one note first.
for(int i = 0; i < frame_total; i++)
    audio[i] = static_cast<int16_t>(128 + 127 * sin(i));
which generated a nice long beeep. And then I changed it with:
for(int i = 0; i < frame_total; i++)
    audio[i] = static_cast<int16_t>(128 + 127 * sin(i*2));
which generated a higher beeeep, but when trying to do the following:
for(int i = 0; i < frame_total/2; i++)
    audio[i] = static_cast<int16_t>(128 + 127 * sin(i*2));
for(int i = frame_total/2; i < frame_total; i++)
    audio[i] = static_cast<int16_t>(128 + 127 * sin(i));
I expect it to write the higher beep in the first half of the audio, and fill the another fall with the "normal" beep. The *.wav file just plays the first note the entire time.
#define FORMAT_AUDIO 1
#define FORMAT_SIZE 16
struct wave_header{
    // Header
    char      riff[4];
    int32_t   file_size;
    char      wave[4];
    // Format
    char      fmt[4];
    int32_t   format_size;
    int16_t   format_audio;
    int16_t   num_channels;
    int32_t   sample_rate;
    int32_t   byte_rate;
    int16_t   block_align;
    int16_t   bits_per_sample;
    // Data
    char      data[4]
    int32_t   data_size;
};
void write_header(ofstream &music_file ,int16_t bits, int32_t samples, int32_t duration){
    wave_header wav_header{};
    int16_t channels_quantity = 1;
    int32_t total_data = duration * samples * channels_quantity * bits/8;
    int32_t file_data = 4 + 8 + FORMAT_SIZE + 8 + total_data;
    wav_header.riff[0] = 'R';
    wav_header.riff[1] = 'I';
    wav_header.riff[2] = 'F';
    wav_header.riff[3] = 'F';
    wav_header.file_size = file_data;
    wav_header.wave[0] = 'W';
    wav_header.wave[1] = 'A';
    wav_header.wave[2] = 'V';
    wav_header.wave[3] = 'E';
    wav_header.fmt[0] = 'f';
    wav_header.fmt[1] = 'm';
    wav_header.fmt[2] = 't';
    wav_header.fmt[3] = ' ';
    wav_header.format_size = FORMAT_SIZE;
    wav_header.format_audio = FORMAT_AUDIO;
    wav_header.num_channels = channels_quantity;
    wav_header.sample_rate = samples;
    wav_header.byte_rate = samples * channels_quantity * bits/8;
    wav_header.block_align = static_cast<int16_t>(channels_quantity * bits / 8);
    wav_header.bits_per_sample = bits;
    wav_header.data[0] = 'd';
    wav_header.data[1] = 'a';
    wav_header.data[2] = 't';
    wav_header.data[3] = 'a';
    wav_header.data_size = total_data;
    music_file.write((char*)&wav_header, sizeof(wave_header));
}
int main(int argc, char const *argv[]) {
    int16_t bits = 8;
    int32_t samples = 44100;
    int32_t duration = 4;
    ofstream music_file("music.wav", ios::out | ios::binary);
    int32_t  frame_total = samples * duration;
    auto* audio = new int16_t[frame_total];
    for(int i = 0; i < frame_total/2; i++)
        audio[i] = static_cast<int16_t>(128 + 127 * sin(i*2));
    for(int i = frame_total/2; i < frame_total; i++)
        audio[i] = static_cast<int16_t>(128 + 127 * sin(i));
    write_header(music_file, bits, samples, duration);
    music_file.write(reinterpret_cast<char*>(audio),sizeof(int16_t)*frame_total);
    return 0;
}
 
    