Coder Social home page Coder Social logo

Comments (3)

peter-marcisovsky avatar peter-marcisovsky commented on July 17, 2024 1

Hello, the problem here is data format. In the esp-dsp repository, all the _s16_ functions use Q15 fixed point data format. In your code, you are feeding the function with incorrect inputs, which causes an output overflow, and this is the reason why you are getting -1 output for your input.

Peter

from esp-dsp.

guilhAbreu avatar guilhAbreu commented on July 17, 2024

@peter-marcisovsky Wouldn't be the case to implement the shift parameter as it is implemented for dsps_add_s16?

from esp-dsp.

guilhAbreu avatar guilhAbreu commented on July 17, 2024

@peter-marcisovsky Thank you for your time, and I'm sorry to continue to bother you. I took a look at both ANSI and ae32 implementations, and simply just removing the shift instruction solved the problem. It would be very helpful if the shift parameter could be implemented.

For those who are facing the same issue. I'm talking about lines 41 and 24 of the ae32 and ANSI implementation, respectively. I'm appending here the custom implementations that solve the problem for me.

#include "dsps_mulc_platform.h"
#if (dsps_mulc_s16_ae32_enabled == 1)

    .text
    .align  4
    .global dsps_mulc_s16_ae32_custom
    .type   dsps_mulc_s16_ae32_custom,@function

dsps_mulc_s16_ae32_custom: 
// input    - a2
// output   - a3
// len      - a4
// C        - a5
// step_in  - a6
// step_out - a7
// shift    - stack (a8)

    entry	a1, 16
    
    l32i.n	a8, a1,  16     // Load shift to the a8 register
    ssr     a8              // sar = a8

    srli    a4, a4, 1   // a4 = a4>>1
    slli 	a6, a6, 2  	// a6 - step_in<<3, because we load two inputs per loop
    slli 	a7, a7, 1  	// a7 - step_out<<2

    addi    a6, a6, -4;
    addi    a2, a2, -4;

	ldinc m0, a2

    loopnez a4, loop_end_mulc_f32_ae32
        add.n       a2, a2, a6     // input+=step_input;
        mul.DA.LL   m0, a5 
        rsr a8, acchi
        rsr a9, acclo
        src a8, a8, a9  // Here result in a8
    	s16i	a8, a3, 0   // store result to the putput        
        // rsr a9, acclo
    	// s16i	a9, a3, 0   // store result to the putput        
        add.n   a3, a3, a7     // output+=step_out;
        mul.DA.HL   m0, a5         

        rsr a8, acchi
        rsr a9, acclo
	    ldinc       m0,   a2               // load next data
        src a10, a8, a9  // Here result in a8
    	s16i	a10, a3, 0   // store result to the putput
        // // rsr a9, acclo
    	// // s16i	a9, a3, 0   // store result to the putput        
        add.n   a3, a3, a7  // output+=step_out;
loop_end_mulc_f32_ae32:
    movi.n	a2, 0 // return status ESP_OK
    retw.n
    
#endif // dsps_mulc_s16_ae32_enabled
esp_err_t dsps_mulc_s16_ansi_custom(const int16_t *input, int16_t *output, int len, int16_t C, int step_in, int step_out, int shift)
{
    if (NULL == input) return ESP_ERR_DSP_PARAM_OUTOFRANGE;
    if (NULL == output) return ESP_ERR_DSP_PARAM_OUTOFRANGE;

    for (int i = 0 ; i < len ; i++) {
        int32_t acc = (int32_t)input[i * step_in] * (int32_t)C;
        output[i * step_out] = (int16_t)(acc>>shift);
    }
    return ESP_OK;
}

from esp-dsp.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.