-
Notifications
You must be signed in to change notification settings - Fork 0
/
Senc1.c
277 lines (233 loc) · 7.47 KB
/
Senc1.c
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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
/*
* --COPYRIGHT--,BSD Copyright (c) 2009, Texas Instruments Incorporated
* All rights reserved. Redistribution and use in source and binary
* forms, with or without modification, are permitted provided that the
* following conditions are met: * Redistributions of source code must
* retain the above copyright notice, this list of conditions and the
* following disclaimer. * Redistributions in binary form must reproduce
* the above copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided with
* the distribution. * Neither the name of Texas Instruments Incorporated
* nor the names of its contributors may be used to endorse or promote
* products derived from this software without specific prior written
* permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
* BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
* DAMAGE. --/COPYRIGHT--
*/
#include <stdio.h>
#include <stdlib.h>
#include <xdc/std.h>
#include <ti/sdo/ce/Engine.h>
#include <ti/sdo/ce/speech1/sphenc1.h>
#include <ti/sdo/dmai/Dmai.h>
#include <ti/sdo/dmai/Buffer.h>
#include <ti/sdo/dmai/ce/Senc1.h>
#define MODULE_NAME "Senc1"
typedef struct Senc1_Object {
SPHENC1_Handle hEncode;
Int32 minInBufSize;
Int32 minOutBufSize;
} Senc1_Object;
const SPHENC1_Params Senc1_Params_DEFAULT = {
sizeof(SPHENC1_Params),
160,
1,
0,
0,
0,
0,
0,
NULL,
};
const SPHENC1_DynamicParams Senc1_DynamicParams_DEFAULT = {
sizeof(SPHENC1_DynamicParams),
0,
0,
0,
ISPEECH1_VADFLAG_DEFAULT,
0,
0,
0,
0,
0,
};
/******************************************************************************
* Senc1_process
******************************************************************************/
Int
Senc1_process(Senc1_Handle hSe1, Buffer_Handle hInBuf,
Buffer_Handle hOutBuf)
{
XDM1_SingleBufDesc inBufDesc;
XDM1_SingleBufDesc outBufDesc;
SPHENC1_InArgs inArgs;
SPHENC1_OutArgs outArgs;
XDAS_Int32 status;
XDAS_Int8 *inPtr;
XDAS_Int8 *outPtr;
assert(hSe1);
assert(hInBuf);
assert(hOutBuf);
assert(Buffer_getUserPtr(hInBuf));
assert(Buffer_getUserPtr(hOutBuf));
assert(Buffer_getNumBytesUsed(hInBuf));
assert(Buffer_getSize(hOutBuf));
inPtr = Buffer_getUserPtr(hInBuf);
outPtr = Buffer_getUserPtr(hOutBuf);
inBufDesc.buf = inPtr;
inBufDesc.bufSize = Buffer_getNumBytesUsed(hInBuf);
outBufDesc.buf = outPtr;
outBufDesc.bufSize = Buffer_getSize(hOutBuf);
inArgs.size = sizeof(SPHENC1_InArgs);
outArgs.size = sizeof(SPHENC1_OutArgs);
/*
* We never use the inArgs.data fields, so initialize them to NULL.
*/
inArgs.data.buf = (XDAS_Int8 *) NULL;
inArgs.data.bufSize = 0L;
/*
* Encode the speech buffer
*/
status =
SPHENC1_process(hSe1->hEncode, &inBufDesc, &outBufDesc, &inArgs,
&outArgs);
Dmai_dbg1("SPHENC1_process() ret %d \n", status);
if (status != SPHENC1_EOK) {
Dmai_err2("SPHENC1_process() failed with error (%d ext: 0x%x)\n",
(Int) status, (Uns) outArgs.extendedError);
return Dmai_EFAIL;
}
/*
* Encoded Bytes Generated: assume output buffer was filled
*/
/*
* IMPORTANT NOTE:
*/
/*
* This implementation assumes that for every frame the
*/
/*
* number of bytes generated by the encoder is EQUAL to the
*/
/*
* size of the output buffer requested by the codec.
*/
// Buffer_setNumBytesUsed(hOutBuf, Senc1_getOutBufSize(hSe1));
Buffer_setNumBytesUsed(hOutBuf, outBufDesc.bufSize);
return Dmai_EOK;
}
/******************************************************************************
* Senc1_create
******************************************************************************/
Senc1_Handle
Senc1_create(Engine_Handle hEngine, Char * codecName,
SPHENC1_Params * params, SPHENC1_DynamicParams * dynParams)
{
Senc1_Handle hSe1;
SPHENC1_Status encStatus;
XDAS_Int32 status;
SPHENC1_Handle hEncode;
if (hEngine == NULL || codecName == NULL ||
params == NULL || dynParams == NULL) {
Dmai_err0("Cannot pass null for engine, codec name, params or "
"dynamic params\n");
return NULL;
}
hSe1 = (Senc1_Handle) calloc(1, sizeof(Senc1_Object));
if (hSe1 == NULL) {
Dmai_err0("Failed to allocate space for Senc1 Object\n");
return NULL;
}
/*
* Create speech encoder
*/
hEncode = SPHENC1_create(hEngine, codecName, params);
if (hEncode == NULL) {
Dmai_err0("Can't open speech encode algorithm\n");
return NULL;
}
Dmai_dbg0("Setting dynParams \n");
/*
* Set dynamic parameters
*/
encStatus.size = sizeof(SPHENC1_Status);
encStatus.data.buf = NULL;
status =
SPHENC1_control(hEncode, XDM_SETPARAMS, dynParams, &encStatus);
if (status != SPHENC1_EOK) {
Dmai_err1("XDM_SETPARAMS failed, status=%d\n", status);
SPHENC1_delete(hEncode);
free(hSe1);
return NULL;
}
Dmai_dbg0("Made XDM_SETPARAMS control call\n");
/*
* Get buffer requirements
*/
status =
SPHENC1_control(hEncode, XDM_GETBUFINFO, dynParams, &encStatus);
if (status != SPHENC1_EOK) {
Dmai_err1("XDM_GETBUFINFO failed, status=%d\n", status);
SPHENC1_delete(hEncode);
free(hSe1);
return NULL;
}
hSe1->minInBufSize = encStatus.bufInfo.minInBufSize[0];
hSe1->minOutBufSize = encStatus.bufInfo.minOutBufSize[0];
Dmai_dbg2
("Speech encoder requires min buffer sizes in %u and out %u\n",
(Uns) encStatus.bufInfo.minInBufSize[0],
(Uns) encStatus.bufInfo.minOutBufSize[0]);
hSe1->hEncode = hEncode;
return hSe1;
}
/******************************************************************************
* Senc1_delete
******************************************************************************/
Int
Senc1_delete(Senc1_Handle hSe1)
{
if (hSe1) {
if (hSe1->hEncode) {
SPHENC1_delete(hSe1->hEncode);
}
free(hSe1);
}
return Dmai_EOK;
}
/******************************************************************************
* Senc1_getVisaHandle
******************************************************************************/
SPHENC1_Handle
Senc1_getVisaHandle(Senc1_Handle hSe1)
{
assert(hSe1);
return hSe1->hEncode;
}
/******************************************************************************
* Senc1_getInBufSize
******************************************************************************/
Int32
Senc1_getInBufSize(Senc1_Handle hSe1)
{
assert(hSe1);
return hSe1->minInBufSize;
}
/******************************************************************************
* Senc1_getOutBufSize
******************************************************************************/
Int32
Senc1_getOutBufSize(Senc1_Handle hSe1)
{
assert(hSe1);
return hSe1->minOutBufSize;
}