<commit_before>/*
 * producer_blipflash.c -- blip/flash generating producer
 * Copyright (C) 2013 <NAME>
 * Author: <NAME> <<EMAIL>>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

#include <framework/mlt.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

/** Fill an audio buffer with 1kHz "blip" samples.
*/

static void fill_blip( mlt_properties producer_properties, float* buffer, int frequency, int channels, int samples )
{
	int new_size = samples * channels * sizeof( float );
	int old_size = 0;
	float* blip = mlt_properties_get_data( producer_properties, "_blip", &old_size );

	if( !blip || new_size > old_size )
	{
		blip = mlt_pool_alloc( new_size );

		// Fill the blip buffer
		if ( blip != NULL )
		{
			int s = 0;
			int c = 0;

			for( s = 0; s < samples; s++ )
			{
				float f = 1000.0;
				float t = (float)s/(float)frequency;
				// Add 90 deg so the blip always starts at 1 for easy detection.
				float phase = M_PI / 2;
				float value = sin( 2*M_PI*f*t + phase );

				for( c = 0; c < channels; c++ )
				{
					float* sample_ptr = ((float*) blip) + (c * samples) + s;
					*sample_ptr = value;
				}
			}
		}
		// Cache the audio blip to save from regenerating it with every blip.
		mlt_properties_set_data( producer_properties, "_blip", blip, new_size, mlt_pool_release, NULL );
	};

	if( blip ) memcpy( buffer, blip, new_size );
}

static int producer_get_audio( mlt_frame frame, int16_t** buffer, mlt_audio_format* format, int* frequency, int* channels, int* samples )
{
	mlt_producer producer = mlt_properties_get_data( MLT_FRAME_PROPERTIES( frame ), "_producer_blipflash", NULL );
	mlt_properties producer_properties = MLT_PRODUCER_PROPERTIES( producer );
	int size = *samples * *channels * sizeof( float );
	double fps = mlt_producer_get_fps( producer );
	int frames = mlt_frame_get_position( frame )  + mlt_properties_get_int( producer_properties, "offset" );
	int seconds = frames / fps;

	// Correct the returns if necessary
	*format = mlt_audio_float;
	*frequency = *frequency <= 0 ? 48000 : *frequency;
	*channels = *channels <= 0 ? 2 : *channels;
	*samples = *samples <= 0 ? mlt_sample_calculator( fps, *frequency, frames ) : *samples;

	// Allocate the buffer
	*buffer = mlt_pool_alloc( size );

	// Determine if this should be a blip or silence.
	frames = frames % lrint( fps );
	seconds = seconds % mlt_properties_get_int( producer_properties, "period" );
	if( seconds == 0 && frames == 0 )
	{
		fill_blip( producer_properties, (float*)*buffer, *frequency, *channels, *samples );
	}
	else
	{
		// Fill silence.
		memset( *buffer, 0, size );
	}

	// Set the buffer for destruction
	mlt_frame_set_audio( frame, *buffer, *format, size, mlt_pool_release );

	return 0;
}

/** Fill an image buffer with either white (flash) or black as requested.
*/

static void fill_image( mlt_properties producer_properties, char* color, uint8_t* buffer, mlt_image_format format, int width, int height )
{

	int new_size = mlt_image_format_size( format, width, height, NULL );
	int old_size = 0;
	uint8_t* image = image = mlt_properties_get_data( producer_properties, color, &old_size );

	if( !image || new_size > old_size )
	{
		// Need to create a new cached image.
		image = mlt_pool_alloc( new_size );

		if ( image != NULL )
		{
			uint8_t r, g, b;<commit_msg>Fix superfluous assigment in initialization (coverity-1026782).<commit_after>/*
 * producer_blipflash.c -- blip/flash generating producer
 * Copyright (C) 2013 <NAME>
 * Author: <NAME> <<EMAIL>>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

#include <framework/mlt.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

/** Fill an audio buffer with 1kHz "blip" samples.
*/

static void fill_blip( mlt_properties producer_properties, float* buffer, int frequency, int channels, int samples )
{
	int new_size = samples * channels * sizeof( float );
	int old_size = 0;
	float* blip = mlt_properties_get_data( producer_properties, "_blip", &old_size );

	if( !blip || new_size > old_size )
	{
		blip = mlt_pool_alloc( new_size );

		// Fill the blip buffer
		if ( blip != NULL )
		{
			int s = 0;
			int c = 0;

			for( s = 0; s < samples; s++ )
			{
				float f = 1000.0;
				float t = (float)s/(float)frequency;
				// Add 90 deg so the blip always starts at 1 for easy detection.
				float phase = M_PI / 2;
				float value = sin( 2*M_PI*f*t + phase );

				for( c = 0; c < channels; c++ )
				{
					float* sample_ptr = ((float*) blip) + (c * samples) + s;
					*sample_ptr = value;
				}
			}
		}
		// Cache the audio blip to save from regenerating it with every blip.
		mlt_properties_set_data( producer_properties, "_blip", blip, new_size, mlt_pool_release, NULL );
	};

	if( blip ) memcpy( buffer, blip, new_size );
}

static int producer_get_audio( mlt_frame frame, int16_t** buffer, mlt_audio_format* format, int* frequency, int* channels, int* samples )
{
	mlt_producer producer = mlt_properties_get_data( MLT_FRAME_PROPERTIES( frame ), "_producer_blipflash", NULL );
	mlt_properties producer_properties = MLT_PRODUCER_PROPERTIES( producer );
	int size = *samples * *channels * sizeof( float );
	double fps = mlt_producer_get_fps( producer );
	int frames = mlt_frame_get_position( frame )  + mlt_properties_get_int( producer_properties, "offset" );
	int seconds = frames / fps;

	// Correct the returns if necessary
	*format = mlt_audio_float;
	*frequency = *frequency <= 0 ? 48000 : *frequency;
	*channels = *channels <= 0 ? 2 : *channels;
	*samples = *samples <= 0 ? mlt_sample_calculator( fps, *frequency, frames ) : *samples;

	// Allocate the buffer
	*buffer = mlt_pool_alloc( size );

	// Determine if this should be a blip or silence.
	frames = frames % lrint( fps );
	seconds = seconds % mlt_properties_get_int( producer_properties, "period" );
	if( seconds == 0 && frames == 0 )
	{
		fill_blip( producer_properties, (float*)*buffer, *frequency, *channels, *samples );
	}
	else
	{
		// Fill silence.
		memset( *buffer, 0, size );
	}

	// Set the buffer for destruction
	mlt_frame_set_audio( frame, *buffer, *format, size, mlt_pool_release );

	return 0;
}

/** Fill an image buffer with either white (flash) or black as requested.
*/

static void fill_image( mlt_properties producer_properties, char* color, uint8_t* buffer, mlt_image_format format, int width, int height )
{

	int new_size = mlt_image_format_size( format, width, height, NULL );
	int old_size = 0;
	uint8_t* image = mlt_properties_get_data( producer_properties, color, &old_size );

	if( !image || new_size > old_size )
	{
		// Need to create a new cached image.
		image = mlt_pool_alloc( new_size );

		if ( image != NULL )
		{
			uint8_t r, g, b;
{'fraction_non_alphanumeric': 0.1094175960346964, 'fraction_numerical': 0.01449814126394052, 'mean_word_length': 3.850360576923077, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 25, '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': '7045230', 'n_tokens_mistral': 2877, 'n_tokens_neox': 2635, 'n_words': 923}