-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathDisplayWaveSource.cpp
More file actions
executable file
·94 lines (77 loc) · 2.27 KB
/
DisplayWaveSource.cpp
File metadata and controls
executable file
·94 lines (77 loc) · 2.27 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// DisplayWaveSource.cpp: implementation of the CDisplayWaveSource class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "SpectrumAnalysis.h"
#include "DisplayWaveSource.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CDisplayWaveSource::CDisplayWaveSource()
{
m_pWaveSource = NULL;
}
CDisplayWaveSource::CDisplayWaveSource(CWave* in_pWave)
{
AttachSource(in_pWave);
InitSource();
}
CDisplayWaveSource::~CDisplayWaveSource()
{
}
//////////////////////////////////////////////////////////////////////////
// this function calculate the max/min value of time and sample value
INT CDisplayWaveSource::InitSource()
{
if(m_pWaveSource == NULL) return SPA_ERR_INVALID_DPSOURCE;
DOUBLE lTotalTime = m_pWaveSource->GetTotalTime();
SetXName(SPA_AXIS_UNIT_MS);
SetXMax(lTotalTime);
SetXMin(0);
SetXUnitVal(m_pWaveSource->GetSampleCycle());
SetFXName(SPA_AXIS_UNIT_PERCENT);
SetFXMax(100);
SetFXMin(-100);
SetFXUnitVal(1);
return SPA_NORMAL;
}
//////////////////////////////////////////////////////////////////////////
INT CDisplayWaveSource::AttachSource(CWave *in_pWave)
{
m_pWaveSource = in_pWave;
m_spMax = m_pWaveSource->GetMaxSample();
m_spMin = m_pWaveSource->GetMinSample();
return SPA_NORMAL;
}
//////////////////////////////////////////////////////////////////////////
DOUBLE CDisplayWaveSource::SampleToPercent(SAMPLE in_spSam)
{
DOUBLE ret = 0;
if(in_spSam >= 0)
{
ret = ((DOUBLE)in_spSam / SHRT_MAX);
}
else //if(in_spSam < 0)
{
ret = ((DOUBLE) in_spSam / SHRT_MAX);
}
ret = ret * 100;
return ret;
}
//////////////////////////////////////////////////////////////////////////
// return the sample value at specified time
// x: time (ms)
// Fx: %Sample (%)
DOUBLE CDisplayWaveSource::Fx(DOUBLE x)
{
if(x<0) return 0;
DOUBLE dTcycle = m_pWaveSource->GetSampleCycle();
LONG lSamplePos = (LONG)(x / dTcycle);
SAMPLE spSam = m_pWaveSource->GetSampleAt(lSamplePos);
return SampleToPercent(spSam);
}