<commit_before>/*
 * Copyright (C) 2010 <NAME>
 *
 * 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.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */


#include <unary_base.h>

#include <math.h>


static GstFlowReturn
transform_ip (GstBaseTransform * trans, GstBuffer * buf)
{
  GstAudioFilter *audiofilter = GST_AUDIO_FILTER (trans);
  GstBufferFormat format = audiofilter->format.format;

  gpointer data = GST_BUFFER_DATA (buf);
  gpointer data_end = GST_BUFFER_DATA (buf) + GST_BUFFER_SIZE (buf);

  if (format >= GST_FLOAT64_LE) {
    double *ptr, *end = data_end;
    for (ptr = data; ptr < end; ptr++)
      *ptr = log (*ptr);
  } else if (format >= GST_FLOAT32_LE) {
    float *ptr, *end = data_end;
    for (ptr = data; ptr < end; ptr++)
      *ptr = logf (*ptr);
  } else {
    g_assert_not_reached ();
  }

  return GST_FLOW_OK;
}


/*
 * ============================================================================
 *
 *                                Type Support
 *
 * ============================================================================
 */


static void
base_init (gpointer class)
{
  gst_element_class_set_details_simple (GST_ELEMENT_CLASS (class),
      "Natural logarithm",
      "Filter/Audio",
      "Calculate natural logarithm, y = ln x",
      "<NAME> <<EMAIL>>");
}


static void
class_init (gpointer class, gpointer class_data)
{
  GstBaseTransformClass *basetransform_class = GST_BASE_TRANSFORM_CLASS (class);
  basetransform_class->transform_ip = GST_DEBUG_FUNCPTR (transform_ip);
}


GType
unary_ln_get_type (void)
{
  static GType type = 0;

  if (!type) {
    static const GTypeInfo info = {
      .class_size = sizeof (UnaryBaseClass),
      .base_init = base_init,
      .class_init = class_init,
      .instance_size = sizeof (UnaryBase),
    };
    type = g_type_register_static (UNARY_BASE_TYPE, "UnaryLn", &info, 0);
  }

  return type;
}
<commit_msg>Update unary_ln.c<commit_after>/*
 * Copyright (C) 2010 <NAME>
 * Copyright (C) 2016 <NAME>
 *
 * 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.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */


#include <unary_base.h>

#include <math.h>


static GstFlowReturn
transform_ip (GstBaseTransform * trans, GstBuffer * buf)
{
  GstAudioFilter *audiofilter = GST_AUDIO_FILTER (trans);
  GstAudioFormat format = audiofilter->info.finfo->format;

  GstMapInfo info;
  gst_buffer_map (buf, &info, GST_MAP_READ);
  gpointer data = info.data;
  gpointer data_end = data + info.size;
  gst_buffer_unmap (buf, &info);

  if (format >= GST_AUDIO_FORMAT_F64) {
    double *ptr, *end = data_end;
    for (ptr = data; ptr < end; ptr++)
      *ptr = log (*ptr);
  } else if (format >= GST_AUDIO_FORMAT_F32) {
    float *ptr, *end = data_end;
    for (ptr = data; ptr < end; ptr++)
      *ptr = logf (*ptr);
  } else {
    g_assert_not_reached ();
  }

  return GST_FLOW_OK;
}


/*
 * ============================================================================
 *
 *                                Type Support
 *
 * ============================================================================
 */


static void
base_init (gpointer class)
{
  gst_element_class_set_details_simple (GST_ELEMENT_CLASS (class),
      "Natural logarithm",
      "Filter/Audio",
      "Calculate natural logarithm, y = ln x",
      "<NAME> <<EMAIL>>, <NAME> <<EMAIL>>");
}


static void
class_init (gpointer class, gpointer class_data)
{
  GstBaseTransformClass *basetransform_class = GST_BASE_TRANSFORM_CLASS (class);
  basetransform_class->transform_ip = GST_DEBUG_FUNCPTR (transform_ip);
}


GType
unary_ln_get_type (void)
{
  static GType type = 0;

  if (!type) {
    static const GTypeInfo info = {
      .class_size = sizeof (UnaryBaseClass),
      .base_init = base_init,
      .class_init = class_init,
      .instance_size = sizeof (UnaryBase),
    };
    type = g_type_register_static (UNARY_BASE_TYPE, "UnaryLn", &info, 0);
  }

  return type;
}

{'fraction_non_alphanumeric': 0.15493503975179368, 'fraction_numerical': 0.009307737056428156, 'mean_word_length': 3.689090909090909, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 28, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6571477', 'n_tokens_mistral': 1682, 'n_tokens_neox': 1569, 'n_words': 511}