WAV_file Derived Type

type, public, extends(tape_recorder) :: WAV_file


Inherits

type~~wav_file~~InheritsGraph type~wav_file WAV_file type~tape_recorder tape_recorder type~wav_file->type~tape_recorder

Components

Type Visibility Attributes Name Initial
real(kind=wp), public :: duration

Duration in seconds:

character(len=:), public, allocatable :: filename
integer, public :: fileunit
real(kind=wp), public, dimension(:, :), allocatable :: left

Two arrays stocking the stereo tracks:

real(kind=wp), public, dimension(:, :), allocatable :: right

Two arrays stocking the stereo tracks:

integer, public :: samples

Number of samples:

integer, public :: tracks

Number of audio tracks (excluding track 0 reserved for the final mix):


Type-Bound Procedures

procedure, public :: clear_tracks

  • public subroutine clear_tracks(self)

    Erase all tracks on all the channels of the tape.

    Arguments

    Type IntentOptional Attributes Name
    class(tape_recorder), intent(inout) :: self

procedure, public :: close_WAV_file

  • public subroutine close_WAV_file(self)

    Must be called at the end. It normalizes the channels, writes them in the WAV file and closes it. It also deallocate the tape arrays.

    Arguments

    Type IntentOptional Attributes Name
    class(WAV_file), intent(inout) :: self

procedure, public :: copy_section

  • public subroutine copy_section(self, from_track, to_track, t1, t2, t3)

    Copy section t1...t2 at t3, either on the same track or another one. The content already present at t3 is overwritten. The code suppose that t1 < t2 < t3.

    Arguments

    Type IntentOptional Attributes Name
    class(tape_recorder), intent(inout) :: self
    integer, intent(in) :: from_track
    integer, intent(in) :: to_track
    real(kind=wp), intent(in) :: t1
    real(kind=wp), intent(in) :: t2
    real(kind=wp), intent(in) :: t3

procedure, public :: create_WAV_file

  • public subroutine create_WAV_file(self, filename, tracks, duration)

    Create a WAV file with a header:

    Arguments

    Type IntentOptional Attributes Name
    class(WAV_file), intent(inout) :: self
    character(len=*), intent(in) :: filename
    integer, intent(in) :: tracks
    real(kind=wp), intent(in) :: duration

procedure, public :: finalize

  • public subroutine finalize(self)

    Called by the close_WAV_file() method.

    Arguments

    Type IntentOptional Attributes Name
    class(tape_recorder), intent(inout) :: self

procedure, public :: get_name

  • public function get_name(self)

    Returns the name of the WAV file:

    Arguments

    Type IntentOptional Attributes Name
    class(WAV_file), intent(inout) :: self

    Return Value character(len=len(self%filename))

procedure, public :: mix_tracks

  • public subroutine mix_tracks(self, levels, pan)

    Tracks 1 to tracks-1 are mixed on track 0.

    Arguments

    Type IntentOptional Attributes Name
    class(tape_recorder), intent(inout) :: self
    real(kind=wp), intent(in), optional, dimension(1:self%tracks) :: levels
    real(kind=wp), intent(in), optional, dimension(1:self%tracks) :: pan

procedure, public :: new

  • public subroutine new(self, tracks, duration)

    Arguments

    Type IntentOptional Attributes Name
    class(tape_recorder), intent(inout) :: self
    integer, intent(in) :: tracks
    real(kind=wp), intent(in) :: duration

procedure, private :: write_header

  • public subroutine write_header(self)

    Creates the 44 bytes WAV header and prints some information:

    Arguments

    Type IntentOptional Attributes Name
    class(WAV_file), intent(inout) :: self

    WAV parameters:

    Read more…

procedure, private :: write_normalized_data

  • public subroutine write_normalized_data(self)

    This method normalizes the sound amplitude on track 0, before saving the left and right channels in the WAV file.

    Arguments

    Type IntentOptional Attributes Name
    class(WAV_file), intent(inout) :: self

Source Code

    type, extends(tape_recorder)    :: WAV_file
      character(len=:), allocatable :: filename
      integer                       :: fileunit
    contains
      procedure :: create_WAV_file
      procedure :: close_WAV_file
      procedure :: get_name
      procedure, private :: write_header
      procedure, private :: write_normalized_data
    end type WAV_file