<commit_before>/*
 *  MAST: Multicast Audio Streaming Toolkit
 *
 *  By <NAME> <<EMAIL>>
 *
 *  Copyright (C) 2003-2007 University of Southampton
 *
 *  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 2 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.
 *
 *  $Id:$
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>

#include "config.h"
#include "codecs.h"
#include "mast.h"

#include "../libgsm/gsm.h"



static u_int32_t encode_gsm(
		mast_codec_t* codec,
		u_int32_t inputsize, 	// input size in samples
		int16_t *input,
		u_int32_t outputsize,	// output size in bytes
		u_int8_t *output)
{
	gsm gsm_handle = codec->ptr;
	int frames = (inputsize/GSM_FRAME_SAMPLES);
	int f = 0;
	
	if (inputsize % GSM_FRAME_SAMPLES) {
		MAST_DEBUG("encode_gsm: number of input samples isn't a multiple of 160 (%d)", inputsize);
	}

	if (outputsize < (frames*GSM_FRAME_BYTES)) {
		MAST_ERROR("encode_gsm: output buffer isn't big enough");
		return -1;
	}

	// Encode frame by frame
	for(f=0; f<frames; f++) {
		gsm_signal* signal = input+(GSM_FRAME_SAMPLES*f);
		gsm_byte* byte = output+(GSM_FRAME_BYTES*f);
		gsm_encode(gsm_handle, signal, byte);
	}

	return frames*GSM_FRAME_BYTES;
}


static u_int32_t decode_gsm(
		mast_codec_t* codec,
		u_int32_t inputsize,		// input size in bytes
		u_int8_t  *input,
		u_int32_t outputsize, 	// output size in samples
		int16_t  *output)
{
	gsm gsm_handle = codec->ptr;
	int frames = (inputsize/GSM_FRAME_BYTES);
	int f = 0;
	
	if (outputsize < (frames*GSM_FRAME_SAMPLES)) {
		MAST_ERROR("decode_gsm: output buffer isn't big enough");
		return -1;
	}

	// Decode frame by frame
	for(f=0; f<frames; f++) {
		gsm_byte* byte = input+(GSM_FRAME_BYTES*f);
		gsm_signal* signal = output+(GSM_FRAME_SAMPLES*f);
		gsm_decode(gsm_handle, byte, signal);
	}

	return frames*GSM_FRAME_SAMPLES;
}


static int deinit_gsm( mast_codec_t* codec )
{
	gsm gsm_handle = codec->ptr;<commit_msg>Fix for pointer position calculations<commit_after>/*
 *  MAST: Multicast Audio Streaming Toolkit
 *
 *  By <NAME> <<EMAIL>>
 *
 *  Copyright (C) 2003-2007 University of Southampton
 *
 *  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 2 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.
 *
 *  $Id:$
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>

#include "config.h"
#include "codecs.h"
#include "mast.h"

#include "../libgsm/gsm.h"



static u_int32_t encode_gsm(
		mast_codec_t* codec,
		u_int32_t inputsize, 	// input size in samples
		int16_t *input,
		u_int32_t outputsize,	// output size in bytes
		u_int8_t *output)
{
	gsm gsm_handle = codec->ptr;
	int frames = (inputsize/GSM_FRAME_SAMPLES);
	int f = 0;
	
	if (inputsize % GSM_FRAME_SAMPLES) {
		MAST_DEBUG("encode_gsm: number of input samples (%d) isn't a multiple of %d", inputsize, GSM_FRAME_SAMPLES);
	}

	if (outputsize < (frames*GSM_FRAME_BYTES)) {
		MAST_ERROR("encode_gsm: output buffer isn't big enough");
		return -1;
	}

	// Encode frame by frame
	for(f=0; f<frames; f++) {
		gsm_signal* signal = &input[GSM_FRAME_SAMPLES*f];
		gsm_byte* byte = output+(GSM_FRAME_BYTES*f);
		gsm_encode(gsm_handle, signal, byte);
	}

	return frames*GSM_FRAME_BYTES;
}


static u_int32_t decode_gsm(
		mast_codec_t* codec,
		u_int32_t inputsize,		// input size in bytes
		u_int8_t  *input,
		u_int32_t outputsize, 	// output size in samples
		int16_t  *output)
{
	gsm gsm_handle = codec->ptr;
	int frames = (inputsize/GSM_FRAME_BYTES);
	int f = 0;
	
	if (outputsize < (frames*GSM_FRAME_SAMPLES)) {
		MAST_ERROR("decode_gsm: output buffer isn't big enough");
		return -1;
	}

	// Decode frame by frame
	for(f=0; f<frames; f++) {
		gsm_byte* byte = input+(GSM_FRAME_BYTES*f);
		gsm_signal* signal = &output[GSM_FRAME_SAMPLES*f];
		gsm_decode(gsm_handle, byte, signal);
	}

	return frames*GSM_FRAME_SAMPLES;
}


static int deinit_gsm( mast_codec_t* codec )
{
	gsm gsm_handle = codec->ptr;
{'fraction_non_alphanumeric': 0.1108760050782903, 'fraction_numerical': 0.014600084638171815, 'mean_word_length': 4.082795698924731, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 23, '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': '7100896', 'n_tokens_mistral': 1890, 'n_tokens_neox': 1772, 'n_words': 508}