forked from osherbakov/MELPe_fxp
/
mat_lib.c
865 lines (775 loc) · 20.3 KB
/
mat_lib.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
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
/*
2.4 kbps MELP Proposed Federal Standard speech coder
Fixed-point C code, version 1.0
Copyright (c) 1998, Texas Instruments, Inc.
Texas Instruments has intellectual property rights on the MELP
algorithm. The Texas Instruments contact for licensing issues for
commercial and non-government use is William Gordon, Director,
Government Contracts, Texas Instruments Incorporated, Semiconductor
Group (phone 972 480 7442).
The fixed-point version of the voice codec Mixed Excitation Linear
Prediction (MELP) is based on specifications on the C-language software
simulation contained in GSM 06.06 which is protected by copyright and
is the property of the European Telecommunications Standards Institute
(ETSI). This standard is available from the ETSI publication office
tel. +33 (0)4 92 94 42 58. ETSI has granted a license to United States
Department of Defense to use the C-language software simulation contained
in GSM 06.06 for the purposes of the development of a fixed-point
version of the voice codec Mixed Excitation Linear Prediction (MELP).
Requests for authorization to make other use of the GSM 06.06 or
otherwise distribute or modify them need to be addressed to the ETSI
Secretariat fax: +33 493 65 47 16.
*/
/* mat_lib.c: Matrix and vector manipulation library */
#include <stdlib.h>
#include <assert.h>
#include "sc1200.h"
#include "mathhalf.h"
#include "mat_lib.h"
/***************************************************************************
*
* FUNCTION NAME: v_add
*
* PURPOSE:
*
* Perform the addition of the two 16 bit input vector with
* saturation.
*
* INPUTS:
*
* vec1 16 bit short signed integer (int16_t) vector whose
* values fall in the range
* 0xffff 8000 <= vec1 <= 0x0000 7fff.
*
* vec2 16 bit short signed integer (int16_t) vector whose
* values falls in the range
* 0xffff 8000 <= vec2 <= 0x0000 7fff.
*
* n size of input vectors.
*
* OUTPUTS:
*
* none
*
* RETURN VALUE:
*
* vec1 16 bit short signed integer (int16_t) vector whose
* values fall in the range
* 0xffff 8000 <= vec1[] <= 0x0000 7fff.
*
* IMPLEMENTATION:
*
* Perform the addition of the two 16 bit input vectors with
* saturation.
*
* vec1 = vec1 + vec2
*
* vec1[] is set to 0x7fff if the operation results in an
* overflow. vec1[] is set to 0x8000 if the operation results
* in an underflow.
*
* KEYWORDS: add, addition
*
*************************************************************************/
int16_t *v_add(int16_t vec1[], const int16_t vec2[], int16_t n)
{
register int16_t i;
for (i = 0; i < n; i++){
*vec1 = add(*vec1, *vec2);
vec1 ++;
vec2 ++;
}
return(vec1 - n);
}
/***************************************************************************
*
* FUNCTION NAME: L_v_add
*
* PURPOSE:
*
* Perform the addition of the two 32 bit input vector with
* saturation.
*
* INPUTS:
*
* L_vec1 32 bit long signed integer (int32_t) vector whose
* values fall in the range
* 0x8000 0000 <= L_vec1 <= 0x7fff ffff.
*
* L_vec2 32 bit long signed integer (int32_t) vector whose
* values falls in the range
* 0x8000 0000 <= L_vec2 <= 0x7fff ffff.
*
* n size of input vectors.
*
* OUTPUTS:
*
* none
*
* RETURN VALUE:
*
* L_vec1 32 bit long signed integer (int32_t) vector whose
* values fall in the range
* 0x8000 0000 <= L_vec1[] <= 0x7fff ffff.
*
* IMPLEMENTATION:
*
* Perform the addition of the two 32 bit input vectors with
* saturation.
*
* L_vec1 = L_vec1 + L_vec2
*
* L_vec1[] is set to 0x7fff ffff if the operation results in an
* overflow. L_vec1[] is set to 0x8000 0000 if the operation results
* in an underflow.
*
* KEYWORDS: add, addition
*
*************************************************************************/
int32_t *L_v_add(int32_t L_vec1[], int32_t L_vec2[], int16_t n)
{
register int16_t i;
for (i = 0; i < n; i++){
*L_vec1 = L_add(*L_vec1, *L_vec2);
L_vec1 ++;
L_vec2 ++;
}
return(L_vec1 - n);
}
/***************************************************************************
*
* FUNCTION NAME: v_equ
*
* PURPOSE:
*
* Copy the contents of one 16 bit input vector to another
*
* INPUTS:
*
* vec2 16 bit short signed integer (int16_t) vector whose
* values falls in the range
* 0xffff 8000 <= vec2 <= 0x0000 7fff.
*
* n size of input vector
*
* OUTPUTS:
*
* vec1 16 bit short signed integer (int16_t) vector whose
* values fall in the range
* 0xffff 8000 <= vec1 <= 0x0000 7fff.
*
* RETURN VALUE:
*
* vec1 16 bit short signed integer (int16_t) vector whose
* values fall in the range
* 0xffff 8000 <= vec1[] <= 0x0000 7fff.
*
* IMPLEMENTATION:
*
* Copy the contents of one 16 bit input vector to another
*
* vec1 = vec2
*
* KEYWORDS: equate, copy
*
*************************************************************************/
int16_t *v_equ(int16_t vec1[], const int16_t vec2[], int16_t n)
{
register int16_t i;
for (i = 0; i < n; i++){
*vec1 = *vec2;
vec1 ++;
vec2 ++;
}
return(vec1 - n);
}
/***************************************************************************
*
* FUNCTION NAME: v_equ_shr
*
* PURPOSE:
*
* Copy the contents of one 16 bit input vector to another with shift
*
* INPUTS:
*
* vec2 16 bit short signed integer (int16_t) vector whose
* values falls in the range
* 0xffff 8000 <= vec2 <= 0x0000 7fff.
* scale right shift factor
* n size of input vector
*
* OUTPUTS:
*
* vec1 16 bit short signed integer (int16_t) vector whose
* values fall in the range
* 0xffff 8000 <= vec1 <= 0x0000 7fff.
*
* RETURN VALUE:
*
* vec1 16 bit short signed integer (int16_t) vector whose
* values fall in the range
* 0xffff 8000 <= vec1[] <= 0x0000 7fff.
*
* IMPLEMENTATION:
*
* Copy the contents of one 16 bit input vector to another with shift
*
* vec1 = vec2>>scale
*
* KEYWORDS: equate, copy
*
*************************************************************************/
int16_t *v_equ_shr(int16_t vec1[], int16_t vec2[], int16_t scale,
int16_t n)
{
register int16_t i;
for (i = 0; i < n; i++){
*vec1 = shr(*vec2, scale);
vec1 ++;
vec2 ++;
}
return(vec1 - n);
}
/***************************************************************************
*
* FUNCTION NAME: L_v_equ
*
* PURPOSE:
*
* Copy the contents of one 32 bit input vector to another
*
* INPUTS:
*
* L_vec2 32 bit long signed integer (int32_t) vector whose
* values falls in the range
* 0x8000 0000 <= L_vec2 <= 0x7fff ffff.
*
* n size of input vector
*
* OUTPUTS:
*
* L_vec1 32 bit long signed integer (int32_t) vector whose
* values fall in the range
* 0x8000 0000 <= L_vec1 <= 0x7fff ffff.
*
* RETURN VALUE:
*
* L_vec1 32 bit long signed integer (int32_t) vector whose
* values fall in the range
* 0x8000 0000 <= L_vec1[] <= 0x7fff ffff.
*
* IMPLEMENTATION:
*
* Copy the contents of one 32 bit input vector to another
*
* vec1 = vec2
*
* KEYWORDS: equate, copy
*
*************************************************************************/
int32_t *L_v_equ(int32_t L_vec1[], int32_t L_vec2[], int16_t n)
{
register int16_t i;
for (i = 0; i < n; i++){
*L_vec1 = *L_vec2;
L_vec1 ++;
L_vec2 ++;
}
return(L_vec1 - n);
}
/***************************************************************************
*
* FUNCTION NAME: v_inner
*
* PURPOSE:
*
* Compute the inner product of two 16 bit input vectors
* with saturation and truncation. Output is a 16 bit number.
*
* INPUTS:
*
* vec1 16 bit short signed integer (int16_t) whose value
* falls in the range 0xffff 8000 <= vec1 <= 0x0000 7fff.
*
* vec2 16 bit short signed integer (int16_t) whose value
* falls in the range 0xffff 8000 <= vec2 <= 0x0000 7fff.
*
* n size of input vectors
*
* qvec1 Q value of vec1
*
* qvec2 Q value of vec2
*
* qout Q value of output
*
* OUTPUTS:
*
* none
*
* RETURN VALUE:
*
* innerprod 16 bit short signed integer (int16_t) whose value
* falls in the range
* 0xffff 8000 <= innerprod <= 0x0000 7fff.
*
* IMPLEMENTATION:
*
* Compute the inner product of the two 16 bit input vectors.
* The output is a 16 bit number.
*
* KEYWORDS: inner product
*
*************************************************************************/
int16_t v_inner(int16_t vec1[], int16_t vec2[], int16_t n,
int16_t qvec1, int16_t qvec2, int16_t qout)
{
register int16_t i;
int16_t innerprod;
int32_t L_temp;
L_temp = 0;
for (i = 0; i < n; i++){
L_temp = L_mac(L_temp, *vec1, *vec2);
vec1 ++;
vec2 ++;
}
/* (qvec1 + qvec2 + 1) is the Q value from L_mult(vec1[i], vec2[i]), and */
/* also that for L_temp. To make it Q qout, L_shl() it by */
/* (qout - (qvec1 + qvec2 + 1)). To return only a int16_t, use */
/* extract_h() after L_shl() by 16. */
innerprod = extract_h(L_shl(L_temp,
(int16_t) (qout - ((qvec1 + qvec2 + 1) -
16))));
return(innerprod);
}
/***************************************************************************
*
* FUNCTION NAME: L_v_inner
*
* PURPOSE:
*
* Compute the inner product of two 16 bit input vectors
* with saturation and truncation. Output is a 32 bit number.
*
* INPUTS:
*
* vec1 16 bit short signed integer (int16_t) whose value
* falls in the range 0xffff 8000 <= vec1 <= 0x0000 7fff.
*
* vec2 16 bit short signed integer (int16_t) whose value
* falls in the range 0xffff 8000 <= vec2 <= 0x0000 7fff.
*
* n size of input vectors
*
* qvec1 Q value of vec1
*
* qvec2 Q value of vec2
*
* qout Q value of output
*
* OUTPUTS:
*
* none
*
* RETURN VALUE:
*
* L_innerprod 32 bit long signed integer (int32_t) whose value
* falls in the range
* 0x8000 0000 <= L_innerprod <= 0x7fff ffff.
*
* IMPLEMENTATION:
*
* Compute the inner product of the two 16 bit vectors
* The output is a 32 bit number.
*
* KEYWORDS: inner product
*
*************************************************************************/
int32_t L_v_inner(int16_t vec1[], int16_t vec2[], int16_t n,
int16_t qvec1, int16_t qvec2, int16_t qout)
{
register int16_t i;
int16_t shift;
int32_t L_innerprod, L_temp;
L_temp = 0;
for (i = 0; i < n; i++){
L_temp = L_mac(L_temp, *vec1, *vec2);
vec1 ++;
vec2 ++;
}
/* L_temp is now (qvec1 + qvec2 + 1) */
shift = sub(qout, add(add(qvec1, qvec2), 1));
L_innerprod = L_shl(L_temp, shift);
return(L_innerprod);
}
/***************************************************************************
*
* FUNCTION NAME: v_magsq
*
* PURPOSE:
*
* Compute the sum of square magnitude of a 16 bit input vector
* with saturation and truncation. Output is a 16 bit number.
*
* INPUTS:
*
* vec1 16 bit short signed integer (int16_t) whose value
* falls in the range 0xffff 8000 <= vec1 <= 0x0000 7fff.
*
* n size of input vectors
*
* qvec1 Q value of vec1
*
* qout Q value of output
*
* OUTPUTS:
*
* none
*
* RETURN VALUE:
*
* magsq 16 bit short signed integer (int16_t) whose value
* falls in the range
* 0xffff 8000 <= magsq <= 0x0000 7fff.
*
* IMPLEMENTATION:
*
* Compute the sum of square magnitude of a 16 bit input vector.
* The output is a 16 bit number.
*
* KEYWORDS: square magnitude
*
*************************************************************************/
int16_t v_magsq(int16_t vec1[], int16_t n, int16_t qvec1,
int16_t qout)
{
register int16_t i;
int16_t shift;
int16_t magsq;
int32_t L_temp;
L_temp = 0;
for (i = 0; i < n; i++){
L_temp = L_mac(L_temp, *vec1, *vec1);
vec1 ++;
}
/* qout - ((2*qvec1 + 1) - 16) */
shift = sub(qout, sub(add(shl(qvec1, 1), 1), 16));
magsq = extract_h(L_shl(L_temp, shift));
return(magsq);
}
/***************************************************************************
*
* FUNCTION NAME: L_v_magsq
*
* PURPOSE:
*
* Compute the sum of square magnitude of a 16 bit input vector
* with saturation and truncation. Output is a 32 bit number.
*
* INPUTS:
*
* vec1 16 bit short signed integer (int16_t) whose value
* falls in the range 0xffff 8000 <= vec1 <= 0x0000 7fff.
*
* n size of input vectors
*
* qvec1 Q value of vec1
*
* qout Q value of output
*
* OUTPUTS:
*
* none
*
* RETURN VALUE:
*
* L_magsq 32 bit long signed integer (int32_t) whose value
* falls in the range
* 0x8000 0000 <= L_magsq <= 0x7fff ffff.
*
* IMPLEMENTATION:
*
* Compute the sum of square magnitude of a 16 bit input vector.
* The output is a 32 bit number.
*
* KEYWORDS: square magnitude
*
*************************************************************************/
int32_t L_v_magsq(int16_t vec1[], int16_t n, int16_t qvec1,
int16_t qout)
{
register int16_t i;
int16_t shift;
int32_t L_magsq, L_temp;
L_temp = 0;
for (i = 0; i < n; i++){
L_temp = L_mac(L_temp, *vec1, *vec1);
vec1 ++;
}
/* ((qout-16)-((2*qvec1+1)-16)) */
shift = sub(sub(qout, shl(qvec1, 1)), 1);
L_magsq = L_shl(L_temp, shift);
return(L_magsq);
}
/***************************************************************************
*
* FUNCTION NAME: v_scale
*
* PURPOSE:
*
* Perform a multipy of the 16 bit input vector with a 16 bit input
* scale with saturation and truncation.
*
* INPUTS:
*
* vec1 16 bit short signed integer (int16_t) vector whose
* values fall in the range
* 0xffff 8000 <= vec1 <= 0x0000 7fff.
* scale
* 16 bit short signed integer (int16_t) whose value
* falls in the range 0xffff 8000 <= var1 <= 0x0000 7fff.
*
* n size of vec1
*
* OUTPUTS:
*
* none
*
* RETURN VALUE:
*
* vec1 16 bit short signed integer (int16_t) vector whose
* values fall in the range
* 0xffff 8000 <= vec1[] <= 0x0000 7fff.
*
* IMPLEMENTATION:
*
* Perform a multipy of the 16 bit input vector with the 16 bit input
* scale. The output is a 16 bit vector.
*
* KEYWORDS: scale
*
*************************************************************************/
int16_t *v_scale(int16_t vec1[], int16_t scale, int16_t n)
{
register int16_t i;
for (i = 0; i < n; i++){
*vec1 = mult(*vec1, scale);
vec1 ++;
}
return(vec1 - n);
}
/***************************************************************************
*
* FUNCTION NAME: v_scale_shl
*
* PURPOSE:
*
* Perform a multipy of the 16 bit input vector with a 16 bit input
* scale and shift to left with saturation and truncation.
*
* INPUTS:
*
* vec1 16 bit short signed integer (int16_t) vector whose
* values fall in the range
* 0xffff 8000 <= vec1 <= 0x0000 7fff.
*
* scale 16 bit short signed integer (int16_t) whose value
* falls in the range 0xffff 8000 <= var1 <= 0x0000 7fff.
*
* n size of vec1
*
* shift 16 bit short signed integer (int16_t) whose value
* falls in the range 0x0000 0000 <= var1 <= 0x0000 1f.
*
* OUTPUTS:
*
* none
*
* RETURN VALUE:
*
* vec1 16 bit short signed integer (int16_t) vector whose
* values fall in the range
* 0xffff 8000 <= vec1[] <= 0x0000 7fff.
*
* IMPLEMENTATION:
*
* Perform a multipy of the 16 bit input vector with the 16 bit input
* scale. The output is a 16 bit vector.
*
* KEYWORDS: scale
*
*************************************************************************/
int16_t *v_scale_shl(int16_t vec1[], int16_t scale, int16_t n,
int16_t shift)
{
register int16_t i;
for (i = 0; i < n; i++){
*vec1 = extract_h(L_shl(L_mult(*vec1, scale), shift));
vec1 ++;
}
return(vec1 - n);
}
/***************************************************************************
*
* FUNCTION NAME: v_sub
*
* PURPOSE:
*
* Perform the subtraction of the two 16 bit input vector with
* saturation.
*
* INPUTS:
*
* vec1 16 bit short signed integer (int16_t) vector whose
* values fall in the range
* 0xffff 8000 <= vec1 <= 0x0000 7fff.
*
* vec2 16 bit short signed integer (int16_t) vector whose
* values falls in the range
* 0xffff 8000 <= vec2 <= 0x0000 7fff.
*
* n size of input vectors.
*
* OUTPUTS:
*
* none
*
* RETURN VALUE:
*
* vec1 16 bit short signed integer (int16_t) vector whose
* values fall in the range
* 0xffff 8000 <= vec1[] <= 0x0000 7fff.
*
* IMPLEMENTATION:
*
* Perform the subtraction of the two 16 bit input vectors with
* saturation.
*
* vec1 = vec1 - vec2
*
* vec1[] is set to 0x7fff if the operation results in an
* overflow. vec1[] is set to 0x8000 if the operation results
* in an underflow.
*
* KEYWORDS: sub, subtraction
*
*************************************************************************/
int16_t *v_sub(int16_t vec1[], const int16_t vec2[], int16_t n)
{
register int16_t i;
for (i = 0; i < n; i++){
*vec1 = sub(*vec1, *vec2);
vec1 ++;
vec2 ++;
}
return(vec1 - n);
}
/***************************************************************************
*
* FUNCTION NAME: v_zap
*
* PURPOSE:
*
* Set the elements of a 16 bit input vector to zero.
*
* INPUTS:
*
* vec1 16 bit short signed integer (int16_t) vector whose
* values fall in the range
* 0xffff 8000 <= vec1 <= 0x0000 7fff.
*
* n size of vec1.
*
* OUTPUTS:
*
* none
*
* RETURN VALUE:
*
* vec1 16 bit short signed integer (int16_t) vector whose
* values are equal to 0x0000 0000.
*
* IMPLEMENTATION:
*
* Set the elements of 16 bit input vector to zero.
*
* vec1 = 0
*
* KEYWORDS: zap, clear, reset
*
*************************************************************************/
int16_t *v_zap(int16_t vec1[], int16_t n)
{
register int16_t i;
for (i = 0; i < n; i++){
*vec1 = 0;
vec1 ++;
}
return(vec1 - n);
}
/***************************************************************************
*
* FUNCTION NAME: L_v_zap
*
* PURPOSE:
*
* Set the elements of a 32 bit input vector to zero.
*
* INPUTS:
*
* L_vec1 32 bit long signed integer (int32_t) vector whose
* values fall in the range
* 0x8000 0000 <= vec1 <= 0x7fff ffff.
*
* n size of L_vec1.
*
* OUTPUTS:
*
* none
*
* RETURN VALUE:
*
* L_vec1 32 bit long signed integer (int32_t) vector whose
* values are equal to 0x0000 0000.
*
* IMPLEMENTATION:
*
* Set the elements of 32 bit input vector to zero.
*
* L_vec1 = 0
*
* KEYWORDS: zap, clear, reset
*
*************************************************************************/
int32_t *L_v_zap(int32_t L_vec1[], int16_t n)
{
register int16_t i;
for (i = 0; i < n; i++){
*L_vec1 = 0;
L_vec1 ++;
}
return(L_vec1 - n);
}
int16_t *v_get(int16_t n)
{
int16_t *ptr;
int32_t size;
size = sizeof(int16_t) * n;
ptr = malloc(size);
assert(ptr != NULL);
return(ptr);
}
int32_t *L_v_get(int16_t n)
{
int32_t *ptr;
int32_t size;
size = sizeof(int32_t) * n;
ptr = malloc(size);
assert(ptr != NULL);
return(ptr);
}
void v_free(void *v)
{
if (v)
free(v);
}