forked from fxsound2/fxsound-app
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathComwave.cpp
More file actions
213 lines (182 loc) · 5.78 KB
/
Copy pathComwave.cpp
File metadata and controls
213 lines (182 loc) · 5.78 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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
/*
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/>.
*/
/* Standard includes */
#include "codedefs.h"
#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
#ifndef __ANDROID__
#include <conio.h>
#include <time.h>
#include <windows.h>
#else
#ifndef DWORD
#define DWORD unsigned int
#endif
#endif //WIN32
#include "pcfg.h"
#include "pt_defs.h"
#define PC_TARGET
#include "platform.h"
#include "boardrv1.h"
extern "C"
{
#include "hrdwr.h"
#include "comSftwr.h"
}
#include "pwav.h"
#include "com.h"
#include "u_com.h"
/* FUNCTION: comProcessBuffer()
* DESCRIPTION:
*
* Process the passed buffer.
*
*/
int PT_DECLSPEC comProcessBuffer(PT_HANDLE *hp_com, long *lp_data, long l_length,
int i_stereo_in_mode, int i_stereo_out_mode,
int i_buffer_type)
{
struct comHdlType *cast_handle;
cast_handle = (struct comHdlType *)hp_com;
if (cast_handle == NULL)
return(NOT_OKAY);
if (comSftwrProcessWaveBuffer(cast_handle->comSftwr_hdl, lp_data, l_length,
i_stereo_in_mode, i_stereo_out_mode,
i_buffer_type) != OKAY)
return(NOT_OKAY);
return(OKAY);
}
/* FUNCTION: comProcessWaveBuffer()
* DESCRIPTION:
*
* Process the passed wave buffer.
* If packed 24 bit format, uses rp_float as a temporary buffer
* to convert to MS floating format (-1.0 to 1.0).
* i_down_sample_ratio is used on data with sampling frequencies greater than 48khz to down sample the data
* before processing and then upsample it after processing.
*
*/
int PT_DECLSPEC comProcessWaveBuffer(PT_HANDLE *hp_com, long *lp_data, float *rp_float, long l_length,
int i_stereo_in_mode, int i_stereo_out_mode, int i_down_sample_ratio,
int i_format_flag)
{
/* l_length comes in with the buffer size in sample sets */
struct comHdlType *cast_handle;
long *l_ptr;
float *f_ptr;
int leftover_samples;
int num_down_sample_sets;
int num_sample_sets_to_process;
int i,j;
cast_handle = (struct comHdlType *)hp_com;
if (cast_handle == NULL)
return(NOT_OKAY);
num_sample_sets_to_process = l_length;
if ( i_format_flag == COM_24_BIT_SAMPLES )
{
if (pwav24BitToFloat((char *)lp_data, rp_float, l_length, i_stereo_in_mode) != OKAY)
return(NOT_OKAY);
l_ptr = (long *)rp_float;
}
else
l_ptr = lp_data;
// 2020-05-01: Initialize local variable pointer f_ptr here so get around error "error C4703: potentially uninitialized local pointer variable 'f_ptr' used"
// since /sdl option is turned on in DfxDsp (it is turned off in original code base so this was treated as warning instead of error).
f_ptr = (float *)l_ptr;
// Downsample the data if needed for higher data sampling frequencies
if(i_down_sample_ratio > 1)
{
f_ptr = (float *)l_ptr;
leftover_samples = l_length % i_down_sample_ratio;
num_down_sample_sets = l_length/i_down_sample_ratio;
num_sample_sets_to_process = num_down_sample_sets;
if(i_stereo_in_mode)
{
for(i=0; i<num_down_sample_sets; i++)
{
f_ptr[i * 2] = f_ptr[i * 2 * i_down_sample_ratio];
f_ptr[i * 2 + 1] = f_ptr[i * 2 * i_down_sample_ratio + 1];
}
}
else // Mono case
{
for(i=0; i< num_down_sample_sets; i++)
{
f_ptr[i] = f_ptr[i * i_down_sample_ratio];
}
}
}
if (cast_handle->softdsp_mode)
{
if (comSftwrProcessWaveBuffer(cast_handle->comSftwr_hdl, l_ptr, num_sample_sets_to_process,
i_stereo_in_mode, i_stereo_out_mode,
i_format_flag) != OKAY)
return(NOT_OKAY);
}
else
{
/* Hardware currently not supported */
/*
if (comHrdwrProcessWaveBuffer(cast_handle->board_address, lp_data, l_length,
i_stereo_in_mode, i_stereo_out_mode) != OKAY)
*/
return(NOT_OKAY);
}
// Upsample the data if needed for higher data sampling frequencies
if(i_down_sample_ratio > 1)
{
if(i_stereo_out_mode)
{
for(i=(num_down_sample_sets - 1); i >= 0; i--)
{
// To be replace with sample averaging operation
for(j=0; j<i_down_sample_ratio; j++)
{
f_ptr[i * 2 * i_down_sample_ratio + j * 2] = f_ptr[i * 2];
f_ptr[i * 2 * i_down_sample_ratio + 1 + j * 2] = f_ptr[i * 2 + 1];
}
}
if( leftover_samples > 0 ) // Fill in leftover samples with last processed value
for(i=0; i<leftover_samples; i++)
{
f_ptr[ (num_down_sample_sets * i_down_sample_ratio + i) * 2 ] =
f_ptr[ (num_down_sample_sets * i_down_sample_ratio - 1) * 2 ];
f_ptr[ (num_down_sample_sets * i_down_sample_ratio + i) * 2 + 1 ] =
f_ptr[ (num_down_sample_sets * i_down_sample_ratio - 1) * 2 + 1 ];
}
}
else // Mono case
{
for(i=(num_down_sample_sets - 1); i >= 0; i--)
{
for(j=0; j<i_down_sample_ratio; j++)
f_ptr[i * i_down_sample_ratio + j] = f_ptr[i];
}
if( leftover_samples > 0 ) // Fill in leftover samples with last processed value
for(i=0; i<leftover_samples; i++)
{
f_ptr[ num_down_sample_sets * i_down_sample_ratio + i] =
f_ptr[ num_down_sample_sets * i_down_sample_ratio - 1];
}
}
}
if ( i_format_flag == COM_24_BIT_SAMPLES )
{
if (pwavFloatTo24Bit(rp_float, (char *)lp_data, l_length, i_stereo_out_mode) != OKAY)
return(NOT_OKAY);
}
return(OKAY);
}