Change volume of a WAV file to C

Asked

Viewed 111 times

1

I’m trying to make a volume change in a WAV file that I just don’t understand because it’s not right. I am a beginner and ask you help to understand the volume pq get very burst and noisy when I try to decrease the volume. Basically if I try to increase the volume works well, but when I put for example "factor = 0.5" which is intended to decrease the audio volume by half does not work. NOTE: it is already said that the file in question has the header with 44 bytes and the samples 16 bits

    // TODO: Copy header from input file to output file
    // HEADER_SIZE = tamanho do cabeçalho do input 
    // BYTE = uint8_t
BYTE bytes[HEADER_SIZE];

fread(bytes,sizeof(BYTE),HEADER_SIZE,input);
fwrite(bytes,sizeof(BYTE),HEADER_SIZE,output);


// TODO: Read samples from input file and write updated data to output file
// BYTE16 = uint16_t
BYTE16 tbytes;

fseek(input,44,0);
fseek(output,44,0);

while(fread(&tbytes, sizeof(BYTE16),1,input))
{
    tbytes = (BYTE16)(tbytes * factor);
    fwrite(&tbytes, sizeof(BYTE16), 1, output);

}

1 answer

-2

Actually the problem is not in C but in the concept of audio, when you change the amplitude, either through coding or through a sound table, you change the dynamics of the audio. When you amplified (increased) what happened was a change in the shape of the wave that produces the amplification, when you pass the same waves several times through the algorithm the precision of the calculation goes inserting these noises. In fact, the change factor for more or less, should be smaller with each passage, instead of using a factor 0.5 tries to use 0.8 or 0.75 and passes 2 times the loop that the interference should become less.....

  • Even putting 0.9 or 0.8 does not change anything, the audio gets extremely loud , burst and noise

Browser other questions tagged

You are not signed in. Login or sign up in order to post.