Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[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: Antti Palosaari <crope@iki.fi>
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

authored by

Antti Palosaari and committed by
Mauro Carvalho Chehab
60f68735 f335c3f2

+12 -19
+12 -19
drivers/media/platform/vivid/vivid-sdr-cap.c
··· 41 41 }; 42 42 43 43 /* format descriptions for capture and preview */ 44 - static struct vivid_format formats[] = { 44 + static const struct vivid_format formats[] = { 45 45 { 46 46 .pixelformat = V4L2_SDR_FMT_CU8, 47 47 .buffersize = SDR_CAP_SAMPLES_PER_BUF * 2, ··· 502 502 s32 fixp_i; 503 503 s32 fixp_q; 504 504 505 - /* 506 - * TODO: Generated beep tone goes very crackly when sample rate is 507 - * increased to ~1Msps or more. That is because of huge rounding error 508 - * of phase angle caused by used cosine implementation. 509 - */ 510 - 511 505 /* calculate phase step */ 512 506 #define BEEP_FREQ 1000 /* 1kHz beep */ 513 507 src_phase_step = DIV_ROUND_CLOSEST(FIXP_2PI * BEEP_FREQ, 514 - dev->sdr_adc_freq); 508 + dev->sdr_adc_freq); 515 509 516 510 for (i = 0; i < plane_size; i += 2) { 517 511 mod_phase_step = fixp_cos32_rad(dev->sdr_fixp_src_phase, ··· 516 522 dev->sdr_fixp_mod_phase += div_s64(s64tmp, M_100000PI); 517 523 518 524 /* 519 - * Transfer phases to [0 / 2xPI] in order to avoid variable 525 + * Transfer phase angle to [0, 2xPI] in order to avoid variable 520 526 * overflow and make it suitable for cosine implementation 521 527 * used, which does not support negative angles. 522 528 */ 523 - while (dev->sdr_fixp_mod_phase < FIXP_2PI) 524 - dev->sdr_fixp_mod_phase += FIXP_2PI; 525 - while (dev->sdr_fixp_mod_phase > FIXP_2PI) 526 - dev->sdr_fixp_mod_phase -= FIXP_2PI; 529 + dev->sdr_fixp_src_phase %= FIXP_2PI; 530 + dev->sdr_fixp_mod_phase %= FIXP_2PI; 527 531 528 - while (dev->sdr_fixp_src_phase > FIXP_2PI) 529 - dev->sdr_fixp_src_phase -= FIXP_2PI; 532 + if (dev->sdr_fixp_mod_phase < 0) 533 + dev->sdr_fixp_mod_phase += FIXP_2PI; 530 534 531 535 fixp_i = fixp_cos32_rad(dev->sdr_fixp_mod_phase, FIXP_2PI); 532 536 fixp_q = fixp_sin32_rad(dev->sdr_fixp_mod_phase, FIXP_2PI); ··· 536 544 537 545 switch (dev->sdr_pixelformat) { 538 546 case V4L2_SDR_FMT_CU8: 539 - /* convert 'fixp float' to u8 */ 547 + /* convert 'fixp float' to u8 [0, +255] */ 540 548 /* u8 = X * 127.5 + 127.5; X is float [-1.0, +1.0] */ 541 549 fixp_i = fixp_i * 1275 + FIXP_FRAC * 1275; 542 550 fixp_q = fixp_q * 1275 + FIXP_FRAC * 1275; ··· 544 552 *vbuf++ = DIV_ROUND_CLOSEST(fixp_q, FIXP_FRAC * 10); 545 553 break; 546 554 case V4L2_SDR_FMT_CS8: 547 - /* convert 'fixp float' to s8 */ 548 - fixp_i = fixp_i * 1275; 549 - fixp_q = fixp_q * 1275; 555 + /* convert 'fixp float' to s8 [-128, +127] */ 556 + /* s8 = X * 127.5 - 0.5; X is float [-1.0, +1.0] */ 557 + fixp_i = fixp_i * 1275 - FIXP_FRAC * 5; 558 + fixp_q = fixp_q * 1275 - FIXP_FRAC * 5; 550 559 *vbuf++ = DIV_ROUND_CLOSEST(fixp_i, FIXP_FRAC * 10); 551 560 *vbuf++ = DIV_ROUND_CLOSEST(fixp_q, FIXP_FRAC * 10); 552 561 break;