<commit_before>// This file is part of the HörTech Open Master Hearing Aid (openMHA)
// Copyright © 2005 2006 2008 2009 2013 2014 2015 2016 2017 2020 HörTech gGmbH
//
// openMHA is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, version 3 of the License.
//
// openMHA 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 Affero General Public License, version 3 for more details.
//
// You should have received a copy of the GNU Affero General Public License, 
// version 3 along with openMHA.  If not, see <http://www.gnu.org/licenses/>.

#include "mha_io_ifc.h"
#include "mha_toolbox.h"
#include "mha_signal.hh"
#include "mha_events.h"
#include <math.h>


/** 
    \brief Main class for Parser IO

*/
class io_parser_t : public MHAParser::parser_t
{
public:
    io_parser_t(unsigned int fragsize, 
                IOProcessEvent_t proc_event,
                void* proc_handle,
                IOStartedEvent_t start_event,
                void* start_handle,
                IOStoppedEvent_t stop_event,
                void* stop_handle);
    ~io_parser_t();
    void prepare(int,int);
    void start();
    void stop();
    void release();
private:
    void stopped(int,int);
    void started();
    void process_frame();
    unsigned int fragsize;
    unsigned int nchannels_in;
    unsigned int nchannels_out;
    IOProcessEvent_t proc_event;
    void* proc_handle;
    IOStartedEvent_t start_event;
    void* start_handle;
    IOStoppedEvent_t stop_event;
    void* stop_handle;
    MHAParser::mfloat_t input;
    MHAParser::mfloat_mon_t output;
    MHASignal::waveform_t* s_in;
    mha_wave_t* s_out;
    bool b_fw_started;
    bool b_stopped;
    bool b_prepared;
    bool b_starting;
    MHAEvents::patchbay_t<io_parser_t> patchbay;
};

/** 
    \brief Remove JACK client and deallocate internal ports and buffers
  
*/
void io_parser_t::release()
{
    delete s_in;
    b_prepared = false;
}

/** 
    \brief Allocate buffers, activate JACK client and install internal ports
  
*/
void io_parser_t::prepare(int nch_in,int nch_out)
{
    if( nch_in < 1 )
        throw MHA_ErrorMsg("MHAIOParser: At least one input channel is required.");
    nchannels_in = nch_in;
    nchannels_out = nch_out;
    b_fw_started = false;
    b_stopped = false;
    b_prepared = true;
    s_in = new MHASignal::waveform_t(fragsize,nchannels_in);
}

io_parser_t::io_parser_t(unsigned int ifragsize, 
                         IOProcessEvent_t iproc_event,
                         void* iproc_handle,
                         IOStartedEvent_t istart_event,
                         void* istart_handle,
                         IOStoppedEvent_t istop_event,
                         void* istop_handle)
    : MHAParser::parser_t("process data from parser input"),
      fragsize(ifragsize),
      proc_event(iproc_event),
      proc_handle(iproc_handle),
      start_event(istart_event),
      start_handle(istart_handle),
      stop_event(istop_event),
      stop_handle(istop_handle),
      input("input signal buffer (size: nchannels x fragsize)","[[]]"),
      output("output signal buffer"),
      s_in(NULL),
      s_out(NULL),
      b_fw_started(false),
      b_stopped(false),
      b_prepared(false),
      b_starting(false)
{
    insert_item("input",&input);
    insert_item("output",&output);
    patchbay.connect(&input.writeaccess,this,&io_parser_t::process_frame);
}

void io_parser_t::start()
{
    if( !b_prepared )
        throw MHA_Error(__FILE__,__LINE__,
                        "MHAIOParser: Not prepared for start.");
    b_fw_started = true;
    b_stopped = false;
    b_starting = true;
}

void io_parser_t::stop()
{
    b_fw_started = false;
}

void io_parser_t::stopped(int proc_err,int io_err)
{
    if( stop_event )
        stop_event(stop_handle,proc_err,io_err);<commit_msg>MHAIOParser: Fix timeout on stop request<commit_after>// This file is part of the HörTech Open Master Hearing Aid (openMHA)
// Copyright © 2005 2006 2008 2009 2013 2014 2015 2016 2017 2020 HörTech gGmbH
//
// openMHA is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, version 3 of the License.
//
// openMHA 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 Affero General Public License, version 3 for more details.
//
// You should have received a copy of the GNU Affero General Public License, 
// version 3 along with openMHA.  If not, see <http://www.gnu.org/licenses/>.

#include "mha_io_ifc.h"
#include "mha_toolbox.h"
#include "mha_signal.hh"
#include "mha_events.h"
#include <math.h>


/** 
    \brief Main class for Parser IO

*/
class io_parser_t : public MHAParser::parser_t
{
public:
    io_parser_t(unsigned int fragsize, 
                IOProcessEvent_t proc_event,
                void* proc_handle,
                IOStartedEvent_t start_event,
                void* start_handle,
                IOStoppedEvent_t stop_event,
                void* stop_handle);
    ~io_parser_t();
    void prepare(int,int);
    void start();
    void stop();
    void release();
private:
    void stopped(int,int);
    void started();
    void process_frame();
    unsigned int fragsize;
    unsigned int nchannels_in;
    unsigned int nchannels_out;
    IOProcessEvent_t proc_event;
    void* proc_handle;
    IOStartedEvent_t start_event;
    void* start_handle;
    IOStoppedEvent_t stop_event;
    void* stop_handle;
    MHAParser::mfloat_t input;
    MHAParser::mfloat_mon_t output;
    MHASignal::waveform_t* s_in;
    mha_wave_t* s_out;
    bool b_fw_started;
    bool b_stopped;
    bool b_prepared;
    bool b_starting;
    MHAEvents::patchbay_t<io_parser_t> patchbay;
};

/** 
    \brief Remove JACK client and deallocate internal ports and buffers
  
*/
void io_parser_t::release()
{
    delete s_in;
    b_prepared = false;
}

/** 
    \brief Allocate buffers, activate JACK client and install internal ports
  
*/
void io_parser_t::prepare(int nch_in,int nch_out)
{
    if( nch_in < 1 )
        throw MHA_ErrorMsg("MHAIOParser: At least one input channel is required.");
    nchannels_in = nch_in;
    nchannels_out = nch_out;
    b_fw_started = false;
    b_stopped = false;
    b_prepared = true;
    s_in = new MHASignal::waveform_t(fragsize,nchannels_in);
}

io_parser_t::io_parser_t(unsigned int ifragsize, 
                         IOProcessEvent_t iproc_event,
                         void* iproc_handle,
                         IOStartedEvent_t istart_event,
                         void* istart_handle,
                         IOStoppedEvent_t istop_event,
                         void* istop_handle)
    : MHAParser::parser_t("process data from parser input"),
      fragsize(ifragsize),
      proc_event(iproc_event),
      proc_handle(iproc_handle),
      start_event(istart_event),
      start_handle(istart_handle),
      stop_event(istop_event),
      stop_handle(istop_handle),
      input("input signal buffer (size: nchannels x fragsize)","[[]]"),
      output("output signal buffer"),
      s_in(NULL),
      s_out(NULL),
      b_fw_started(false),
      b_stopped(false),
      b_prepared(false),
      b_starting(false)
{
    insert_item("input",&input);
    insert_item("output",&output);
    patchbay.connect(&input.writeaccess,this,&io_parser_t::process_frame);
}

void io_parser_t::start()
{
    if( !b_prepared )
        throw MHA_Error(__FILE__,__LINE__,
                        "MHAIOParser: Not prepared for start.");
    b_fw_started = true;
    b_stopped = false;
    b_starting = true;
}

void io_parser_t::stop()
{
    b_fw_started = false;
    // The below code does not cause a race condition as all process callbacks
    // are also called from the configuration thread. This is a special case
    // and can not be generalized to other io libraries.
    stopped(0,0);
}

void io_parser_t::stopped(int proc_err,int io_err)
{
    if( stop_event )
        stop_event(stop_handle,proc_err,io_err);
{'fraction_non_alphanumeric': 0.0898755385351843, 'fraction_numerical': 0.01077070368597415, 'mean_word_length': 2.8476058931860035, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '4021497', 'n_tokens_mistral': 2831, 'n_tokens_neox': 2645, 'n_words': 723}