Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UAC2: Implement feedback by fifo counting. #2328

Open
wants to merge 25 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
1b66c14
UAC2: Implement feedback by fifo counting.
HiFiPhile Nov 19, 2023
187c379
Add tu_static to global variables.
HiFiPhile Mar 24, 2024
02e129a
Guard ep_fb with usbd_edpt_claim().
HiFiPhile Mar 23, 2024
f2d4552
Add UAC2 speaker with feedback example.
HiFiPhile Nov 19, 2023
f69255e
Fix CI.
HiFiPhile Nov 19, 2023
ba27179
Fix typo.
HiFiPhile Dec 1, 2023
0a70a66
Fix up TUD_AUDIO_SPEAKER_MONO_FB_DESCRIPTOR.
HiFiPhile Nov 19, 2023
a7762ff
LPC55 : Use PLL clock for better precision, allows easier UAC testing.
HiFiPhile Nov 19, 2023
73d61fa
Migrate to weak default implementation.
HiFiPhile May 8, 2024
8dc767f
Fix cycle based feedback calculation.
HiFiPhile May 8, 2024
ab53989
Reorganize feedback documentation.
HiFiPhile May 8, 2024
0e907b4
Add callback to to set feedback format correction at runtime.
HiFiPhile May 8, 2024
8133af4
Merge remote-tracking branch 'remotes/tinyusb/master' into rx_fb
HiFiPhile May 8, 2024
fc7647f
Allow feedback EP size change.
HiFiPhile May 9, 2024
f4d4f2d
Merge remote-tracking branch 'remotes/tinyusb/master' into rx_fb
HiFiPhile May 9, 2024
9ce44db
Always send 4 bytes feedback despite 10.14 format (Apple wtf ?!)
HiFiPhile May 11, 2024
33882b3
Merge remote-tracking branch 'remotes/tinyusb/master' into rx_fb
HiFiPhile May 11, 2024
ad85c37
Optimize SOF.
HiFiPhile May 11, 2024
256ccc4
Fix CI.
HiFiPhile May 11, 2024
08f9e4e
Hint missing import, exit on error.
HiFiPhile May 12, 2024
df67403
Optimize fifo level display.
HiFiPhile May 12, 2024
32d0baa
Tested 3 bytes feedback work on OSX.
HiFiPhile May 12, 2024
301fb2a
Fix CI.
HiFiPhile May 12, 2024
d54a157
Typo.
HiFiPhile May 12, 2024
6745635
Fix HS playback on OSX.
HiFiPhile May 12, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/device/cdc_uac2/src/uac2_app.c
Expand Up @@ -141,7 +141,7 @@ static bool tud_audio_feature_unit_get_request(uint8_t rhport, audio_control_req
TU_LOG1("Get channel %u mute %d\r\n", request->bChannelNumber, mute1.bCur);
return tud_audio_buffer_and_schedule_control_xfer(rhport, (tusb_control_request_t const *)request, &mute1, sizeof(mute1));
}
else if (UAC2_ENTITY_SPK_FEATURE_UNIT && request->bControlSelector == AUDIO_FU_CTRL_VOLUME)
else if (request->bControlSelector == AUDIO_FU_CTRL_VOLUME)
{
if (request->bRequest == AUDIO_CS_REQ_RANGE)
{
Expand Down
2 changes: 1 addition & 1 deletion examples/device/uac2_headset/src/main.c
Expand Up @@ -229,7 +229,7 @@ static bool tud_audio_feature_unit_get_request(uint8_t rhport, audio_control_req
TU_LOG1("Get channel %u mute %d\r\n", request->bChannelNumber, mute1.bCur);
return tud_audio_buffer_and_schedule_control_xfer(rhport, (tusb_control_request_t const *)request, &mute1, sizeof(mute1));
}
else if (UAC2_ENTITY_SPK_FEATURE_UNIT && request->bControlSelector == AUDIO_FU_CTRL_VOLUME)
else if (request->bControlSelector == AUDIO_FU_CTRL_VOLUME)
{
if (request->bRequest == AUDIO_CS_REQ_RANGE)
{
Expand Down
33 changes: 33 additions & 0 deletions examples/device/uac2_speaker_fb/CMakeLists.txt
@@ -0,0 +1,33 @@
cmake_minimum_required(VERSION 3.17)

include(${CMAKE_CURRENT_SOURCE_DIR}/../../../hw/bsp/family_support.cmake)

# gets PROJECT name for the example (e.g. <BOARD>-<DIR_NAME>)
family_get_project_name(PROJECT ${CMAKE_CURRENT_LIST_DIR})

project(${PROJECT} C CXX ASM)

# Checks this example is valid for the family and initializes the project
family_initialize_project(${PROJECT} ${CMAKE_CURRENT_LIST_DIR})

# Espressif has its own cmake build system
if(FAMILY STREQUAL "espressif")
return()
endif()

add_executable(${PROJECT})

# Example source
target_sources(${PROJECT} PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/src/main.c
${CMAKE_CURRENT_SOURCE_DIR}/src/usb_descriptors.c
)

# Example include
target_include_directories(${PROJECT} PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/src
)

# Configure compilation flags and libraries for the example without RTOS.
# See the corresponding function in hw/bsp/FAMILY/family.cmake for details.
family_configure_device_example(${PROJECT} noos)
11 changes: 11 additions & 0 deletions examples/device/uac2_speaker_fb/Makefile
@@ -0,0 +1,11 @@
include ../../build_system/make/make.mk

INC += \
src \
$(TOP)/hw \

# Example source
EXAMPLE_SOURCE += $(wildcard src/*.c)
SRC_C += $(addprefix $(CURRENT_PATH)/, $(EXAMPLE_SOURCE))

include ../../build_system/make/rules.mk
8 changes: 8 additions & 0 deletions examples/device/uac2_speaker_fb/skip.txt
@@ -0,0 +1,8 @@
mcu:LPC11UXX
mcu:LPC13XX
mcu:NUC121
mcu:SAMD11
mcu:SAME5X
mcu:SAMG
board:stm32l052dap52
family:broadcom_64bit
69 changes: 69 additions & 0 deletions examples/device/uac2_speaker_fb/src/audio_debug.py
@@ -0,0 +1,69 @@
# Install python3 HID package https://pypi.org/project/hid/
# Install python3 matplotlib package https://pypi.org/project/matplotlib/

from ctypes import *
try:
import hid
import matplotlib.pyplot as plt
import matplotlib.animation as animation
except:
print("Missing import, please try 'pip install hid matplotlib' or consult your OS's python package manager.")

# Example must be compiled with CFG_AUDIO_DEBUG=1
VID = 0xcafe
PID = 0x4014

CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_RX = 2

class audio_debug_info_t (Structure):
_fields_ = [("sample_rate", c_uint32),
("alt_settings", c_uint8),
("mute", (CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_RX + 1) * c_int8),
("volume", (CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_RX + 1) * c_int16),
("fifo_size", c_uint16),
("fifo_count", c_uint16),
("fifo_count_avg", c_uint16)
]

dev = hid.Device(VID, PID)

if dev:
# Create figure for plotting
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
fifo_avg = []
fifo_cnt = []
# This function is called periodically from FuncAnimation
def animate(i):
info = None
for i in range(30):
try:
str_in = dev.read(64, 50)
info = audio_debug_info_t.from_buffer_copy(str_in)

global fifo_avg
global fifo_cnt
fifo_avg.append(info.fifo_count_avg)
fifo_cnt.append(info.fifo_count)
except:
exit(1)
# Limit to 1000 items
fifo_avg = fifo_avg[-1000:]
fifo_cnt = fifo_cnt[-1000:]

if info is not None:
# Draw x and y lists
ax.clear()
ax.plot(fifo_cnt, label='FIFO count')
ax.plot(fifo_avg, label='FIFO average')
ax.legend()
ax.set_ylim(bottom=0, top=info.fifo_size)

# Format plot
plt.title('FIFO information')
plt.grid()

print(f'Sample rate:{info.sample_rate} | Alt settings:{info.alt_settings} | Volume:{info.volume[:]}')

ani = animation.FuncAnimation(fig, animate, interval=10)
plt.show()
52 changes: 52 additions & 0 deletions examples/device/uac2_speaker_fb/src/common_types.h
@@ -0,0 +1,52 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2023 HiFiPhile
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
*/

#ifndef _COMMON_TYPES_H_
#define _COMMON_TYPES_H_

enum
{
ITF_NUM_AUDIO_CONTROL = 0,
ITF_NUM_AUDIO_STREAMING,
#if CFG_AUDIO_DEBUG
ITF_NUM_DEBUG,
#endif
ITF_NUM_TOTAL
};

#if CFG_AUDIO_DEBUG
typedef struct
{
uint32_t sample_rate;
uint8_t alt_settings;
int8_t mute[CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_RX + 1];
int16_t volume[CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_RX + 1];
uint16_t fifo_size;
uint16_t fifo_count;
uint16_t fifo_count_avg;
} audio_debug_info_t;
#endif

#endif