Building an "audio desk" app

Hi, I’m one of the small contributors to StreamRadio, an app which allows to listen to online streams.

At some point, I wanted to add recording capabilities to it (I must inform, in first place, that I don’t have any background in C++). While looking at the Media Kit API searching for ways to do this I’ve come up with what I think is a better idea: to make another app, able to record any audio stream currently playing.

In the multimedia control preflet, I can set different volumes for every stream playing, and what’s better, every single stream has its proper name. For example, if I start two different radio streams in StreamRadio (yes, it can do that) I get a different volume control for every one of them, along with the names. That led me to the following idea: maybe it’s not so difficult to build an application to grab those outputs and feed them to an encoder.

I already know how to use GetLiveNodes() to get a list of the active nodes, and I’ve learned to filter those results to get only the nodes I want. Problem is I can’t Connect() to them because the function fails with B_MEDIA_ALREADY_CONNECTED, which makes sense since they’re already connected to the mixer/audio output, and obviously an application shouldn’t be able to mess with another.

So, to summarize… is there a way to do what I want? Can I get a “copy” of the node? Is there an app for this already? (I have a vague memory of a BeOS screenshot showing an app which could redirect audio inputs/outputs, like an audio desk or something, but I might be making this up)

Thanks in advance

1 Like

The app you may be thinking about is called “Cortex”. It’s included as a demo app with every Haiku installation.

One caveat is that I believe there are some issues/bugs in the Media Kit for some of the reconnections in Cortex, in particular I believe things go badly if you mess much with the system mixer. I see one particular bug related to Cortex and connections, so in case you see issues keep that in mind.

Obviously we want all this to work perfectly but the Media Kit is quite a beast and we have not had many people working on it in the last few years. I’ve done a few things but still have a lot to learn and not much time lately.

Thanks to both of you. It was Cortex, indeed. I’ve just made a couple of tests and I can confirm what the bug report describes. Disconnecting the system mixer output means a restart is needed. In any case, I just need to connect (for example) StreamRadio’s output to the sound recorder’s input. In my tests, the connection is made but then nothing happens, and I can’t get a record of what’s being played.

I’ll keep trying a few different things in Cortex and I’ll take a look at the source code, as a starting point, to see how disconnections are done and nodes are freed. The ultimate goal is to write a simple app that records any stream being played.

I am not the kind of person who gets snippy and says “patches welcome!” when people find bugs, but honestly if you have some experience with the Media Kit and an app you want to make, then patches are welcome indeed! Obviously if Cortex can make these connection changes your app should as well, and in fact that would be a nice way for the app to work: you start the app, it asks which streams you want to record, and it does the magic to put itself in the middle and make the reconnections.

In some sense maybe your simpler app would be a better test bed to fix any issues with the connection handling in the Media Kit than Cortex.

Regarding the system mixer disconnection requiring a reboot I believe that is just something sort of stupid where it just doesn’t handling being disconnected and reconnected. There are quite a few TODOs and little issues in the Media Kit code. As I said I tried to step up a few years ago but it was a lot to learn and I did not have a specific use case like you do. If you want to know about known bugs obviously you can search on our Trac using components like Media Kit, media_server, media_addon_server, Mixer and maybe a few more…there are a lot of pieces involved…


A post was split to a new topic: Any tips on using Cortex?