For more information about the examples, such as how the Python and Mojo files interact with each other, see the Examples Overview
In2Out¶
This is the simplest MMMAudio example. It routes input channels directly to output channels. It also demonstrates how to send a message to the graph to print the current input values to the REPL.
Python Code¶
from mmm_src.MMMAudio import *
# this will list available audio devices
list_audio_devices()
# set your own input and output devices here
in_device = "Fireface UFX+ (24059506)"
out_device = "Fireface UFX+ (24059506)"
# or get some feedback
in_device = "MacBook Pro Microphone"
out_device = "External Headphones"
# instantiate and load the graph
mmm_audio = MMMAudio(128, num_input_channels=12, num_output_channels=12, in_device=in_device, out_device=out_device, graph_name="In2Out", package_name="examples")
mmm_audio.start_audio()
# print the current sample of inputs to the REPL
mmm_audio.send_trig("print_inputs")
mmm_audio.stop_audio()
Mojo Code¶
from mmm_src.MMMWorld import MMMWorld
from mmm_utils.functions import *
from mmm_src.MMMTraits import *
from mmm_utils.Messenger import *
# this is the simplest possible
struct In2Out(Representable, Movable, Copyable):
var world: UnsafePointer[MMMWorld]
var messenger: Messenger
fn __init__(out self, world: UnsafePointer[MMMWorld]):
self.world = world
self.messenger = Messenger(world)
fn __repr__(self) -> String:
return String("In2Out")
fn next(mut self) -> SIMD[DType.float64, 16]:
if self.messenger.notify_trig("print_inputs"):
for i in range(self.world[].num_in_chans):
print("input[", i, "] =", self.world[].sound_in[i])
# the SIMD vector has to be a power of 2
output = SIMD[DType.float64, 16](0.0)
# whichever is smaller, the output or the sound_in - that number of values are copied to the output
smaller = min(len(output), len(self.world[].sound_in))
for i in range(smaller):
output[i] = self.world[].sound_in[i]
return output # Return the combined output samples