Commit 60f68735 authored by Antti Palosaari's avatar Antti Palosaari Committed by Mauro Carvalho Chehab

[media] vivid: sdr cap: few enhancements

* Constify struct

* Fix comments

* Fix alignment

* Use modulus to transfer phase angles

* Correct float [-1.0, +1.0] to s8 [-128, 127] conversion
Signed-off-by: default avatarAntti Palosaari <crope@iki.fi>
Signed-off-by: default avatarHans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@osg.samsung.com>
parent f335c3f2
...@@ -41,7 +41,7 @@ struct vivid_format { ...@@ -41,7 +41,7 @@ struct vivid_format {
}; };
/* format descriptions for capture and preview */ /* format descriptions for capture and preview */
static struct vivid_format formats[] = { static const struct vivid_format formats[] = {
{ {
.pixelformat = V4L2_SDR_FMT_CU8, .pixelformat = V4L2_SDR_FMT_CU8,
.buffersize = SDR_CAP_SAMPLES_PER_BUF * 2, .buffersize = SDR_CAP_SAMPLES_PER_BUF * 2,
...@@ -502,12 +502,6 @@ void vivid_sdr_cap_process(struct vivid_dev *dev, struct vivid_buffer *buf) ...@@ -502,12 +502,6 @@ void vivid_sdr_cap_process(struct vivid_dev *dev, struct vivid_buffer *buf)
s32 fixp_i; s32 fixp_i;
s32 fixp_q; s32 fixp_q;
/*
* TODO: Generated beep tone goes very crackly when sample rate is
* increased to ~1Msps or more. That is because of huge rounding error
* of phase angle caused by used cosine implementation.
*/
/* calculate phase step */ /* calculate phase step */
#define BEEP_FREQ 1000 /* 1kHz beep */ #define BEEP_FREQ 1000 /* 1kHz beep */
src_phase_step = DIV_ROUND_CLOSEST(FIXP_2PI * BEEP_FREQ, src_phase_step = DIV_ROUND_CLOSEST(FIXP_2PI * BEEP_FREQ,
...@@ -522,17 +516,15 @@ void vivid_sdr_cap_process(struct vivid_dev *dev, struct vivid_buffer *buf) ...@@ -522,17 +516,15 @@ void vivid_sdr_cap_process(struct vivid_dev *dev, struct vivid_buffer *buf)
dev->sdr_fixp_mod_phase += div_s64(s64tmp, M_100000PI); dev->sdr_fixp_mod_phase += div_s64(s64tmp, M_100000PI);
/* /*
* Transfer phases to [0 / 2xPI] in order to avoid variable * Transfer phase angle to [0, 2xPI] in order to avoid variable
* overflow and make it suitable for cosine implementation * overflow and make it suitable for cosine implementation
* used, which does not support negative angles. * used, which does not support negative angles.
*/ */
while (dev->sdr_fixp_mod_phase < FIXP_2PI) dev->sdr_fixp_src_phase %= FIXP_2PI;
dev->sdr_fixp_mod_phase += FIXP_2PI; dev->sdr_fixp_mod_phase %= FIXP_2PI;
while (dev->sdr_fixp_mod_phase > FIXP_2PI)
dev->sdr_fixp_mod_phase -= FIXP_2PI;
while (dev->sdr_fixp_src_phase > FIXP_2PI) if (dev->sdr_fixp_mod_phase < 0)
dev->sdr_fixp_src_phase -= FIXP_2PI; dev->sdr_fixp_mod_phase += FIXP_2PI;
fixp_i = fixp_cos32_rad(dev->sdr_fixp_mod_phase, FIXP_2PI); fixp_i = fixp_cos32_rad(dev->sdr_fixp_mod_phase, FIXP_2PI);
fixp_q = fixp_sin32_rad(dev->sdr_fixp_mod_phase, FIXP_2PI); fixp_q = fixp_sin32_rad(dev->sdr_fixp_mod_phase, FIXP_2PI);
...@@ -544,7 +536,7 @@ void vivid_sdr_cap_process(struct vivid_dev *dev, struct vivid_buffer *buf) ...@@ -544,7 +536,7 @@ void vivid_sdr_cap_process(struct vivid_dev *dev, struct vivid_buffer *buf)
switch (dev->sdr_pixelformat) { switch (dev->sdr_pixelformat) {
case V4L2_SDR_FMT_CU8: case V4L2_SDR_FMT_CU8:
/* convert 'fixp float' to u8 */ /* convert 'fixp float' to u8 [0, +255] */
/* u8 = X * 127.5 + 127.5; X is float [-1.0, +1.0] */ /* u8 = X * 127.5 + 127.5; X is float [-1.0, +1.0] */
fixp_i = fixp_i * 1275 + FIXP_FRAC * 1275; fixp_i = fixp_i * 1275 + FIXP_FRAC * 1275;
fixp_q = fixp_q * 1275 + FIXP_FRAC * 1275; fixp_q = fixp_q * 1275 + FIXP_FRAC * 1275;
...@@ -552,9 +544,10 @@ void vivid_sdr_cap_process(struct vivid_dev *dev, struct vivid_buffer *buf) ...@@ -552,9 +544,10 @@ void vivid_sdr_cap_process(struct vivid_dev *dev, struct vivid_buffer *buf)
*vbuf++ = DIV_ROUND_CLOSEST(fixp_q, FIXP_FRAC * 10); *vbuf++ = DIV_ROUND_CLOSEST(fixp_q, FIXP_FRAC * 10);
break; break;
case V4L2_SDR_FMT_CS8: case V4L2_SDR_FMT_CS8:
/* convert 'fixp float' to s8 */ /* convert 'fixp float' to s8 [-128, +127] */
fixp_i = fixp_i * 1275; /* s8 = X * 127.5 - 0.5; X is float [-1.0, +1.0] */
fixp_q = fixp_q * 1275; fixp_i = fixp_i * 1275 - FIXP_FRAC * 5;
fixp_q = fixp_q * 1275 - FIXP_FRAC * 5;
*vbuf++ = DIV_ROUND_CLOSEST(fixp_i, FIXP_FRAC * 10); *vbuf++ = DIV_ROUND_CLOSEST(fixp_i, FIXP_FRAC * 10);
*vbuf++ = DIV_ROUND_CLOSEST(fixp_q, FIXP_FRAC * 10); *vbuf++ = DIV_ROUND_CLOSEST(fixp_q, FIXP_FRAC * 10);
break; break;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment