<commit_before>/*** MODULEINFO
	<depend>amr_nb</depend>
 ***/

#include "asterisk.h"

/* version 1.0 */
/* based on codecs/codec_opus.c */

#include "asterisk/codec.h"             /* for AST_MEDIA_TYPE_AUDIO */
#include "asterisk/frame.h"             /* for ast_frame, etc */
#include "asterisk/linkedlists.h"       /* for AST_LIST_NEXT, etc */
#include "asterisk/logger.h"            /* for ast_log, ast_debug, etc */
#include "asterisk/module.h"
#include "asterisk/translate.h"         /* for ast_trans_pvt, etc */

#include <opencore-amrnb/interf_dec.h>
#include <opencore-amrnb/interf_enc.h>

#define BUFFER_SAMPLES     8000 /* 1000 milliseconds */
#define GSM_EFR_SAMPLES    160
#define GSM_EFR_FRAME_LEN  32

/* Sample frame data */
#include "asterisk/slin.h"
#include "ex_gsm_efr.h"

struct efr_coder_pvt {
	void *state; /* May be encoder or decoder */
	short buf[BUFFER_SAMPLES];
};

static int lintoefr_new(struct ast_trans_pvt *pvt)
{
	struct efr_coder_pvt *apvt = pvt->pvt;
	const int dtx = 0;

	apvt->state = Encoder_Interface_init(dtx);

	if (NULL == apvt->state) {
		ast_log(LOG_ERROR, "Error creating the GSM-EFR encoder\n");
		return -1;
	}

	ast_debug(3, "Created encoder (GSM-EFR)\n");

	return 0;
}

static int efrtolin_new(struct ast_trans_pvt *pvt)
{
	struct efr_coder_pvt *apvt = pvt->pvt;

	apvt->state = Decoder_Interface_init();

	if (NULL == apvt->state) {
		ast_log(LOG_ERROR, "Error creating the GSM-EFR decoder\n");
		return -1;
	}

	ast_debug(3, "Created decoder (GSM-EFR)\n");

	return 0;
}

static int lintoefr_framein(struct ast_trans_pvt *pvt, struct ast_frame *f)
{
	struct efr_coder_pvt *apvt = pvt->pvt;

	/* XXX We should look at how old the rest of our stream is, and if it
	   is too old, then we should overwrite it entirely, otherwise we can
	   get artifacts of earlier talk that do not belong */
	memcpy(apvt->buf + pvt->samples, f->data.ptr, f->datalen);
	pvt->samples += f->samples;

	return 0;
}

static struct ast_frame *lintoefr_frameout(struct ast_trans_pvt *pvt)
{
	struct efr_coder_pvt *apvt = pvt->pvt;
	struct ast_frame *result = NULL;
	struct ast_frame *last = NULL;
	int samples = 0; /* output samples */

	while (pvt->samples >= GSM_EFR_SAMPLES) {
		struct ast_frame *current;
		const int forceSpeech = 0; /* ignored by underlying API anyway */
		unsigned char *out = pvt->outbuf.uc;
		const short *speech = apvt->buf + samples;
		int status, i; /* result value; either error or output bytes */

		status = Encoder_Interface_Encode(apvt->state, MR122, speech, out, forceSpeech);
<commit_msg>aligned with Asterisk coding-style guides<commit_after>/*** MODULEINFO
	<depend>amr_nb</depend>
 ***/

#include "asterisk.h"

/* version 1.0 */
/* based on codecs/codec_opus.c */

#include "asterisk/codec.h"             /* for AST_MEDIA_TYPE_AUDIO */
#include "asterisk/frame.h"             /* for ast_frame, etc */
#include "asterisk/linkedlists.h"       /* for AST_LIST_NEXT, etc */
#include "asterisk/logger.h"            /* for ast_log, ast_debug, etc */
#include "asterisk/module.h"
#include "asterisk/translate.h"         /* for ast_trans_pvt, etc */

#include <opencore-amrnb/interf_dec.h>
#include <opencore-amrnb/interf_enc.h>

#define BUFFER_SAMPLES     8000 /* 1000 milliseconds */
#define GSM_EFR_SAMPLES    160
#define GSM_EFR_FRAME_LEN  32

/* Sample frame data */
#include "asterisk/slin.h"
#include "ex_gsm_efr.h"

struct efr_coder_pvt {
	void *state; /* May be encoder or decoder */
	short buf[BUFFER_SAMPLES];
};

static int lintoefr_new(struct ast_trans_pvt *pvt)
{
	struct efr_coder_pvt *apvt = pvt->pvt;
	const int dtx = 0;

	apvt->state = Encoder_Interface_init(dtx);

	if (NULL == apvt->state) {
		ast_log(LOG_ERROR, "Error creating the GSM-EFR encoder\n");
		return -1;
	}

	ast_debug(3, "Created encoder (GSM-EFR)\n");

	return 0;
}

static int efrtolin_new(struct ast_trans_pvt *pvt)
{
	struct efr_coder_pvt *apvt = pvt->pvt;

	apvt->state = Decoder_Interface_init();

	if (NULL == apvt->state) {
		ast_log(LOG_ERROR, "Error creating the GSM-EFR decoder\n");
		return -1;
	}

	ast_debug(3, "Created decoder (GSM-EFR)\n");

	return 0;
}

static int lintoefr_framein(struct ast_trans_pvt *pvt, struct ast_frame *f)
{
	struct efr_coder_pvt *apvt = pvt->pvt;

	/* XXX We should look at how old the rest of our stream is, and if it
	   is too old, then we should overwrite it entirely, otherwise we can
	   get artifacts of earlier talk that do not belong */
	memcpy(apvt->buf + pvt->samples, f->data.ptr, f->datalen);
	pvt->samples += f->samples;

	return 0;
}

static struct ast_frame *lintoefr_frameout(struct ast_trans_pvt *pvt)
{
	struct efr_coder_pvt *apvt = pvt->pvt;
	struct ast_frame *result = NULL;
	struct ast_frame *last = NULL;
	int samples = 0; /* output samples */

	while (pvt->samples >= GSM_EFR_SAMPLES) {
		struct ast_frame *current;
		const int force_speech = 0; /* ignored by underlying API anyway */
		unsigned char *out = pvt->outbuf.uc;
		const short *speech = apvt->buf + samples;
		int status, i; /* result value; either error or output bytes */

		status = Encoder_Interface_Encode(apvt->state, MR122, speech, out, force_speech);

{'fraction_non_alphanumeric': 0.12895044869293795, 'fraction_numerical': 0.01092469761997659, 'mean_word_length': 3.7737430167597767, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 49, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6163071', 'n_tokens_mistral': 2031, 'n_tokens_neox': 1925, 'n_words': 504}