wavfile.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. A simple sound library for CSE 20211 by Douglas Thain
  3. For course assignments, you should not change this file.
  4. For complete documentation, see:
  5. http://www.nd.edu/~dthain/courses/cse20211/fall2013/wavfile
  6. */
  7. #ifndef _WAVFILE_H_
  8. #define _WAVFILE_H_
  9. #ifdef __cplusplus
  10. extern "C" {
  11. #endif
  12. #include <stdio.h>
  13. //#include <inttypes.h>
  14. struct wavfile_header {
  15. char riff_tag[4];
  16. int riff_length;
  17. char wave_tag[4];
  18. char fmt_tag[4];
  19. int fmt_length;
  20. short audio_format;
  21. short num_channels;
  22. int sample_rate;
  23. int byte_rate;
  24. short block_align;
  25. short bits_per_sample;
  26. char data_tag[4];
  27. int data_length;
  28. };
  29. /*
  30. open an audio file with write flag
  31. and write necessary wav header to it;
  32. input:
  33. filename: string of the file name
  34. output:
  35. the file pointer of the audio file
  36. */
  37. FILE* wavfile_write_open(const char* filename);
  38. /*
  39. write data to the audio file
  40. input:
  41. file: file pointer of the FILE
  42. data: the array of data that need to be written to the file
  43. length: number of short type numbers that need to be written
  44. */
  45. void wavfile_write(FILE* file, short data[], int length);
  46. /*
  47. read data from file
  48. input:
  49. file:
  50. file: file pointer of the file
  51. data: the array to store data.
  52. length: the number of short type numbers that need to be fetched.
  53. output
  54. the number of bytes that the function fetched fromt the file.
  55. */
  56. long wavfile_read(FILE* file, short data[], int length);
  57. /*
  58. close the audio file and write the length to the header
  59. */
  60. void wavfile_write_close(FILE* file);
  61. /*
  62. open an audio file for reading and get the header from file
  63. */
  64. FILE* wavfile_read_open(const char* filename, struct wavfile_header* header);
  65. /*
  66. read the data of an channel with the specified postion and length
  67. */
  68. void wavfile_read_channel(FILE* file, short data[], int channel_num, int channel_index, int start_pos, int length);
  69. #define WAVFILE_SAMPLES_PER_SECOND 16000
  70. #ifdef __cplusplus
  71. }
  72. #endif
  73. #endif