-
Notifications
You must be signed in to change notification settings - Fork 0
/
WavInfo.cpp
42 lines (32 loc) · 1.19 KB
/
WavInfo.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
//---------------------------------------------------------------------------
#pragma hdrstop
#include <System.Classes.hpp>
#include <System.SysUtils.hpp>
#include <memory>
#include "WavInfo.h"
using std::make_unique;
//---------------------------------------------------------------------------
#pragma package(smart_init)
WavInfo::WavInfo( String FileName )
{
auto FS = make_unique<TFileStream>( FileName, fmOpenRead, fmShareDenyNone );
if ( FS->Read( &wh_, sizeof wh_ ) < sizeof wh_ ) {
RaiseInvalidFileFormat( FileName );
}
if ( wh_.AudioFormat != 1 ) {
RaiseInvalidFileFormat( FileName );
}
// fileSize_ = FS->Size;
}
//---------------------------------------------------------------------------
void WavInfo::RaiseInvalidFileFormat( String FileName )
{
throw Exception( _T( "Invalid file format (%s)" ), ARRAYOFCONST( ( FileName ) ) );
}
//---------------------------------------------------------------------------
double WavInfo::GetDuration() const
{
return static_cast<double>( wh_.Subchunk2Size ) * 8 /
wh_.bitsPerSample / wh_.NumOfChan / wh_.SamplesPerSec;
}
//---------------------------------------------------------------------------