MayaFlux 0.4.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ make_granular_matrix()

MAYAFLUX_API std::shared_ptr< GranularMatrix > MayaFlux::Yantra::Granular::make_granular_matrix ( ComputationContext  attribution_context = ComputationContext::SPECTRAL,
GranularOutput  output = GranularOutput::REGION_GROUP,
GrainTaper  taper = {} 
)

Construct a GranularMatrix with grammar rules appropriate for the requested output type.

REGION_GROUP: registers segment, attribute, sort (existing behaviour). CONTAINER: registers segment, attribute, sort, then appends reconstruct. The reconstruct rule reads the source container from ExecutionContext::execution_metadata["container"] and writes stitched per-channel audio into a SoundFileContainer. CONTAINER_ADDITIVE: same as CONTAINER but uses an overlap-add reconstruct rule

Parameters
attribution_contextComputationContext assigned to the attribution rule.
outputTerminal output type for this pipeline.
taperOptional per-grain taper for OLA output.
Returns
Configured GranularMatrix instance.

Definition at line 729 of file GranularWorkflow.cpp.

733{
734 auto matrix = std::make_shared<GranularMatrix>();
735
736 matrix->create_operation<SegmentOp>("segment");
737 matrix->create_operation<AttributeOp>("attribute");
738 matrix->create_operation<SortOp>("sort");
739
740 matrix->get_grammar()->create_rule("segment") //
741 .with_context(ComputationContext::TEMPORAL)
742 .with_priority(100)
743 .with_description("Fixed hop-size grain segmentation")
744 .matches_type<Kakshya::RegionGroup>()
745 .executes(segment_grains)
746 .build();
747
748 matrix->get_grammar()->create_rule("attribute") //
749 .with_context(attribution_context)
750 .with_priority(75)
751 .with_description("Per-grain feature attribution via analyzer or lambda")
752 .matches_type<Kakshya::RegionGroup>()
753 .executes(attribute_grains)
754 .build();
755
756 matrix->get_grammar()->create_rule("sort") //
757 .with_context(ComputationContext::STRUCTURAL)
758 .with_priority(50)
759 .with_description("Attribute-keyed grain sort, CPU or GPU")
760 .matches_type<Kakshya::RegionGroup>()
761 .executes(sort_grains)
762 .build();
763
764 if (output == GranularOutput::CONTAINER) {
765 matrix->get_grammar()->create_rule("reconstruct") //
766 .with_context(ComputationContext::STRUCTURAL)
767 .with_priority(25)
768 .with_description("Stitch sorted grains into a SoundFileContainer")
769 .matches_type<Kakshya::RegionGroup>()
770 .executes(reconstruct_grains)
771 .build();
772 } else if (output == GranularOutput::CONTAINER_ADDITIVE) {
773 auto ola_executor =
774 [t = std::move(taper)](const std::any& in, const ExecutionContext& ctx) -> std::any {
775 ExecutionContext patched = ctx;
776 if (t) {
777 patched.execution_metadata["grain_taper"] = t;
778 }
779 return reconstruct_grains_additive(in, patched);
780 };
781
782 matrix->get_grammar()->create_rule("reconstruct") //
783 .with_context(ComputationContext::STRUCTURAL)
784 .with_priority(25)
785 .with_description("Additive grain reconstruction into SoundFileContainer")
786 .matches_type<Kakshya::RegionGroup>()
787 .executes(ola_executor)
788 .build();
789 } else if (output == GranularOutput::STREAM) {
790 matrix->get_grammar()->create_rule("reconstruct") //
791 .with_context(ComputationContext::STRUCTURAL)
792 .with_priority(25)
793 .with_description("Stitch sorted grains into a DynamicSoundStream")
794 .matches_type<Kakshya::RegionGroup>()
795 .executes(reconstruct_grains_stream)
796 .build();
797 } else if (output == GranularOutput::STREAM_ADDITIVE) {
798 auto ola_executor =
799 [t = std::move(taper)](const std::any& in, const ExecutionContext& ctx) -> std::any {
800 ExecutionContext patched = ctx;
801 if (t)
802 patched.execution_metadata["grain_taper"] = t;
803 return reconstruct_grains_additive_stream(in, patched);
804 };
805
806 matrix->get_grammar()->create_rule("reconstruct") //
807 .with_context(ComputationContext::STRUCTURAL)
808 .with_priority(25)
809 .with_description("Additive grain reconstruction into DynamicSoundStream")
810 .matches_type<Kakshya::RegionGroup>()
811 .executes(ola_executor)
812 .build();
813 }
814
815 return matrix;
816}
Computes a scalar attribute per grain and writes it onto each Region.
Segments container audio into fixed hop-size grain windows.
Sorts grains by a named attribute key, with optional GPU dispatch.
const ComputationGrammar::Rule::Executor reconstruct_grains_additive_stream
Grammar rule executor — OLA reconstruct into DynamicSoundStream.
Organizes related signal regions into a categorized collection.
std::unordered_map< std::string, std::any > execution_metadata
Arbitrary metadata parameters used by operations.
Context information controlling how a compute operation executes.

References attribute_grains, CONTAINER, CONTAINER_ADDITIVE, MayaFlux::Yantra::ExecutionContext::execution_metadata, reconstruct_grains, reconstruct_grains_additive, reconstruct_grains_additive_stream, reconstruct_grains_stream, segment_grains, sort_grains, STREAM, STREAM_ADDITIVE, MayaFlux::Yantra::STRUCTURAL, and MayaFlux::Yantra::TEMPORAL.

Referenced by process(), and process().

+ Here is the caller graph for this function: