use opus_(re)alloc and opus_free for dnn and DRED related functions
This commit is contained in:
parent
f5a1efdc17
commit
12fbd8111a
10 changed files with 31 additions and 21 deletions
|
@ -41,7 +41,7 @@
|
|||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
/** Opus wrapper for malloc(). To do your own dynamic allocation, all you need to do is replace this function and opus_free */
|
||||
/** Opus wrapper for malloc(). To do your own dynamic allocation replace this function, opus_realloc, and opus_free */
|
||||
#ifndef OVERRIDE_OPUS_ALLOC
|
||||
static OPUS_INLINE void *opus_alloc (size_t size)
|
||||
{
|
||||
|
@ -49,7 +49,15 @@ static OPUS_INLINE void *opus_alloc (size_t size)
|
|||
}
|
||||
#endif
|
||||
|
||||
/** Same as celt_alloc(), except that the area is only needed inside a CELT call (might cause problem with wideband though) */
|
||||
#ifndef OVERRIDE_OPUS_REALLOC
|
||||
static OPUS_INLINE void *opus_realloc (void *ptr, size_t size)
|
||||
{
|
||||
return realloc(ptr, size);
|
||||
}
|
||||
#endif
|
||||
|
||||
/** Used only for non-threadsafe pseudostack.
|
||||
If desired, this can always return the same area of memory rather than allocating a new one every time. */
|
||||
#ifndef OVERRIDE_OPUS_ALLOC_SCRATCH
|
||||
static OPUS_INLINE void *opus_alloc_scratch (size_t size)
|
||||
{
|
||||
|
@ -58,7 +66,7 @@ static OPUS_INLINE void *opus_alloc_scratch (size_t size)
|
|||
}
|
||||
#endif
|
||||
|
||||
/** Opus wrapper for free(). To do your own dynamic allocation, all you need to do is replace this function and opus_alloc */
|
||||
/** Opus wrapper for free(). To do your own dynamic allocation replace this function, opus_realloc, and opus_free */
|
||||
#ifndef OVERRIDE_OPUS_FREE
|
||||
static OPUS_INLINE void opus_free (void *ptr)
|
||||
{
|
||||
|
|
|
@ -189,7 +189,7 @@ int fargan_load_model(FARGANState *st, const unsigned char *data, int len) {
|
|||
int ret;
|
||||
parse_weights(&list, data, len);
|
||||
ret = init_fargan(&st->model, list);
|
||||
free(list);
|
||||
opus_free(list);
|
||||
if (ret == 0) return 0;
|
||||
else return -1;
|
||||
}
|
||||
|
|
|
@ -275,7 +275,7 @@ int fwgan_load_model(FWGANState *st, const unsigned char *data, int len) {
|
|||
int ret;
|
||||
parse_weights(&list, data, len);
|
||||
ret = init_fwgan(&st->model, list);
|
||||
free(list);
|
||||
opus_free(list);
|
||||
if (ret == 0) return 0;
|
||||
else return -1;
|
||||
}
|
||||
|
|
|
@ -205,7 +205,7 @@ int lpcnet_load_model(LPCNetState *st, const unsigned char *data, int len) {
|
|||
int ret;
|
||||
parse_weights(&list, data, len);
|
||||
ret = init_lpcnet_model(&st->model, list);
|
||||
free(list);
|
||||
opus_free(list);
|
||||
if (ret == 0) return 0;
|
||||
else return -1;
|
||||
}
|
||||
|
@ -214,14 +214,15 @@ int lpcnet_load_model(LPCNetState *st, const unsigned char *data, int len) {
|
|||
LPCNetState *lpcnet_create()
|
||||
{
|
||||
LPCNetState *lpcnet;
|
||||
lpcnet = (LPCNetState *)calloc(lpcnet_get_size(), 1);
|
||||
lpcnet = (LPCNetState *)opus_alloc(lpcnet_get_size(), 1);
|
||||
OPUS_CLEAR(lpcnet, 1);
|
||||
lpcnet_init(lpcnet);
|
||||
return lpcnet;
|
||||
}
|
||||
|
||||
void lpcnet_destroy(LPCNetState *lpcnet)
|
||||
{
|
||||
free(lpcnet);
|
||||
opus_free(lpcnet);
|
||||
}
|
||||
|
||||
void lpcnet_reset_signal(LPCNetState *lpcnet)
|
||||
|
|
|
@ -62,13 +62,13 @@ int lpcnet_encoder_load_model(LPCNetEncState *st, const unsigned char *data, int
|
|||
|
||||
LPCNetEncState *lpcnet_encoder_create(void) {
|
||||
LPCNetEncState *st;
|
||||
st = malloc(lpcnet_encoder_get_size());
|
||||
st = opus_alloc(lpcnet_encoder_get_size());
|
||||
lpcnet_encoder_init(st);
|
||||
return st;
|
||||
}
|
||||
|
||||
void lpcnet_encoder_destroy(LPCNetEncState *st) {
|
||||
free(st);
|
||||
opus_free(st);
|
||||
}
|
||||
|
||||
static void frame_analysis(LPCNetEncState *st, kiss_fft_cpx *X, float *Ex, const float *in) {
|
||||
|
|
|
@ -76,7 +76,7 @@ int lpcnet_plc_load_model(LPCNetPLCState *st, const unsigned char *data, int len
|
|||
int ret;
|
||||
parse_weights(&list, data, len);
|
||||
ret = init_plc_model(&st->model, list);
|
||||
free(list);
|
||||
opus_free(list);
|
||||
if (ret == 0) {
|
||||
ret = lpcnet_encoder_load_model(&st->enc, data, len);
|
||||
}
|
||||
|
|
|
@ -31,6 +31,7 @@
|
|||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include "nnet.h"
|
||||
#include "os_support.h"
|
||||
|
||||
#define SPARSE_BLOCK_SIZE 32
|
||||
|
||||
|
@ -55,7 +56,7 @@ int parse_weights(WeightArray **list, const unsigned char *data, int len)
|
|||
{
|
||||
int nb_arrays=0;
|
||||
int capacity=20;
|
||||
*list = malloc(capacity*sizeof(WeightArray));
|
||||
*list = opus_alloc(capacity*sizeof(WeightArray));
|
||||
while (len > 0) {
|
||||
int ret;
|
||||
WeightArray array = {NULL, 0, 0, 0};
|
||||
|
@ -64,11 +65,11 @@ int parse_weights(WeightArray **list, const unsigned char *data, int len)
|
|||
if (nb_arrays+1 >= capacity) {
|
||||
/* Make sure there's room for the ending NULL element too. */
|
||||
capacity = capacity*3/2;
|
||||
*list = realloc(*list, capacity*sizeof(WeightArray));
|
||||
*list = opus_realloc(*list, capacity*sizeof(WeightArray));
|
||||
}
|
||||
(*list)[nb_arrays++] = array;
|
||||
} else {
|
||||
free(*list);
|
||||
opus_free(*list);
|
||||
*list = NULL;
|
||||
return -1;
|
||||
}
|
||||
|
@ -269,7 +270,7 @@ int main()
|
|||
printf("found %s: size %d\n", list[i].name, list[i].size);
|
||||
}
|
||||
printf("%p\n", list[i].name);
|
||||
free(list);
|
||||
opus_free(list);
|
||||
munmap(data, len);
|
||||
close(fd);
|
||||
return 0;
|
||||
|
|
|
@ -73,7 +73,7 @@ int pitchdnn_load_model(PitchDNNState *st, const unsigned char *data, int len) {
|
|||
int ret;
|
||||
parse_weights(&list, data, len);
|
||||
ret = init_pitchdnn(&st->model, list);
|
||||
free(list);
|
||||
opus_free(list);
|
||||
if (ret == 0) return 0;
|
||||
else return -1;
|
||||
}
|
||||
|
|
|
@ -58,7 +58,7 @@ int dred_encoder_load_model(DREDEnc* enc, const unsigned char *data, int len)
|
|||
int ret;
|
||||
parse_weights(&list, data, len);
|
||||
ret = init_rdovaeenc(&enc->model, list);
|
||||
free(list);
|
||||
opus_free(list);
|
||||
if (ret == 0) {
|
||||
ret = lpcnet_encoder_load_model(&enc->lpcnet_enc_state, data, len);
|
||||
}
|
||||
|
|
|
@ -1189,7 +1189,7 @@ int dred_decoder_load_model(OpusDREDDecoder *dec, const unsigned char *data, int
|
|||
int ret;
|
||||
parse_weights(&list, data, len);
|
||||
ret = init_rdovaedec(&dec->model, list);
|
||||
free(list);
|
||||
opus_free(list);
|
||||
if (ret == 0) dec->loaded = 1;
|
||||
return (ret == 0) ? OPUS_OK : OPUS_BAD_ARG;
|
||||
}
|
||||
|
@ -1233,8 +1233,8 @@ OpusDREDDecoder *opus_dred_decoder_create(int *error)
|
|||
|
||||
void opus_dred_decoder_destroy(OpusDREDDecoder *dec)
|
||||
{
|
||||
dec->magic = 0xDE57801D;
|
||||
free(dec);
|
||||
if (dec) dec->magic = 0xDE57801D;
|
||||
opus_free(dec);
|
||||
}
|
||||
|
||||
int opus_dred_decoder_ctl(OpusDREDDecoder *dred_dec, int request, ...)
|
||||
|
@ -1372,7 +1372,7 @@ OpusDRED *opus_dred_alloc(int *error)
|
|||
void opus_dred_free(OpusDRED *dec)
|
||||
{
|
||||
#ifdef ENABLE_DRED
|
||||
free(dec);
|
||||
opus_free(dec);
|
||||
#else
|
||||
(void)dec;
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue