Guest User

Untitled

a guest
May 1st, 2021
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.26 KB | None | 0 0
  1. // Modifies the volume of an audio file
  2.  
  3. #include <stdint.h>
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6.  
  7. // Number of bytes in .wav header
  8. const int HEADER_SIZE = 44;
  9.  
  10. int main(int argc, char *argv[])
  11. {
  12.     // Check command-line arguments
  13.     if (argc != 4)
  14.     {
  15.         printf("Usage: ./volume input.wav output.wav factor\n");
  16.         return 1;
  17.     }
  18.  
  19.     // Open files and determine scaling factor
  20.     FILE *input = fopen(argv[1], "r");
  21.     if (input == NULL)
  22.     {
  23.         printf("Could not open file.\n");
  24.         return 1;
  25.     }
  26.  
  27.     FILE *output = fopen(argv[2], "w");
  28.     if (output == NULL)
  29.     {
  30.         printf("Could not open file.\n");
  31.         return 1;
  32.     }
  33.  
  34.     float factor = atof(argv[3]);
  35.    
  36.    
  37. // begin my portion
  38.     uint8_t header[HEADER_SIZE];
  39.     int16_t buffer;
  40.  
  41.     fread(header, sizeof(uint8_t), HEADER_SIZE, input);
  42.     fwrite(header, sizeof(uint8_t), HEADER_SIZE, output);
  43.     while(!feof(input))
  44.     {
  45.         fread(&buffer, sizeof(uint16_t), 1, input);
  46.         printf("%i\t", buffer);
  47.         buffer *= factor;
  48.         fwrite(&buffer, sizeof(uint16_t), 1, output);
  49.         printf("%i\n", buffer);
  50.     }
  51.     printf("%i\n", buffer);
  52. // end my portion
  53.  
  54.     // Close files
  55.     fclose(input);
  56.     fclose(output);
  57.  
Advertisement
Add Comment
Please, Sign In to add comment