Skip to content

Conversation

@oliviamiller
Copy link
Member

@oliviamiller oliviamiller commented Oct 21, 2025

Add the AudioIn component type. Protos in this PR: #490

manually tested using the audio module example included here.

@oliviamiller oliviamiller marked this pull request as ready for review October 21, 2025 16:16
@oliviamiller oliviamiller requested a review from a team as a code owner October 21, 2025 16:16
@oliviamiller oliviamiller requested review from SebastianMunozP, lia-viam and njooma and removed request for a team October 21, 2025 16:16
Copy link
Collaborator

@lia-viam lia-viam left a comment

Choose a reason for hiding this comment

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

Thanks for the PR, added some suggestions we can iterate on in addition to figuring out the test failures.

/// @struct audio_info
/// @brief Information about a piece of audio data
struct audio_info {
std::string codec;
Copy link
Collaborator

Choose a reason for hiding this comment

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

are these possible to enumerate in advance or do we allow arbitrary codecs?

Copy link
Member Author

Choose a reason for hiding this comment

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

We decided not to include an enum in the protos so we can allow for any codec but we could include some string constants for commonly used codecs

AudioIn::AudioIn(std::string name) : Component(std::move(name)) {}

bool operator==(const AudioIn::properties& lhs, const AudioIn::properties& rhs) {
return lhs.supported_codecs == rhs.supported_codecs &&
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's write this with std::tie instead

Copy link
Member Author

Choose a reason for hiding this comment

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

cool didn't know about this, changed

Copy link
Collaborator

Choose a reason for hiding this comment

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

oops we need to #include <tuple> for this

audio_chunk chunk;

// Convert int16_t samples to uint8_t bytes
chunk.audio_data.resize(samples.size() * sizeof(int16_t));
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think let's do this with std::copy and/or boost::span

for (int i = 0; i < samples_in_chunk; ++i) {
int sample_idx = chunk_idx * chunk_size + i;
double t = static_cast<double>(sample_idx) / sample_rate;
double sample_value = amplitude * std::sin(2.0 * M_PI * frequency_ * t);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's put as much of this stuff as possible into named helpers since it's a bit mysterious and I believe used a couple times

Copy link
Member Author

Choose a reason for hiding this comment

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

its only used here but I added helper functions for clarity

uint32_t subchunk1_size = 16; // PCM
outfile.write(reinterpret_cast<const char*>(&subchunk1_size), 4);
uint16_t audio_format = 1; // PCM
outfile.write(reinterpret_cast<const char*>(&audio_format), 2);
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is kind of opaque as written, I think let's do a helper function template (or generic lambda) that expresses this in terms of sizeof, which is what I assume is going on

Copy link
Member Author

Choose a reason for hiding this comment

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

Created a template and helper function for writing wav files

@@ -0,0 +1,50 @@
#pragma once
Copy link
Member Author

Choose a reason for hiding this comment

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

created common audio package for things that will be reused between audioin and audioout

@oliviamiller
Copy link
Member Author

Thanks for the PR, added some suggestions we can iterate on in addition to figuring out the test failures.

I think the test failures are due to #490 not being merged yet, all tests are passing for me when I have the protos locally

@oliviamiller oliviamiller requested a review from lia-viam October 21, 2025 20:56

/// @struct properties
/// @brief Properties of an audio component (input or output)
struct properties {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
struct properties {
struct audio_properties {

since properties is a very general name to be putting in the sdk namespace

@lia-viam
Copy link
Collaborator

just merged #490 and merged it into this branch, let's see how the tests do now

@oliviamiller oliviamiller requested a review from lia-viam October 22, 2025 18:45

std::string host("xarm-main.aqb785vhl4.viam.cloud");
DialOptions dial_opts;
dial_opts.set_entity(std::string("88dcef8e-db7f-47dc-9b0f-eb08fdc5a97d"));
Copy link
Collaborator

Choose a reason for hiding this comment

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

don't forget to revert these before merging! also in the future it's best to git stash these changes rather than committing them while working on the PR

Copy link
Member Author

Choose a reason for hiding this comment

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

oops yeah did not mean to commit this, reverted

@oliviamiller oliviamiller merged commit a856b5a into viamrobotics:main Oct 23, 2025
5 checks passed
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.

3 participants