Bonjour je ne trouvais comment faire le lab 4 de cs50 donc j'ai regardé sur internet et j'en suis arrivé a ceci
// Modifies the volume of an audio file
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
// Number of bytes in .wav header
const int HEADER_SIZE = 44;
int main(int argc, char *argv[])
{
// Check command-line arguments
if (argc != 4)
{
printf("Usage: ./volume input.wav output.wav factor\n");
return 1;
}
// Open files and determine scaling factor
FILE *input = fopen(argv[1], "r");
if (input == NULL)
{
printf("Could not open file.\n");
return 1;
}
FILE *output = fopen(argv[2], "w");
if (output == NULL)
{
printf("Could not open file.\n");
return 1;
}
float factor = atof(argv[3]);
uint8_t header_bytes[HEADER_SIZE];
fread(header_bytes, sizeof(uint8_t), HEADER_SIZE, input);
fwrite(header_bytes, sizeof(uint8_t), HEADER_SIZE, output);
int16_t buffer;
int count = 0;
while (fread(&buffer, sizeof(int16_t), 1, input))
{
buffer *= factor;
fwrite(&buffer, sizeof(int16_t), 1, output);
}
fclose(input);
fclose(output);
}
Cepandant je ne comprends pas pourquoi cela fonctionne car on commence par écrire 44 bytes sur le ficher en sortie et ensuite on écrit les sample 2 bytes par 2 bytes sur le fichier mais ne devrais-t-on pas commencer a écrire ces 2 bytes 44 bytes plus loins car sinon il vont overwrite le 44 premiers header bytes ?
Voici le lien du lab https://cs50.harvard.edu/x/2022/labs/4/