Skip to content

Instantly share code, notes, and snippets.

@cbscribe
Created October 21, 2021 04:37
Show Gist options
  • Save cbscribe/2efa43b800ce9ed5d0e855c85807c2fd to your computer and use it in GitHub Desktop.
Save cbscribe/2efa43b800ce9ed5d0e855c85807c2fd to your computer and use it in GitHub Desktop.
Distribution code for Lab 4: Volume
// 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]);
// TODO: Copy header from input file to output file
// TODO: Read samples from input file and write updated data to output file
// Close files
fclose(input);
fclose(output);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment