c++wavriff

How to find the Creation time of a .wav file using C++


I am currently working on reading a RIff fmt .wav file using c++. How could I find the date and time the file was created. The only time included in the header is the TimeStamp which represents Seconds since epoch.

The following are the parsed RIff headers I am using :

typedef struct RIFF_CHUNCK_DISCRIPTOR {
    char                RIFF[4];        // RIFF Header      Magic header
    int32_t             ChunkSize;      // RIFF Chunk Size  
    int32_t             WAVE[4];        // WAVE Header      

};
typedef struct CRIF_CHUNCK {

    char    Crif[4];
    int32_t Length;
    int32_t CrifCheckSum;
};
typedef struct FMT_CHUNCK_DISCRIPTOR {
    char                fmt[4];         // FMT header       
    int32_t             Subchunk1Size;  // Size of the fmt chunk     
    int16_t             EncodingTag;
    int16_t             NumOfChan;      // Number of channels 
    int32_t             SamplesPerSec;  // Sampling Frequency in Hz                             
    int32_t             bytesPerSec;    // bytes per second 
    int16_t             blockAlign;     // 2=16-bit mono, 4=16-bit stereo 
    int16_t             bitsPerSample;  // Number of bits per sample      
    int16_t             AudioFormat;    // PCM = 0 , ADPCM = 2
    int16_t             SmplesPerChan;
};typedef struct FMT_CHUNCK_DISCRIPTOR_PCM {
    char                fmt[4];         // FMT header       
    int32_t             Subchunk1Size;  // Size of the fmt chunk     
    int16_t             EncodingTag;
    int16_t             NumOfChan;      // Number of channels 
    int32_t             SamplesPerSec;  // Sampling Frequency in Hz                             
    int32_t             bytesPerSec;    // bytes per second 
    int16_t             blockAlign;     // 2=16-bit mono, 4=16-bit stereo 
    int16_t             bitsPerSample;  // Number of bits per sample      
    int16_t             AudioFormat;    // PCM = 0 , ADPCM = 2

};

typedef struct FACT_CHUNCK {
    char                fact[4];
    int32_t             FactSize;
    int32_t             dwSampleLength;

};
typedef struct META_DATA {
    char                    meta[4];
    uint32_t                HeadData;// <length of the head data - 8>
    uint8_t                 Version;
    uint8_t                 Model;
    uint32_t                Serial;
    uint32_t                RecordingNumber;
    uint16_t                ChunkNumber;
    uint32_t                TimeStamp;
    uint32_t                MetadataChecksum;

};
typedef struct  DATA_SUB_CHUNCK {
    char                Subchunk2ID[4]; // "data"  string   
    int32_t             Subchunk2Size;  // Sampled data length    

};
typedef struct  CDAT {
    char                cdat[4]; // "data"  string   
    int32_t             CdatCheckSum;  // Sampled data length    

};
typedef struct  FOOTER {
    char                foot[4]; // "data"  string   
    int16_t             PrevChunckNumb;  // Sampled data length    
    int16_t             NextChunckNumb;
    int32_t             FooterChunckSum;


};



Solution

  • The Timestamp field in the WAV file metadata and the file creation date are to unrelated pieces of information.

    The file creation date is the date the file was created on the hard drive. You can use the Windows API GetFileTime to get the creation, last access and last write times.

    The Timestamp is just some information someone put inside the WAV file. It may or may not be present and may or may not be the same time/date information you will get with GetFileTime.