Rockbox Technical Forums

Rockbox Development => Starting Development and Compiling => Topic started by: slecta on May 04, 2020, 09:32:54 PM

Title: Porting audio-related code to c++ with a different
Post by: slecta on May 04, 2020, 09:32:54 PM
hi all,

was wondering if anyone could give me an idea what API library is closest to rockbox architecture when it comes to the audio callback type API stuff?  i made a plugin and was hoping to copy it over to another platform, like to run on a raspberry pi independently without rockbox..

not sure if i'm using the right language to explain what i am asking, hope it makes sense.. just want to get my stuff running outside of rockbox and i found the streaming audio callback part of the coding (specifically pcm_callback and rb->pcm_play_data) to be the most difficult when i got it running with rockbox, so was wondering if there is a library that is similar (or even identical) to how rockbox (plugin api) treats audio streams?

tried one or two libraries and they seemed somewhat different, and was wondering if there's an obvious answer like "rb was using this library which is also available outside the rockbox context"

thanks in advance
Title: Re: Porting audio-related code to c++ with a different
Post by: saratoga on May 04, 2020, 11:35:15 PM
tried one or two libraries and they seemed somewhat different, and was wondering if there's an obvious answer like "rb was using this library which is also available outside the rockbox context"

There is no external library here, you are directly calling the underlying OS functions.  I think it would be easiest to just write a wrapper around them for whatever you're using.
Title: Re: Porting audio-related code to c++ with a different
Post by: __builtin on May 05, 2020, 12:49:39 AM
There's a couple strategies you could take here. I'm most familiar with the SDL library, so I'll speak to that here.

SDL's audio module has a pretty similar callback architecture for getting PCM samples, see: https://www.libsdl.org/release/SDL-1.2.15/docs/html/guideaudioexamples.html (https://www.libsdl.org/release/SDL-1.2.15/docs/html/guideaudioexamples.html). The exact semantics (callback function parameters, caller/callee allocation etc.) are different but pretty trivial. Also the SDL video module (for SDL 1.2 and sticking to software rendering, at least) is superficially similar enough that you should be able to port most things easily enough.

You could also take a different route entirely and just compile rockbox itself into SDL application, which will give you whatever plugin you wrote for free (minus some adaptation of the input code IIRC). That's probably much easier, but comes at the cost of bringing all of rockbox with it.
Title: Re: Porting audio-related code to c++ with a different
Post by: boomselecta on August 09, 2021, 02:09:07 PM
Hi there,

Thanks for both your replies!

What kind of thing should I be looking for (googling) if I were to follow the compile-the-plugin-with-rockboz-into-a-standalone-pc-program (as you called it, as a standalone SDL?

Thanks again!
Title: Re: Porting audio-related code to c++ with a different
Post by: saratoga on August 09, 2021, 08:30:36 PM
When you configure a rockbox build (see development guide on the left side of the screen), select SDL as your target.  You'll need SDL libraries installed, but that will let you run Rockbox as a PC application.
Title: Re: Porting audio-related code to c++ with a different
Post by: boomselecta on August 11, 2021, 01:37:02 PM
Wow that's awesome!  Thanks for your help.

Have a great day