?? sum.c
字號:
/*************************************************************************** * sum.c - Sums up all inputs * ------------------- * begin : 2003 * authors : ineiti * emails : linus.gasser@epfl.ch ***************************************************************************//*************************************************************************** * Changes * ------- * date - name - description * 03/01/16 - ineiti - begin * 04/03/08 - ineiti - adjusted description * **************************************************************************//*************************************************************************** * * * 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. * * * ***************************************************************************//** * Sums up complex-signal blocks to one block. For every module connected * it waits for available data, and only processes all data, once all modules * have something to send. */#include "spc.h"#define DBG_LVL 0#define MAX_INPUTS 10typedef struct { // The division done for every input. If it is 0, then weight = number // of input-signals int weight; // 0}config_t;typedef struct {}stats_t;typedef struct { int weight;}private_t;/* * The initialisation function, or constructor, * is called the first time this module is instantiated. */int spc_init( swr_sdb_t *context ) { // Begin system-definitions { config_t *config; stats_t *stats; MOD_INC_USE_COUNT; if ( sizeof( private_t ) > 0 ) context->private_data = swr_malloc( sizeof( private_t ) ); swr_sdb_get_config_struct( context->id, (void**)&config ); swr_sdb_get_stats_struct( context->id, (void**)&stats ); // } End of system-definitions private->weight = config->weight = 0; // Begin system-definitions swr_sdb_free_stats_struct( context->id, (void**)&stats ); swr_sdb_free_config_struct( context->id, (void**)&config ); return 0; // End system-definitions}/* * To configure the inputs * this is called when the output-sizes change. */int spc_configure_inputs( swr_sdb_t *context ) { int i; // Definition of variables - don't touch config_t *config; swr_sdb_get_config_struct( context->id, (void**)&config ); for ( i=0; i<MAX_INPUTS; i++ ) { port_in(i).size = port_out(0).size; } // Definition - don't touch swr_sdb_free_config_struct( context->id, (void**)&config ); return 0;}/* * To configure the outputs * this is called when the input-sizes change */int spc_configure_outputs( swr_sdb_t *context ) { // Definition of variables - don't touch config_t *config; swr_sdb_get_config_struct( context->id, (void**)&config ); // Hmm, this is difficult, as you're not allowed to have different // input-sizes. Well, let's just take the size of the first // input-port... port_out(0).size = port_in(0).size; // PR_DBG( 0, "Attention: configuring outputs in sum, this is not cool\n" ); // Definition - don't touch swr_sdb_free_config_struct( context->id, (void**)&config ); return 0;}/* * Every time modules from the outside change the value of a configuration parameter, * this function is called. */int spc_reconfig( swr_sdb_t *context ) { // Definition of variables - don't touch config_t *config; swr_sdb_get_config_struct( context->id, (void**)&config ); if ( config->weight ) { private->weight = config->weight; } // Definition - don't touch swr_sdb_free_config_struct( context->id, (void**)&config ); return 0;}/* * This is the function that implements the `main method' of the class * Every class has got just ONE method/working-mode. */int spc_pdata( swr_sdb_t *context ) { int inputs=0, i, j, weight; // Definition of variables - don't touch stats_t *stats; SYMBOL_COMPLEX *in[MAX_INPUTS], *out; // Search how many input-ports there are for ( i=0; i<MAX_INPUTS; i++ ) { if ( port_in( i ).sdb_id >= 0 ) { inputs++; } } PR_DBG( 4, "Found %i inputs\n", inputs ); // Look if all input-ports are filled for ( i=0; i<inputs; i++ ) { if ( !data_available( i ) ) { // Input-data is missing, return and wait for next round PR_DBG( 4, "Input %i is missing\n", i ); return 0; } } if ( inputs ) { // We have inputs, and all are filled with data // Prepare pointers PR_DBG( 4, "Calculating output\n" ); out = buffer_out( 0 ); for ( i=0; i<inputs; i++ ) { in[i] = buffer_in( i ); } if ( !( weight = private->weight ) ){ weight = inputs; } // And calculate for ( i=0; i<port_out(0).size; i++ ) { out[i].imag = out[i].real = 0; // Now this would be something for MMX for ( j=0; j<inputs; j++ ) { out[i].imag += in[j][i].imag / weight; out[i].real += in[j][i].real / weight; } } } swr_sdb_get_stats_struct( context->id, (void**)&stats ); // Put your code here // ADD HERE swr_sdb_free_stats_struct( context->id, (void**)&stats ); return(0);}/* * This is the `destructor'. */int spc_finalize( swr_sdb_t *context ) { if ( sizeof( private_t ) > 0 ) swr_free( private ); MOD_DEC_USE_COUNT; return 0;}/* * This function is called upon "insmod" and is used to register the * different parts of the module to the SPM. */swr_spc_id_t cdb_id;int spc_module_init(void) { swr_spc_desc_t *desc; int i; /** * Get a description-part from SPM * Give the following parameters: * Input-ports, output-ports, config-params, stat-params */ desc = swr_spc_get_new_desc( MAX_INPUTS, 1, 1, 0 ); if ( !desc ) { PR_DBG( 0, "Can't initialise the module. This is BAD!\n" ); return -1; } /** * Define the different parts of config and stats. You have to define * them in the same order as they appear in the structures. The names * can be freely chosen. * * UM_CONFIG_{INT,DOUBLE,STRING128,POINTER}( "name" ); * UM_STATS_{INT,DOUBLE,STRING128,POINTER,BLOCK}( "name" ); */ UM_CONFIG_INT( "weight" ); /** * The in- and outputs have also to be defined in the right order. First * port first. The additional flag is not used yet, but it will... * * UM_INPUT( SIG_{U8,SYMBOL_{S16,COMPLEX,MMX},SAMPLE_S12,S32}, 0 ); * UM_OUTPUT( SIG_{U8,SYMBOL_{S16,COMPLEX,MMX},SAMPLE_S12,S32}, 0 ); */ for ( i=0; i<MAX_INPUTS; i++ ) { UM_INPUT( SIG_SYMBOL_COMPLEX, 0 ); } UM_OUTPUT( SIG_SYMBOL_COMPLEX, 0 ); // Initialise the callback-functions. Delete the ones you don't use desc->fn_init = spc_init; desc->fn_reconfigure = spc_reconfig; desc->fn_process_data = spc_pdata; desc->fn_configure_inputs = spc_configure_inputs; desc->fn_configure_outputs = spc_configure_outputs; desc->fn_finalize = spc_finalize; // And register the module in the SPM. Change the name! cdb_id = swr_cdb_register_spc( &desc, "sum_symbol_complex" ); if ( cdb_id == SWR_SPM_INVALID_ID ) { swr_spc_free_desc( desc ); PR_DBG( 0, "Couldn't register the module!\n" ); return 1; } PR_DBG( 4, "Ready\n" ); return 0;}/* * This is called upon rmmod */void spc_module_exit( void ) { PR_DBG( 4, "Freeing id: %i\n", cdb_id ); if ( swr_cdb_unregister_spc( cdb_id ) < 0 ) { PR_DBG( 0, "Still in use somewhere\n" ); }}module_init( spc_module_init );module_exit( spc_module_exit );
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -