<commit_before>/*
 *  MAST: Multicast Audio Streaming Toolkit
 *
 *  Copyright (C) 2003-2007 <NAME> <<EMAIL>>
 *
 *  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 <netinet/in.h>
#include <twolame.h>

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


typedef struct
{
	twolame_options *twolame;
	int prepared;
} mast_mpegaudio_t;


// Calculate the number of samples per packet
static int mast_samples_per_packet_mpa( mast_codec_t *codec, int max_bytes)
{
	mast_mpegaudio_t* p = codec->ptr;
	int frames_per_packet = max_bytes/twolame_get_framelength( p->twolame );
	MAST_DEBUG("MPEG Audio Frames per Packet: %d", frames_per_packet );
	
	return frames_per_packet*TWOLAME_SAMPLES_PER_FRAME;
}


// Prepare to start encoding/decoding
static int mast_prepare_mpa( mast_codec_t *codec )
{
	mast_mpegaudio_t* p = codec->ptr;

	return twolame_init_params( p->twolame );
}


static int mast_set_param_mpa( mast_codec_t* codec, const char* name, const char* value )
{
	mast_mpegaudio_t* p = codec->ptr;

	/*	Parameters listed in RFC3555 for audio/MPA:
	
		layer: 1,2,3
		samplerate: 
		mode: "stereo", "joint_stereo", "single_channel", "dual_channel"
		bitrate: the data rate for the audio bit stream
		ptime: duration of each packet in milliseconds
		maxptime: maximum duration of each packet in milliseconds
		
		Example:
		audio/MPA;layer=2;mode=stereo;bitrate=160;
	*/
	
	if (strcmp(name, "layer")==0) {
		int layer = atoi(value);
		if (layer!=2) return -2;
	} else if (strcmp(name, "mode")==0) {
		int mode;
		if (strcmp(value, "stereo")==0) mode = TWOLAME_STEREO;
		else if (strcmp(value, "joint_stereo")==0) mode = TWOLAME_JOINT_STEREO;
		else if (strcmp(value, "single_channel")==0) mode = TWOLAME_MONO;
		else if (strcmp(value, "dual_channel")==0) mode = TWOLAME_DUAL_CHANNEL;
		else return -2;
		
		if (twolame_set_mode( p->twolame, mode )) {
			MAST_WARNING("Failed to set mode");
		}
	} else if (strcmp(name, "bitrate")==0) {
		int bitrate = atoi(value);
		if (twolame_set_bitrate( p->twolame, bitrate )) {
			MAST_WARNING("Failed to set bitrate");
		}
	} else {
		// Unsupported parameter
		return -1;
	}
	
	// Success
	return 0;
}

static const char* mast_get_param_mpa( mast_codec_t* codec, const char* name )
{

	if (strcmp(name, "layer")==0) {
		// We only support layer 2
		return "2";
	} else {
		// Unsupported
		return NULL;
	}

}<commit_msg>Added some debugging when setting the bitrate (to ensure it is working)<commit_after>/*
 *  MAST: Multicast Audio Streaming Toolkit
 *
 *  Copyright (C) 2003-2007 <NAME> <<EMAIL>>
 *
 *  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 <netinet/in.h>
#include <twolame.h>

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


typedef struct
{
	twolame_options *twolame;
	int prepared;
} mast_mpegaudio_t;


// Calculate the number of samples per packet
static int mast_samples_per_packet_mpa( mast_codec_t *codec, int max_bytes)
{
	mast_mpegaudio_t* p = codec->ptr;
	int frames_per_packet = max_bytes/twolame_get_framelength( p->twolame );
	MAST_DEBUG("MPEG Audio Frames per Packet: %d", frames_per_packet );
	
	return frames_per_packet*TWOLAME_SAMPLES_PER_FRAME;
}


// Prepare to start encoding/decoding
static int mast_prepare_mpa( mast_codec_t *codec )
{
	mast_mpegaudio_t* p = codec->ptr;

	return twolame_init_params( p->twolame );
}


static int mast_set_param_mpa( mast_codec_t* codec, const char* name, const char* value )
{
	mast_mpegaudio_t* p = codec->ptr;

	/*	Parameters listed in RFC3555 for audio/MPA:
	
		layer: 1,2,3
		samplerate: 
		mode: "stereo", "joint_stereo", "single_channel", "dual_channel"
		bitrate: the data rate for the audio bit stream
		ptime: duration of each packet in milliseconds
		maxptime: maximum duration of each packet in milliseconds
		
		Example:
		audio/MPA;layer=2;mode=stereo;bitrate=160;
	*/
	
	if (strcmp(name, "layer")==0) {
		int layer = atoi(value);
		if (layer!=2) return -2;
	} else if (strcmp(name, "mode")==0) {
		int mode;
		if (strcmp(value, "stereo")==0) mode = TWOLAME_STEREO;
		else if (strcmp(value, "joint_stereo")==0) mode = TWOLAME_JOINT_STEREO;
		else if (strcmp(value, "single_channel")==0) mode = TWOLAME_MONO;
		else if (strcmp(value, "dual_channel")==0) mode = TWOLAME_DUAL_CHANNEL;
		else return -2;
		
		if (twolame_set_mode( p->twolame, mode )) {
			MAST_WARNING("Failed to set mode");
		}
	} else if (strcmp(name, "bitrate")==0) {
		int bitrate = atoi(value);
		if (twolame_set_bitrate( p->twolame, bitrate )) {
			MAST_WARNING("Failed to set bitrate");
		} else {
			MAST_DEBUG("Set bitrate to %d", bitrate);
		}
	} else {
		// Unsupported parameter
		return -1;
	}
	
	// Success
	return 0;
}

static const char* mast_get_param_mpa( mast_codec_t* codec, const char* name )
{

	if (strcmp(name, "layer")==0) {
		// We only support layer 2
		return "2";
	} else {
		// Unsupported
		return NULL;
	}

}
{'fraction_non_alphanumeric': 0.117003367003367, 'fraction_numerical': 0.011784511784511785, 'mean_word_length': 4.170583115752828, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 35, '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': '4284792', 'n_tokens_mistral': 2317, 'n_tokens_neox': 2154, 'n_words': 635}