Skip to content

Conversation

richinsley
Copy link

This adds an abstract audio device class with a sub-class that creates an audio device using the sounddevice package.
ShadertoyChannelMusic is implemented to pull the audio data from it's given audio device and generates the waveform and fft data.
infer_subclass detects ctype of 'mic' and creates the ShadertoyChannelMusic instance.
An example (shadertoy/examples/shadertoy_mic_input.py) was added that demonstrates how to select and add the audio device to the ShaderToy instance.
Changes from original PR (#45):

@richinsley richinsley force-pushed the audio-input-feature branch from f7da90a to 951fe02 Compare June 13, 2025 16:29
@richinsley richinsley force-pushed the audio-input-feature branch from 951fe02 to 8a07a93 Compare June 13, 2025 16:49
action='store_true',
help='List all available audio input/output devices and exit',
)
argument_parser.add_argument('--enable-audio-input',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this seems redundant to enable audio and pick a device. I guess in the case of using defaults this might make sense. So perhaps the opposite works better: --audio-input OFF or similar to disable it specifically

new_data_contiguous = np.ascontiguousarray(self.data)

bytes_per_row = self.texture_size[0] * self._num_components * new_data_contiguous.itemsize
if bytes_per_row % 256 != 0:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wouldn't this be a constant here?

class ShadertoyChannelMusic(ShadertoyChannel):
pass
"""
Represents a Shadertoy music input channel, updated to match the
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this should be the ShadertoyChannelMicrophone while a lot of code can be reused (and maybe inherited) for Music and Soundcloud - there will be differences in where the samples come from (streaming from file, streaming from network vs device).

So code will likely be shuffled around a bit when these get implemented.

import sounddevice as sd
import sys

# Set up command line argument parsing
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since this functionality is supported by the cli, we should just have a simple example that has the code as a string and show how the channel class can be setup manually.

settings["address_mode_w"] = wgpu.AddressMode.clamp_to_edge
return settings

# class ShadertoyChannelMusic(ShadertoyChannel):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you want to preserve the initial version you can try to add a commit before so it shows up in diff for this branch (we will squash merge). Otherwise this should be cleaned up before we can merge

@Vipitis
Copy link
Collaborator

Vipitis commented Jul 8, 2025

hey @richinsley sorry this took a while. I left a few comments that need to be addressed and it would also be great to get CI working. It might required some additional library for the linux setup in the workflow.

Looking forward to have this merged as I found some update propagation oversights that I will look into in a followup while working on keyboard input. So having another interactive channel working will be great.
Also motivated me to try another music visualization shader which I can report works really well with this branch: https://www.shadertoy.com/view/wcySRc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants