forked from fxsound2/fxsound-app
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdfxpSpectrum.cpp
More file actions
166 lines (129 loc) · 4.27 KB
/
Copy pathdfxpSpectrum.cpp
File metadata and controls
166 lines (129 loc) · 4.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
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
158
159
160
161
162
163
164
165
166
/*
FxSound
Copyright (C) 2023 FxSound LLC
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/* dfxpSpectrum.cpp */
#include "codedefs.h"
#include <windows.h>
#include <stdio.h>
#include <share.h>
#include "u_dfxp.h"
#include "dfxp.h"
#include "spectrum.h"
#include "DfxSdk.h"
#include "reg.h"
#include "file.h"
#include "dfxSharedUtil.h"
/*
* FUNCTION: dfxp_SpectrumInit()
* DESCRIPTION:
*
* Initialize the spectrum handle and the associated data.
*
*/
int dfxp_SpectrumInit(PT_HANDLE *hp_dfxp)
{
struct dfxpHdlType *cast_handle;
cast_handle = (struct dfxpHdlType *)(hp_dfxp);
if (cast_handle == NULL)
return(OKAY);
realtype r_host_buffer_delay_secs;
realtype r_spectrum_refresh_rate_secs;
/* Initialize the spectrum handle */
r_host_buffer_delay_secs = (realtype)cast_handle->l_host_buffer_delay_msecs * (realtype)0.001;
r_spectrum_refresh_rate_secs = (realtype)DFXP_SPECTRUM_REFRESH_RATE_MSECS * (realtype)0.001;
if (spectrumNew(&(cast_handle->spectrum.spectrum_hdl),
DFXP_SPECTRUM_NUM_BANDS,
r_host_buffer_delay_secs,
r_spectrum_refresh_rate_secs,
cast_handle->slout1,
cast_handle->trace.mode) != OKAY)
return(NOT_OKAY);
cast_handle->spectrum.sample_sets_since_last_spectrum_save = 0;
if (dfxpSpectrumSendClearValues((PT_HANDLE *)cast_handle) != OKAY)
return(NOT_OKAY);
return(OKAY);
}
/*
* FUNCTION: dfxpSpectrumSendClearValues()
* DESCRIPTION:
*
* Sends all zero spectrum values to the GUI.
*
*/
int dfxpSpectrumSendClearValues(PT_HANDLE *hp_dfxp)
{
struct dfxpHdlType *cast_handle;
cast_handle = (struct dfxpHdlType *)(hp_dfxp);
if (cast_handle == NULL)
return(OKAY);
/* Clear the spectrum file */
if (dfxp_SpectrumStoreCurrentValuesInSharedMemory(hp_dfxp, IS_TRUE) != OKAY)
return(NOT_OKAY);
return(OKAY);
}
/*
* FUNCTION: dfxpSpectrumGetBandValues()
* DESCRIPTION:
*
* Get the array with the previously calculated band values
*
*/
int dfxpSpectrumGetBandValues(PT_HANDLE* hp_dfxp, realtype* rp_band_values, int i_array_size)
{
struct dfxpHdlType *cast_handle;
cast_handle = (struct dfxpHdlType *)(hp_dfxp);
if (cast_handle == NULL)
return(OKAY);
if (cast_handle->spectrum.spectrum_hdl == NULL)
return(OKAY);
if (spectrumGetBandValues(cast_handle->spectrum.spectrum_hdl, rp_band_values, i_array_size) != OKAY)
return(NOT_OKAY);
return(OKAY);
}
/*
* FUNCTION: dfxp_SpectrumStoreCurrentValuesInSharedMemory()
* DESCRIPTION:
*
* Stores the current spectrum values in the shared memory so they can be sent to the UI.
*
*/
int dfxp_SpectrumStoreCurrentValuesInSharedMemory(PT_HANDLE *hp_dfxp, int i_clear_values)
{
struct dfxpHdlType *cast_handle;
cast_handle = (struct dfxpHdlType *)(hp_dfxp);
if (cast_handle == NULL)
return(OKAY);
realtype rp_band_values[DFXP_SPECTRUM_NUM_BANDS];
int index;
if (cast_handle->spectrum.spectrum_hdl == NULL)
return(OKAY);
if (cast_handle->hp_sharedUtil == NULL)
return(OKAY);
if (i_clear_values)
{
for (index = 0; index < DFXP_SPECTRUM_NUM_BANDS; index++)
{
rp_band_values[index] = (realtype)0.0;
}
}
else
{
if (spectrumGetBandValues(cast_handle->spectrum.spectrum_hdl, rp_band_values, DFXP_SPECTRUM_NUM_BANDS) != OKAY)
return(NOT_OKAY);
}
/* Store the values in shared memory */
if (dfxSharedUtilSetSpectrumValues(cast_handle->hp_sharedUtil, rp_band_values, DFXP_SPECTRUM_NUM_BANDS) != OKAY)
return(NOT_OKAY);
return(OKAY);
}