[Sound-open-firmware] [PATCH 2/4] Tone: Add channel specific volume plus other fixes

Pierre-Louis Bossart pierre-louis.bossart at linux.intel.com
Mon Jun 26 16:21:58 CEST 2017


On 6/26/17 5:28 AM, Liam Girdwood wrote:
> On Thu, 2017-06-22 at 15:22 +0300, Seppo Ingalsuo wrote:
>>> Thanks, that works. At least with the compiler that I use
>>> (http://alsa-project.org/main/index.php/Firmware) the optimizing
>> does
>>> the conversion to fixed without increase of the firmware image size.
>> I
>>> also checked from disassembly that this part of the code remains
>>> identical. I did a minor fix and added rounding into the macro
>> since
>>> compiler doesn't round the cast to int:
>>>
>>> #define TONE_FREQ(f)    (int)((f) * (1 << 16))    /* f = float */
>>>
>>> #define TONE_FREQ(f)    (((int)((f) * (1 << 17)) + 1) >> 1)  /* f =
>>> float */
>>
>> Sorry, the rounded version overflows and depending on the way 20000
>> vs.
>> 20000.0 as the parameter the compiler may even pass it silently.
>> However
>> this way the rounded Q16.16 conversion seems to work:
>>
>> #define TONE_FREQ(f) (int)(((int64_t)((f) * 131072.0 + 1.0)) >> 1) /*
>> f
>> = float */
>
> Best to make 131072.0 a macro too so easy to understand what it's doing.

Hehe, I've done things like this in 1999...we should be able to compile 
all this DSP code in both fixed and floating point formats, with macros 
the tables can be generated in the two modes and the low-level code can 
be maintained with two different implementations of the baseline. I used 
a 'Fract' typedef to represent both fixed point and floating point 
representations.

It helps if all your floating point constants are represented as 
[-1.0,1.0[ since it's a direct map with the fractional representation. 
If you want more bits for the integer part then you can add this as an 
argument to the macro. You can also add a MAXVAL if you want to quantize 
with less than 32 bits total.


>
> We should also have this as our non optimal "generic" version and we
> should look to create arch specific macros (with inline assembler) later
> on (that take take of overflow or larger types).
>
> Liam
>
> ---------------------------------------------------------------------
> Intel Corporation (UK) Limited
> Registered No. 1134945 (England)
> Registered Office: Pipers Way, Swindon SN3 1RJ
> VAT No: 860 2173 47
>
> This e-mail and any attachments may contain confidential material for
> the sole use of the intended recipient(s). Any review or distribution
> by others is strictly prohibited. If you are not the intended
> recipient, please contact the sender and delete all copies.
> _______________________________________________
> Sound-open-firmware mailing list
> Sound-open-firmware at alsa-project.org
> http://mailman.alsa-project.org/mailman/listinfo/sound-open-firmware
>



More information about the Sound-open-firmware mailing list