Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Develop Audio Nodes #1115

Open
wants to merge 49 commits into
base: v3_develop
Choose a base branch
from
Open

Develop Audio Nodes #1115

wants to merge 49 commits into from

Conversation

TheMutta
Copy link

Adding audio managment capabilities to depthai with the creation of various audio nodes for audio capture, output, mixing, encoding and replay.

  • AudioIn and AudioOut as endpoints for raw audio passing through alsa devices.
  • AudioEncoder recieves data from one endpoint and converts it to some other format.
  • AudioReplay, which plays a specific audio file on host.
  • AudioMixer, tasked with multiplexing audio inputs and outputs

@TheMutta TheMutta requested a review from moratom August 26, 2024 15:03
@TheMutta TheMutta self-assigned this Aug 26, 2024
@@ -647,6 +654,9 @@ target_link_libraries(${TARGET_CORE_NAME}
INTERFACE
XLinkPublic
PRIVATE
sndfile
samplerate
asound
Copy link
Contributor

Choose a reason for hiding this comment

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

Please fix indentation

@asahtik
Copy link
Contributor

asahtik commented Sep 4, 2024

It'd probably be good to add comments to node / datatype getters and setters for docs generation before merging.

Also might be good to run clangformat, but I'm not sure if v3_develop is properly formatted. If clangformat causes a lot of new changes, skip - we'll make a separate merge just for formatting.

Copy link
Collaborator

@moratom moratom left a comment

Choose a reason for hiding this comment

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

Thanks Filippo!

Writing here a brief TODO list as a summary:

  • Address comments from the PR
  • Try to make all used libraries included by Hunter and/or make them optional so DAI can be compiled without audio support
  • Regardless of the option chosen above, they should be included with cmake
  • Make sure the PR builds successfully on all platforms in CI
  • TBD on the AudioMixer node

Comment on lines +559 to +560
.def("getAlsaDevices", [](DeviceBase& d) { py::gil_scoped_release release; return d.getAlsaDevices(); }, DOC(dai, DeviceBase, getAlsaDevices))
.def("getAlsaPCMs", [](DeviceBase& d) { py::gil_scoped_release release; return d.getAlsaPCMs(); }, DOC(dai, DeviceBase, getAlsaPCMs))
Copy link
Collaborator

Choose a reason for hiding this comment

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

TODO:

  • Add impl on RVC2 side of things as well to return empty arrays

namespace dai {
namespace audio {

std::vector<AudioDevice> GetAlsaDevices() {
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
std::vector<AudioDevice> GetAlsaDevices() {
std::vector<AudioDevice> getAlsaDevices() {

return vec;
}

std::vector<AudioPCM> GetAlsaPCMs() {
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
std::vector<AudioPCM> GetAlsaPCMs() {
std::vector<AudioPCM> getAlsaPCMs() {

Same comment for other functions

@@ -0,0 +1,234 @@
#include "depthai/utility/AudioHelpers.hpp"

#include <alsa/asoundlib.h>
Copy link
Collaborator

Choose a reason for hiding this comment

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

We'll need to include this with hunter ideally or at least make it optional at compile time if we leave it for the system.

break;
}

// std::cout << "Duration frames: " << durationFrames << std::endl;
Copy link
Collaborator

Choose a reason for hiding this comment

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

We can use a logger here

Comment on lines +51 to +56
public:
sf_count_t frames;
unsigned int bitrate;
unsigned int channels;
int format;

Copy link
Collaborator

Choose a reason for hiding this comment

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

Can be made private?

struct AudioMixerProperties : PropertiesSerializable<Properties, AudioMixerProperties> {
static constexpr int AUTO = -1;

bool ready = false;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does it make sense for this to be a serializable property?

Comment on lines +1 to +33
#!/usr/bin/env python3

import depthai as dai

# Create pipeline
device = dai.Device()
with dai.Pipeline(device) as pipeline:
in = pipeline.create(dai.node.AudioIn);
in.setRunOnHost(True);
in.setDeviceName("microphone");
in.setDevicePath("default");
in.setBitrate(48000);
in.setFps(16);
in.setChannels(2);
in.setFormat(dai.AudioFrame.AUDIO_FORMAT_PCM_32);

out = pipeline.create(dai.node.AudioOut);
out.setRunOnHost(True);
out.setDeviceName("speaker");
out.setDevicePath("default");
out.setBitrate(44100);
out.setFps(16);
out.setChannels(2);
out.setFormat(dai.AudioFrame.AUDIO_FORMAT_PCM_16);

encoder = pipeline.create(dai.node.AudioOut);
out.setRunOnHost(False);
out.setBitrate(44100);
out.setChannels(2);
out.setFormat(dai.AudioFrame.AUDIO_FORMAT_PCM_16);

in.out.link(encoder.input);
encoder.out.link(out.input);
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 skip the semicolons

Copy link
Collaborator

Choose a reason for hiding this comment

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

Rename the example to match others

dai::Pipeline pipeline;

auto replay = pipeline.create<dai::node::AudioReplay>();
replay->setSourceFile("/tmp/test.wav");
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 add all test files to be pulled by hunter so that the examples work out of the box.

Likewise for python, so they're pulled in by install_requirements.py script. (Check how it works for videos that are used in current replay examples)

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