|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +## |
| 4 | +## Case Name: check-8bit-play-rec |
| 5 | +## Preconditions: |
| 6 | +## - sox installed |
| 7 | +## Description: |
| 8 | +## This test verifies 8-bit audio playback and recording functionality using ALSA devices. |
| 9 | +## It generates test chirp signals in multiple 8-bit formats (unsigned 8-bit, A-LAW, MU-LAW), plays them back, records the output, |
| 10 | +## and checks the integrity of the recorded files. The test ensures that the pipeline correctly handles 8-bit audio data for both playback and capture. |
| 11 | +## Case steps: |
| 12 | +## 1. Generate chirp signals in unsigned 8-bit, A-LAW, MU-LAW, and S32_LE formats using sox. |
| 13 | +## 2. Play each chirp file and record the output using arecord and aplay with the specified ALSA devices. |
| 14 | +## 3. Convert raw recordings to WAV format for analysis. |
| 15 | +## 4. Analyze the recorded files for integrity. |
| 16 | +## Expected results: |
| 17 | +## - All chirp files are played and recorded without errors. |
| 18 | +## - The recorded files are successfully generated and converted. |
| 19 | +## - No failures are reported during analysis. |
| 20 | +## |
| 21 | + |
| 22 | +set -e |
| 23 | + |
| 24 | +# It is pointless to perf component in HDMI pipeline, so filter out HDMI pipelines |
| 25 | +# shellcheck disable=SC2034 |
| 26 | +NO_HDMI_MODE=true |
| 27 | + |
| 28 | +# shellcheck source=case-lib/lib.sh |
| 29 | +source "$(dirname "${BASH_SOURCE[0]}")"/../case-lib/lib.sh |
| 30 | + |
| 31 | +OPT_NAME['t']='tplg' OPT_DESC['t']='tplg file, default value is env TPLG: $''TPLG' |
| 32 | +OPT_HAS_ARG['t']=1 OPT_VAL['t']="$TPLG" |
| 33 | + |
| 34 | +OPT_NAME['p']='playback_device' OPT_DESC['p']='ALSA pcm playback device. Example: hw:0,1' |
| 35 | +OPT_HAS_ARG['p']=1 OPT_VAL['p']='' |
| 36 | + |
| 37 | +OPT_NAME['c']='capture_device' OPT_DESC['c']='ALSA pcm capture device. Example: hw:0,1' |
| 38 | +OPT_HAS_ARG['c']=1 OPT_VAL['c']='' |
| 39 | + |
| 40 | +OPT_NAME['s']='sof-logger' OPT_DESC['s']="Open sof-logger trace the data will store at $LOG_ROOT" |
| 41 | +OPT_HAS_ARG['s']=0 OPT_VAL['s']=1 |
| 42 | + |
| 43 | +func_opt_parse_option "$@" |
| 44 | + |
| 45 | +init_globals() |
| 46 | +{ |
| 47 | + tplg=${OPT_VAL['t']} |
| 48 | + playback_dev=${OPT_VAL['p']} |
| 49 | + capture_dev=${OPT_VAL['c']} |
| 50 | + |
| 51 | + rec8_opt="-c 2 -r 48000 -d 7" |
| 52 | + rec_opt="-f S32_LE -c 2 -r 48000 -d 7" |
| 53 | + play_opt="-c 2 -r 48000" |
| 54 | + |
| 55 | + chirp_u8_filename="$LOG_ROOT/chirp_u8.wav" |
| 56 | + chirp_alaw_filename="$LOG_ROOT/chirp_alaw.raw" |
| 57 | + chirp_mulaw_filename="$LOG_ROOT/chirp_mulaw.raw" |
| 58 | + chirp_s32_filename="$LOG_ROOT/chirp_s32.wav" |
| 59 | + |
| 60 | + u8_play_filename="$LOG_ROOT/rec_play_u8.wav" |
| 61 | + alaw_play_filename="$LOG_ROOT/rec_play_alaw.wav" |
| 62 | + mulaw_play_filename="$LOG_ROOT/rec_play_mulaw.wav" |
| 63 | + |
| 64 | + u8_rec_filename="$LOG_ROOT/rec_u8.wav" |
| 65 | + alaw_rec_filename="$LOG_ROOT/rec_alaw.wav" |
| 66 | + mulaw_rec_filename="$LOG_ROOT/rec_mulaw.wav" |
| 67 | + |
| 68 | + all_result_files=("$u8_play_filename" "$alaw_play_filename" "$mulaw_play_filename" "$u8_rec_filename" "$alaw_rec_filename" "$mulaw_rec_filename") |
| 69 | +} |
| 70 | + |
| 71 | +generate_chirps() |
| 72 | +{ |
| 73 | + dlogi "Generating chirps" |
| 74 | + sox -n --encoding unsigned-integer -b 8 -r 48000 -c 2 "$chirp_u8_filename" synth 5 sine 100+20000 norm -3 |
| 75 | + sox -n --encoding a-law -b 8 -r 48000 -c 2 "$chirp_alaw_filename" synth 5 sine 100+20000 norm -3 |
| 76 | + sox -n --encoding mu-law -b 8 -r 48000 -c 2 "$chirp_mulaw_filename" synth 5 sine 100+20000 norm -3 |
| 77 | + sox -n --encoding signed-integer -b 32 -r 48000 -c 2 "$chirp_s32_filename" synth 5 sine 100+20000 norm -3 |
| 78 | +} |
| 79 | + |
| 80 | +cleanup() |
| 81 | +{ |
| 82 | + if [ -f "tmp1.raw" ]; then sudo rm tmp1.raw; fi |
| 83 | + if [ -f "tmp2.raw" ]; then sudo rm tmp2.raw; fi |
| 84 | +} |
| 85 | + |
| 86 | +run_tests() |
| 87 | +{ |
| 88 | + generate_chirps |
| 89 | + |
| 90 | + set +e |
| 91 | + play_and_record "-D$capture_dev $rec_opt $u8_play_filename" "-D$playback_dev $play_opt -t wav $chirp_u8_filename" |
| 92 | + play_and_record "-D$capture_dev $rec_opt $alaw_play_filename" "-D$playback_dev $play_opt -t raw -f A_LAW $chirp_alaw_filename" |
| 93 | + play_and_record "-D$capture_dev $rec_opt $mulaw_play_filename" "-D$playback_dev $play_opt -t raw -f MU_LAW $chirp_mulaw_filename" |
| 94 | + |
| 95 | + play_and_record "-D$capture_dev $rec8_opt -f U8 $u8_rec_filename" "-D$playback_dev $chirp_s32_filename" |
| 96 | + play_and_record "-D$capture_dev $rec8_opt -f A_LAW -t raw tmp1.raw" "-D$playback_dev $chirp_s32_filename" |
| 97 | + play_and_record "-D$capture_dev $rec8_opt -f MU_LAW -t raw tmp2.raw" "-D$playback_dev $chirp_s32_filename" |
| 98 | + |
| 99 | + sox --encoding a-law -r 48000 -c 2 tmp1.raw "$alaw_rec_filename" |
| 100 | + sox --encoding u-law -r 48000 -c 2 tmp2.raw "$mulaw_rec_filename" |
| 101 | + set -e |
| 102 | + |
| 103 | + if check_soundfile_for_glitches "${all_result_files[@]}"; then |
| 104 | + dlogi "All files correct" |
| 105 | + else |
| 106 | + die "Detected corrupted files!" |
| 107 | + fi |
| 108 | +} |
| 109 | + |
| 110 | +main() |
| 111 | +{ |
| 112 | + init_globals |
| 113 | + |
| 114 | + start_test |
| 115 | + logger_disabled || func_lib_start_log_collect |
| 116 | + |
| 117 | + setup_kernel_check_point |
| 118 | + func_lib_check_sudo |
| 119 | + func_pipeline_export "$tplg" "type:any" |
| 120 | + |
| 121 | + run_tests |
| 122 | + cleanup |
| 123 | +} |
| 124 | + |
| 125 | +{ |
| 126 | + main "$@"; exit "$?" |
| 127 | +} |
0 commit comments