FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
TensorVox/spectrogram.cpp at master · ZDisket/TensorVox · GitHub
ZDisket
/
TensorVox
Public
Notifications
You must be signed in to change notification settings
Fork
23
Star
214
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
TensorVox
/
spectrogram.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
157 lines (90 loc) · 3.06 KB
Breadcrumbs
TensorVox
/
spectrogram.cpp
Copy path
File metadata and controls
157 lines (90 loc) · 3.06 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#
include
"
spectrogram.h
"
void
Spectrogram::TimerTick
()
{
if
(!DoSlide)
return
;
float
RemSecs = ((
float
)timEndTick->
remainingTime
()) /
1000
.
f
;
float
CurrentPos = TotSecs - RemSecs;
float
TickSet = CurrentPos/TotSecs;
PlayRect->
topLeft
->
setCoords
(TickSet,
0
);
layer
(
"
Lay2
"
)->
replot
();
}
void
Spectrogram::EndSlide
()
{
timGenericTick->
stop
();
timEndTick->
stop
();
PlayRect->
topLeft
->
setCoords
(
1
,
0
);
layer
(
"
Lay2
"
)->
replot
();
}
size_t
Spectrogram::Get2DIndex
(
size_t
x,
size_t
y,
size_t
xSize)
{
return
x + xSize*y;
}
Spectrogram::Spectrogram
(QWidget *parent) : QCustomPlot(parent)
{
QBrush
FillBrush
(
QColor
(
100
,
100
,
100
));
this
->
setBackground
(FillBrush);
QColor
White
(
255
,
255
,
255
);
QPen
AxisPen
(
QColor
(
150
,
150
,
150
));
xAxis->
setTickLabelColor
(White);
yAxis->
setTickLabelColor
(White);
xAxis->
setBasePen
(AxisPen);
yAxis->
setBasePen
(AxisPen);
yAxis->
setLabel
(
"
Frequency
"
);
xAxis->
setLabel
(
"
Time
"
);
//
They show the wrong info
xAxis->
setTickLabels
(
false
);
yAxis->
setTickLabels
(
false
);
xAxis->
setTicks
(
false
);
yAxis->
setTicks
(
false
);
xAxis->
setLabelColor
(White);
yAxis->
setLabelColor
(White);
QFont Fnt =
QFont
(
font
().
family
(),
10
);
xAxis->
setLabelFont
(Fnt);
yAxis->
setLabelFont
(Fnt);
PlayRect =
new
QCPItemRect
(
this
);
PlayRect->
topLeft
->
setType
(QCPItemPosition::ptViewportRatio);
PlayRect->
bottomRight
->
setType
(QCPItemPosition::ptViewportRatio);
//
The rect is not visible without adding a layer, probably because we are using a more unusual type of plot
addLayer
(
"
Lay2
"
);
QPen
RectPen
(
QColor
(
255
,
255
,
255
,
150
));
QBrush
RectBrush
(
QColor
(
200
,
200
,
200
,
75
));
RectPen.
setWidth
(
3
);
PlayRect->
topLeft
->
setCoords
(
0
,
0
);
PlayRect->
bottomRight
->
setCoords
(
1
,
1
);
PlayRect->
setPen
(RectPen);
PlayRect->
setBrush
(RectBrush);
PlayRect->
setLayer
(
"
Lay2
"
);
timGenericTick =
new
QTimer
(
this
);
timGenericTick->
setInterval
(
10
);
timGenericTick->
setSingleShot
(
false
);
timEndTick =
new
QTimer
(
this
);
timEndTick->
setInterval
(
1000
);
timEndTick->
setSingleShot
(
false
);
connect
(timGenericTick,&QTimer::timeout,
this
,&Spectrogram::TimerTick);
connect
(timEndTick,&QTimer::timeout,
this
,&Spectrogram::EndSlide);
DoSlide =
false
;
}
void
Spectrogram::DoPlot
(
const
TFTensor<
float
> &InMel,
float
TimeInSeconds)
{
const
TFTensor<
float
>& Mel = InMel;
const
auto
& Shp = Mel.
Shape
;
Map->
data
()->
setSize
((
int32_t
)Shp[
2
],(
int32_t
)Shp[
1
]);
Map->
data
()->
setRange
(
QCPRange
(
0.0
,(
double
)Shp[
1
]),
QCPRange
(
0.0
,(
double
)Shp[
2
]));
for
(
int64_t
x =
0
; x < Shp[
2
];x++)
{
for
(
int64_t
y =
0
;y < Shp[
1
];y++)
{
size_t
i =
Get2DIndex
(x,y,Shp[
2
]);
Map->
data
()->
setCell
(x,y,(
double
)Mel.
Data
[i]);
}
}
Map->
rescaleDataRange
(
true
);
rescaleAxes
();
replot
();
TotSecs = TimeInSeconds;
PlayRect->
setVisible
(
true
);
PlayRect->
topLeft
->
setCoords
(
1
,
0
);
timGenericTick->
start
();
timEndTick->
start
((
int
)(TimeInSeconds *
1000
));
}
Back
|
FazBrowse Home
|
New Git URL