Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // 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]);
- // begin my portion
- uint8_t header[HEADER_SIZE];
- int16_t buffer;
- fread(header, sizeof(uint8_t), HEADER_SIZE, input);
- fwrite(header, sizeof(uint8_t), HEADER_SIZE, output);
- while(!feof(input))
- {
- fread(&buffer, sizeof(uint16_t), 1, input);
- printf("%i\t", buffer);
- buffer *= factor;
- fwrite(&buffer, sizeof(uint16_t), 1, output);
- printf("%i\n", buffer);
- }
- printf("%i\n", buffer);
- // end my portion
- // Close files
- fclose(input);
- fclose(output);
Advertisement
Add Comment
Please, Sign In to add comment