init
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
# Copyright 2024-2025 XMOS LIMITED.
|
||||
# This Software is subject to the terms of the XMOS Public Licence: Version 1.
|
||||
|
||||
# start example
|
||||
from audio_dsp.design.pipeline import Pipeline
|
||||
from audio_dsp.stages import *
|
||||
|
||||
p, edge = Pipeline.begin(4)
|
||||
|
||||
# thread 0
|
||||
e0 = p.stage(Bypass, edge[0], "a")
|
||||
|
||||
# thread 1
|
||||
p.next_thread()
|
||||
e1 = p.stage(Bypass, edge[1:], "b")
|
||||
e1 = p.stage(Bypass, e1, "c")
|
||||
|
||||
# thread 2
|
||||
p.next_thread()
|
||||
e = p.stage(Bypass, e0 + e1, "d")
|
||||
|
||||
p.set_outputs(e)
|
||||
# end example
|
||||
|
||||
from pathlib import Path
|
||||
from utils import IMGS_PATH
|
||||
output_dir = IMGS_PATH / Path(__file__).with_suffix(".gv").name
|
||||
p.draw(output_dir)
|
||||
36
lib_audio_dsp/test/pipeline/doc_examples/run_time_control.py
Normal file
36
lib_audio_dsp/test/pipeline/doc_examples/run_time_control.py
Normal file
@@ -0,0 +1,36 @@
|
||||
# Copyright 2024-2025 XMOS LIMITED.
|
||||
# This Software is subject to the terms of the XMOS Public Licence: Version 1.
|
||||
|
||||
|
||||
|
||||
# start example
|
||||
from audio_dsp.design.pipeline import Pipeline
|
||||
from audio_dsp.stages import *
|
||||
|
||||
p, edge = Pipeline.begin(4)
|
||||
edge = p.stage(VolumeControl, edge, "volume")
|
||||
edge = p.stage(LimiterRMS, edge)
|
||||
p.set_outputs(edge)
|
||||
# end example
|
||||
|
||||
from pathlib import Path
|
||||
from utils import IMGS_PATH
|
||||
output_dir = IMGS_PATH / Path(__file__).with_suffix(".gv").name
|
||||
p.draw(output_dir)
|
||||
|
||||
from audio_dsp.design.pipeline import generate_dsp_main
|
||||
generate_dsp_main(p, Path(__file__).parent/"run_time_dsp/src/dsp")
|
||||
|
||||
# start config
|
||||
config = p["volume"].get_config()
|
||||
print(config)
|
||||
# end config
|
||||
|
||||
(Path(__file__).parent/"run_time_dsp"/"config.txt").write_text(repr(config))
|
||||
|
||||
# check the app builds
|
||||
from subprocess import run
|
||||
|
||||
kwargs = dict(check=True, cwd=Path(__file__).parent/"run_time_dsp")
|
||||
run(["cmake", "-B", "build", "-G", "Unix Makefiles"], **kwargs)
|
||||
run(["cmake", "--build", "build"], **kwargs)
|
||||
@@ -0,0 +1,14 @@
|
||||
cmake_minimum_required(VERSION 3.21)
|
||||
include($ENV{XMOS_CMAKE_PATH}/xcommon.cmake)
|
||||
project(run_time_dsp)
|
||||
|
||||
set(APP_HW_TARGET XK-EVK-XU316)
|
||||
set(APP_DEPENDENT_MODULES lib_audio_dsp)
|
||||
set(APP_PCA_ENABLE OFF)
|
||||
set(APP_COMPILER_FLAGS -Wall -Werror)
|
||||
set(APP_INCLUDES
|
||||
src
|
||||
src/dsp)
|
||||
set(XMOS_SANDBOX_DIR ${CMAKE_CURRENT_LIST_DIR}/../../../../..)
|
||||
|
||||
XMOS_REGISTER_APP()
|
||||
@@ -0,0 +1 @@
|
||||
{'target_gain': 134217728, 'slew_shift': 7, 'mute_state': 0}
|
||||
@@ -0,0 +1,7 @@
|
||||
// Copyright 2024-2025 XMOS LIMITED.
|
||||
// This Software is subject to the terms of the XMOS Public Licence: Version 1.
|
||||
#pragma once
|
||||
|
||||
#define thread0_stage_index (1)
|
||||
#define volume_stage_index (2)
|
||||
#define auto_thread_stage_indices { thread0_stage_index }
|
||||
@@ -0,0 +1,77 @@
|
||||
// Copyright 2024-2025 XMOS LIMITED.
|
||||
// This Software is subject to the terms of the XMOS Public Licence: Version 1.
|
||||
|
||||
|
||||
|
||||
// example that is used in the run time guide
|
||||
|
||||
// start example
|
||||
#include <xcore/parallel.h>
|
||||
#include "cmds.h"
|
||||
#include "adsp_generated_auto.h"
|
||||
#include "adsp_instance_id_auto.h"
|
||||
#include "dsp/signal_chain.h"
|
||||
#include "control/signal_chain.h"
|
||||
#include "stages/adsp_control.h"
|
||||
#include "stages/adsp_pipeline.h"
|
||||
|
||||
void control_thread(adsp_controller_t* control) {
|
||||
// convert desired value to parameter type
|
||||
float desired_vol_db = -6;
|
||||
int32_t desired_vol_raw = adsp_dB_to_gain(desired_vol_db);
|
||||
|
||||
adsp_stage_control_cmd_t command = {
|
||||
.instance_id = volume_stage_index,
|
||||
.cmd_id = CMD_VOLUME_CONTROL_TARGET_GAIN,
|
||||
.payload_len = sizeof(desired_vol_raw),
|
||||
.payload = &desired_vol_raw
|
||||
};
|
||||
|
||||
// try write until success
|
||||
while(ADSP_CONTROL_SUCCESS != adsp_write_module_config(control, &command));
|
||||
|
||||
// DONE!
|
||||
}
|
||||
|
||||
void audio_source_sink(adsp_pipeline_t* p) {
|
||||
// sends and receives audio to the pipeline
|
||||
}
|
||||
|
||||
void dsp_main(void) {
|
||||
adsp_pipeline_t* dsp = adsp_auto_pipeline_init();
|
||||
|
||||
// created a controller instance for each thread.
|
||||
adsp_controller_t control;
|
||||
adsp_controller_init(&control, dsp);
|
||||
|
||||
PAR_FUNCS(
|
||||
PFUNC(audio_source_sink, dsp),
|
||||
PFUNC(control_thread, &control),
|
||||
PFUNC(adsp_auto_pipeline_main, dsp)
|
||||
);
|
||||
}
|
||||
// end example
|
||||
|
||||
// start read
|
||||
int32_t read_volume_gain(adsp_controller_t* control) {
|
||||
int32_t gain_raw;
|
||||
|
||||
adsp_stage_control_cmd_t command = {
|
||||
.instance_id = volume_stage_index,
|
||||
.cmd_id = CMD_VOLUME_CONTROL_GAIN,
|
||||
.payload_len = sizeof(gain_raw),
|
||||
.payload = &gain_raw
|
||||
};
|
||||
|
||||
// try write until success
|
||||
while(ADSP_CONTROL_SUCCESS != adsp_read_module_config(control, &command));
|
||||
|
||||
return gain_raw;
|
||||
}
|
||||
// end read
|
||||
|
||||
// main just to ensure the code compiles. not expected to run
|
||||
int main() {
|
||||
(void)read_volume_gain(NULL);
|
||||
dsp_main();
|
||||
}
|
||||
11
lib_audio_dsp/test/pipeline/doc_examples/utils.py
Normal file
11
lib_audio_dsp/test/pipeline/doc_examples/utils.py
Normal file
@@ -0,0 +1,11 @@
|
||||
# Copyright 2024-2025 XMOS LIMITED.
|
||||
# This Software is subject to the terms of the XMOS Public Licence: Version 1.
|
||||
|
||||
"""
|
||||
if docs path change, update them here
|
||||
"""
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
DOC_PATH = Path(__file__).parents[3] / "doc"
|
||||
IMGS_PATH = DOC_PATH / "images"
|
||||
Reference in New Issue
Block a user