summaryrefslogtreecommitdiff
path: root/lib/igt_audio.c
AgeCommit message (Collapse)Author
2019-06-05lib/igt_audio: detect noise and popsSimon Ser
First, normalize the bin power by dividing it by the number of input samples. We need to multiply by 2 since we get half as many bins as input samples. Second, check that low frequencies are under a given threshold. If there is a pop or some noise, the low frequencies will be affected. Signed-off-by: Simon Ser <simon.ser@intel.com> Reviewed-by: Martin Peres <martin.peres@linux.intel.com>
2019-05-27lib/igt_audio: make audio_extract_channel_s32_le support a NULL dstSimon Ser
This adds a snprintf-like behaviour to audio_extract_channel_s32_le. Signed-off-by: Simon Ser <simon.ser@intel.com> Reviewed-by: Martin Peres <martin.peres@linux.intel.com>
2019-05-27lib/igt_audio: introduce audio_convert_toSimon Ser
This function converts normalized doubles into an ALSA PCM format. Instead of having per-format audio_signal_fill_* functions, we can only have audio_signal_fill that outputs normalized doubles. Then in ALSA's playback callback, we can simply use the new audio_convert_to function to fill the buffer. This makes the test code simpler and prevents code duplication when another ALSA playback callback is implemented. This adds a dependency of igt_audio over ALSA for the PCM format enum, but I don't think this is a concern, since I don't see the point of using igt_audio without igt_alsa. If this is an issue, it would always be possible to replace ALSA's enum with our own in the future. Signed-off-by: Simon Ser <simon.ser@intel.com> Reviewed-by: Martin Peres <martin.peres@linux.intel.com>
2019-05-27lib/igt_audio: use calloc instead of malloc + memsetSimon Ser
This is less error-prone. Signed-off-by: Simon Ser <simon.ser@intel.com> Reviewed-by: Martin Peres <martin.peres@linux.intel.com>
2019-05-27lib/igt_audio: add more assertionsSimon Ser
- Make sure an audio signal isn't created with zero channels - Make sure each channel has at least one frequency when synthesizing Signed-off-by: Simon Ser <simon.ser@intel.com> Reviewed-by: Martin Peres <martin.peres@linux.intel.com>
2019-05-24lib/igt_audio: fix uninitialized variableSimon Ser
Seems like I'm not used to the C89 style yet, and ASan caught it but with a completely unrelated stack trace. Signed-off-by: Simon Ser <simon.ser@intel.com>
2019-05-24lib/igt_audio: fix amplitude for S24_LE and S32_LESimon Ser
We need to use signed integers (hence "S" in the format name). The reason this has gone unnoticed is that we were generating signals with half of the amplitude they were supposed to have. As a result, using UINT32_MAX (which is almost INT32_MAX * 2) resulted in the correct amplitude. In other words, these two bugs were cancelling each other's effects. Signed-off-by: Simon Ser <simon.ser@intel.com> Fixes: 42576d710255 ("lib/igt_audio: add support for S24_LE and S32_LE signal generation")
2019-05-20lib/igt_audio: add support for S24_LE and S32_LE signal generationSimon Ser
This adds two new helpers to generate S24_LE and S32_LE signals. Signed-off-by: Simon Ser <simon.ser@intel.com> Reviewed-by: Martin Peres <martin.peres@linux.intel.com>
2019-05-17lib/igt_audio: sanity-check generated signalsSimon Ser
This is a safety net to ensure we haven't completely messed up our signal generation. It would be unfortunate to send e.g. a null signal after a refactoring. Signed-off-by: Simon Ser <simon.ser@intel.com> Reviewed-by: Martin Peres <martin.peres@linux.intel.com>
2019-05-17lib/igt_audio: fix synthesized signal amplitudeSimon Ser
For each channel of the audio signal, we choose a set of frequencies to generate. However we previously divided each sample by the total number of frequencies, instead of the number of frequencies assigned to the channel we're currently processing. This resulted in low amplitudes (0.5 instead of 1.0 for 2 channels). This patch fixes this issue and sets the generated signal amplitude to 0.9. Indeed, we want to detect if the receiver grows the signal, we don't want it to get capped at 1.0 immediately. Signed-off-by: Simon Ser <simon.ser@intel.com> Reviewed-by: Martin Peres <martin.peres@linux.intel.com>
2019-05-16lib/igt_audio: use double instead of int16_tSimon Ser
In order to be able to generate S32_LE signals, we need a higher precision than S16_LE. Change the signal generation code to use double instead of int16_t and introduce a new helper to fill a buffer with S16_LE samples. We already use arrays of doubles elsewhere (see audio_signal_detect). Similar format-specific helpers will be added for S32_LE in the future. Signed-off-by: Simon Ser <simon.ser@intel.com> Reviewed-by: Arkadiusz Hiler <arkadiusz.hiler@intel.com>
2019-05-15lib/igt_audio: make audio_signal_detect take const dataSimon Ser
audio_signal_detect uses gsl_fft_real_radix2_transform which mutates the data array. This can be surprising when calling audio_signal_detect and then read again the data (e.g. for another check). Instead of mutating the array, make audio_signal_detect less error-prone by taking a const parameter. Do an internal copy before calling the gsl function. Signed-off-by: Simon Ser <simon.ser@intel.com> Reviewed-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
2019-05-15lib/igt_audio: normalize samples when extracting channelSimon Ser
audio_extract_channel_s32_le converts S32 samples to double. Prior to this patch, the output samples weren't normalized, resulting in values up to INT32_MAX. Future amplitude tests need to be format-agnostic (ie. shouldn't care whether the format used is S16 or S32). Thus, it is preferable to always use normalized double values. The current tests don't check the amplitude (or check it relative to the max. on the whole buffer), so they still pass without any modification. Signed-off-by: Simon Ser <simon.ser@intel.com> Reviewed-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
2019-04-29lib/igt_audio: fix filemode not specified in open(O_CREAT)Simon Ser
open(3) takes va_args after the flags and O_CREAT will read the first one. If we don't provide one, this is undefined behaviour. (Someone reported it broke the build for them) Signed-off-by: Simon Ser <simon.ser@intel.com> Fixes: 311baff151f9 ("tests/kms_chamelium: add dp-audio test") Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk> Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
2019-04-25tests/kms_chamelium: test we receive a signal from both audio channelsSimon Ser
This commit updates the audio test to make sure we receive a signal from both audio channels. However this commit doesn't check that left and right channels are not swapped. Such a check requires some more work (because the Chamelium device does swap left and right channels) and will be implemented in a future commit. This commit adds a new channel argument to audio_signal_add_frequency, to add a frequency to a single channel only. Some light refactoring has been performed: a proper audio_signal_fini function has been introduced and size_t in now used when it should be. Signed-off-by: Simon Ser <simon.ser@intel.com> Reviewed-by: Martin Peres <martin.peres@linux.intel.com>
2019-04-25lib/igt_{alsa, audio}: improve loggingSimon Ser
- Print matched audio devices - Print min/max values when alsa_test_configuration fails - Print debug log line when skipping a frequency Signed-off-by: Simon Ser <simon.ser@intel.com> Reviewed-by: Martin Peres <martin.peres@linux.intel.com>
2019-04-25tests/kms_chamelium: add dp-audio testSimon Ser
This new test ensures DisplayPort audio works by using the Chamelium. It enables the DisplayPort output and sends an audio signal containing a set of frequencies we choose to all HDMI/DisplayPort audio devices. It starts recording audio on the Chamelium device and uses the stream server to retrieve captured audio pages. It then checks that the capture audio signal contains the frequencies we sent, and only those, by computing a FFT. A new library has been added to libigt to communicate with the stream server. It implements a simple custom TCP protocol. In case the test fails, a WAV file with the captured data is saved on disk. Right now the test has a few limitations: - Only the first channel is checked - IGT only generates audio with a single sampling rate (48 KHz) - Audio data is not captured in real-time These limitations will be lifted in future patches. PulseAudio must not run during the tests since ALSA is used directly. To ensure this, edit /etc/pulse/client.conf and add `autospawn=no`. Then run `pulseaudio --kill`. This commit deletes the existing audio tests. They weren't run and required an exotic configuration (HDMI audio splitter, dummy HDMI sink and a line-in port on the DUT). This patch also changes lib/igt_audio to use uint16_t instead of short. The rationale is: - The standard says a short is at least 16 bit wide, but a short can be larger (in practice it won't happen, but better use types correctly) - It makes it clearer that the audio format is S16_LE, since "16" is in the type name. This patch depends on the following Chameleon bugs: - https://crbug.com/948060 - https://crbug.com/950857 Signed-off-by: Simon Ser <simon.ser@intel.com> Reviewed-by: Martin Peres <martin.peres@linux.intel.com>
2019-01-21lib/igt_audio: Initialize freq in audio_signal_detect()Petri Latvala
It's not clear to the static analyzer that freq is assigned when handling the previous frame and then used in the next. In fact, it wasn't clear to me either before staring at the code for some minutes. Initializing it to something makes both of us happier. Signed-off-by: Petri Latvala <petri.latvala@intel.com> Cc: Paul Kocialkowski <paul.kocialkowski@bootlin.com> Reviewed-by: Paul Kocialkowski <paul.kocialkowski@bootlin.com>
2018-05-14lib/audio: Replace sqrt(a*a + b*b) with hypot(a, b)Chris Wilson
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk> Reviewed-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
2017-09-08lib: clean up header includesDaniel Vetter
Just a bit of OCD, I like it when connections within library modules are a bit more obvious. igt.h is ok for tests, but let's use individual include lines for libraries consistently. Also order standard includes before igt ones. v2: Rebase. Acked-by: Jani Nikula <jani.nikula@intel.com> Acked-by: Arkadiusz Hiler <arkadiusz.hiler@intel.com> Acked-by: Petri Latvala <petri.latvala@intel.com> Acked-by: Daniel Stone <daniels@collabora.com> Acked-by: Radoslaw Szwichtenberg <radoslaw.szwichtenberg@intel.com> Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
2017-08-21lib: Add audio library with dedicated helpersPaul Kocialkowski
This introduces an audio library, with dedicated helpers for both generating signals and detecting peak frequencies in a signal. This library paves the way for testing audio going through display connectors, such as HDMI. Signed-off-by: Paul Kocialkowski <paul.kocialkowski@linux.intel.com> Reviewed-by: Lyude Paul <lyude@redhat.com>