English 中文(简体)
Basic DSP - level adjustment
原标题:

I m new to DSP programming, and I m wondering how best to carry out the seemingly basic operation of level adujustment. Say I have an 8 bit number that represents the amplitude I want a signal to be in 256 steps. I have a set of 16 bit numbers representing the signal data. What s the best way to go about scaling the signal data based on the "volume" parameter so that say 0 is complete attenuation, and 255 leaves the data unchanged?

问题回答

What unwind said:

out_sample = in_sample * volume / 255;

If you re working on a real DSP chip or hardware without fast dividers you can use this trick to get the same values without division:

int product = in_sample * volume;
out_sample = (product + (product>>8) + 1)>>8;

On a modern DSP like the C64x+ this code runs about 10 times faster...

Also:

You re talking about volume, and you currently apply a 8 bit volume as a linear gain factor. However, our ears interpret volume as a logarithmic effect. You may want to do a conversion from db (your 8 bits) to linear gain prior to the multiplication. Precalculate them and put them into a table. While you re doing this you can also raise the scale of the value to 2^15 for more precision.

That ll give you a much nicer response and much less clicks of you do volume-fades.

How about

out_sample = in_sample * volume / 255;

A straight linear rescaling. This assumes that the computation can be done using higher precision, to capture the result of the multiplication without truncation.





相关问题
Least squares optimal scaling

I have two waveforms which are linked by a numerical factor. I need to use optimal scaling (least squares) between the two waveforms to calculate this factor in Matlab. Unfortunately I have no idea ...

How to Get a Quantitative Comparison of Two Signals

I’m trying to implement a Blind Source Separation (BSS) algorithm and I’m running into trouble determining the efficacy of the algorithm. I’m trying to create test cases where I work backwards and ...

数字过滤器设计

采用什么最佳方法选择马特拉布数字过滤器设计特性与全球数据分析仪的过滤器? 更具体地说,如果我有信号,我如何确定哪些过滤价值......。

DSP Algorithms Book [closed]

I m looking for a book similar to "Introduction to Algorithms" by Thomas Cormen geared towards DSP algorithms. Is there anything as thorough as Cormen on the DSP market? EDIT I should say I m ...

Digital Sound Processing in C# (and possibly SilverLight)

I need to do some basic and non basic DSP programming in C#. At its core, it includes the generation of a sin wave deciding its frequency in Hertz. Then I d like to Frequency Modulate it and maybe ...

Basic DSP - level adjustment

I m new to DSP programming, and I m wondering how best to carry out the seemingly basic operation of level adujustment. Say I have an 8 bit number that represents the amplitude I want a signal to be ...

Entertaining a baby with VB.NET

I would like to write a little application in VB.NET that will detect a baby s cry. How would I get started with such an application?

热门标签