Creates the 44 bytes WAV header and prints some information:
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(WAV_file), | intent(inout) | :: | self |
WAV parameters: Number of channels: 1 for mono, 2 for stereo, etc. |
subroutine write_header(self) class(WAV_file), intent(inout) :: self !**************** ! WAV parameters: !**************** ! Number of channels: 1 for mono, 2 for stereo, etc. integer(INT16), parameter :: CHANNELS = 2 integer(INT16), parameter :: BITS_PER_SAMPLE = 16 integer(INT64) :: DATA_BYTES integer(INT32) :: file_size, bytes_per_second, data_size integer(INT16) :: bytes_per_sample print *, "Nb of tracks, excluding track 0:", self%tracks DATA_BYTES = (BITS_PER_SAMPLE / 8) * CHANNELS * self%samples print *, "Used RAM: ", DATA_BYTES * self%tracks, "bytes" print *, "File size ~ ", DATA_BYTES, "bytes" associate(u => self%fileunit) ! RIFF format: write(u, iostat=status) "RIFF" ! Remaining bytes after this data: file_size = 36 + DATA_BYTES write(u, iostat=status) file_size write(u, iostat=status) "WAVE" ! ***** First sub-chunk ***** ! Don't remove the final space in the string! write(u, iostat=status) "fmt " ! Remaining bytes in this sub-chunk, 16 for PCM (32 bits integer): write(u, iostat=status) 16_INT32 ! Encoding is 1 for PCM (16 bits integer): write(u, iostat=status) 1_INT16 write(u, iostat=status) int(CHANNELS, kind=INT16) ! Sampling frequency: write(u, iostat=status) int(RATE, kind=INT32) bytes_per_second = RATE * CHANNELS * (BITS_PER_SAMPLE / 8) write(u, iostat=status) bytes_per_second bytes_per_sample = CHANNELS * (BITS_PER_SAMPLE / 8) write(u, iostat=status) bytes_per_sample write(u, iostat=status) BITS_PER_SAMPLE ! ***** Second sub-chunk ***** write(u, iostat=status) "data" data_size = self%samples * CHANNELS * (BITS_PER_SAMPLE / 8) write(u, iostat=status) data_size end associate end subroutine write_header