Read audio from movie

Hello, there.

I have need to extract the audio from formats supported by all platforms and I’ve been given the limitation of not using third party software and be cross-platform. So while I can use built-in functions (movieplayer, etc.) and declares (as long as they work cross-platform) I can’t use plug-ins or command-line helpers.

I can’t know the format of the audio, but I can read, for example, an MP3 into a movieplayer and get the duration. I can’t access anything of the player though other than state and position.

The final goal is to be able to show a timeline to flag events of the audio so I could do this with an interface-less movieplayer, but then I’d need to possibly show the audio’s waveform (which I can technically do if I can get to the uncompressed data as a binarystream) and then save as WAV (which I can also do if I have the audio datastream).

So, after a couple of days trying different options I ask the forum: Do you know of a plugin-less/helper-less way to get the audio that a movieplayer can load so I can read its uncompressed form to later write to a WAV myself? We’re talking hour-long files so I need to be able to read asynchronoously on load.

Obviously movieplayer is not required, but it takes care of “understanding” the file using the OS’es frameworks (mac and windows, most frequently). Not basing a solution in movieplayer may be an option I can’t imagine yet.

Also, I’m limited to Xojo 2014r2.1

I’m OK with being given a direction on what to do, as I’m just hitting walls here.

I really can’t help with a plugin?

[quote=246089:@Eduardo Gutierrez de Oliveira]
I’m OK with being given a direction on what to do, as I’m just hitting walls here.[/quote]
Work as hard as you can to tell whoever set the “no plugins” restriction that setting that one restriction means its going to cost you WAY more time & effort to do all the declares into OS provided function than using the plugin would cost you

Basically to do it without the plugin means you have to recreate similar functionality by declaring into the OS API’s which are VERY different x-platform to get the same level of functionality that the plugin already has

[quote=246127:@Norman Palardy]Work as hard as you can to tell whoever set the “no plugins” restriction that setting that one restriction means its going to cost you WAY more time & effort to do all the declares into OS provided function than using the plugin would cost you

Basically to do it without the plugin means you have to recreate similar functionality by declaring into the OS API’s which are VERY different x-platform to get the same level of functionality that the plugin already has[/quote]

I’ve tried this before. It seems to come from a past bad experience with VB code where some add-on was used and at some point it just stopped working but a huge app depended on it for a ton of functionality. In the end they ended up setting a policy about having the source of all house-built applications. The policy is not local to my office or this country, so there’s not a lot I’ve been able to to about it over the years (I think I might have mentioned it some years ago as well, I personally have no problem with plug-ins or helpers).

Sorry, Christian. I didn’t doubt you’d have one and I did mention it, but Compliance bounced me back.

I wish you good luck with the MP3 specification.

Even if you relay on a plugin and someday it stops working, you can swap out that part of the app and replace with a different plugin/tool/whatever.

We had some transitions. I used QuickTime a lot and Apple deprecated it.
But we have AVFoundation on Mac and some Windows Media Player things on Windows and VLC cross platform.

[quote=246168:@Christian Schmitz]I wish you good luck with the MP3 specification.

Even if you relay on a plugin and someday it stops working, you can swap out that part of the app and replace with a different plugin/tool/whatever.

We had some transitions. I used QuickTime a lot and Apple deprecated it.
But we have AVFoundation on Mac and some Windows Media Player things on Windows and VLC cross platform.[/quote]

Thanks, I don’t plan on implementing the MP3 specification at all (I have the IDV3 part implemented, which I’ll be using when present for other things), since the requirement is not for specific formats but for “formats supported by the OS”. So essentially I need to find a way for the system to provide the sound, in the same way the movieplayer can play it (regardless of format, as long as the format is OS-supported).

If I can’t find a way to have an internal representation of the data I won’t be doing that part, as it would be unsustainable with the current specs. The way they see it, if the system can play it then the system should also be able to provide the audio data to the app on demand. So off to the declares and frameworks I go.

I have Mac declares using the Audio Toolbox Framework for reading PCM data in from mp3, mp4, mov… I think any format the OS understands. Fairly simple to use framework actually, like only 7 declares needed.

Audio Toolbox See the ‘Extended Audio File Services’ section for most of the necessary info.

I can post what I have to get you going if you want but it’s not checked for 64bit compatibility and the asynchronous read portion was never finished because the longest I’d read in is 1/2 hour audio and that takes just a few seconds.

For Windows I don’t know those frameworks.

[quote=246172:@Will Shank]I have Mac declares using the Audio Toolbox Framework for reading PCM data in from mp3, mp4, mov… I think any format the OS understands. Fairly simple to use framework actually, like only 7 declares needed.

Audio Toolbox See the ‘Extended Audio File Services’ section for most of the necessary info.

I can post what I have to get you going if you want but it’s not checked for 64bit compatibility and the asynchronous read portion was never finished because the longest I’d read in is 1/2 hour audio and that takes just a few seconds.

For Windows I don’t know those frameworks.[/quote]

That would seriously get me started down the right track! This is for a 70 mac/30 windows shop so it’s aligned with the priorities :smiley:

Your first post says that the given limitation is: ‘not third party software’ and therefore it needs to be ‘plugin-less/helper-less’.

Is that based on the policy you mentioned in your second post?

If that’s the case, are you sure you’re interpreting this policy correctly?

For example, if you use ffmpeg as helper, you have everything you need if you include the ffmpeg source with the build instructions as part of your project.

Here’s a couple versions of the declares. It’s not really documented for others but this may help make sense of it.

In project AudioTB look in…
LPCM > newAudioAsMonoIntInterleaved
This method defines all the declares and returns PCM data from a Folderitem.
There’s also a window, PlayPlotFreqWindow, that demos opening a file and drawing the waveform (hit space to play/pause or click/drag in the bottom strip).

Project EAFS is a refactoring, with all declares wrapped in individual methods, and the basic/common routines collected in Module ez. Look in…
ATB > ez > loadFile/AtRate/InRange
…for where it loads PCM data. Basically the same as the method above but probably cleaner to read. There’s also some loadFileAsync variations being tested. No demo.

Here’s an outline of the loading routine

[code]ExtFileRef = handle to the ‘object’ for getting audio info
asbd = AudioStreamBasicDescription (struct of sample rate, type, mono, etc…)

  1. Folderitem -> CFURL

  2. CFURL -> ExtFileRef

  3. Get some info about the source audio
    at least sample rate (from input asbd) and frame count

  4. create output asbd describing the pcm format you want
    32bit integer or float, mono or stereo, split or interleaved

  5. create a bufferlist structure pointing to Memoryblocks

  6. read n samples into the bufferlist Memoryblocks

  7. close references and return Memoryblocks[/code]

To load asynchronously you’d loop, reading a smaller n. First update the bufferlist so it points to the right place in the Memoryblock, read 20M samples in, then loop and reposition bufferlist for the next 20M and so on. Should be done in a thread I guess but I was trying to make a version that relied on Refresh for drawing progress (which wouldn’t work anymore anyways).

I’ve been working here for a decade and a half. Any confusion regarding the policy is by mi inability to communicate properly, not due to any confusion on my part. This is also not a place to be clever or to find workarounds, as this thing is pretty clear: All code for the application in this case should be viewable/editable within Xojo. Only non-xojo allowed is system calls (declares) and built-in helpers (I can use “find” from the commandline OSX, for example, as long as the functionality has equivalents in other targetted platforms, but I can’t use ffmpeg, which isn’t included in OSX and isn’t built from Xojo source).

I’m not justifying the rules they have here, but I have to abide by them. The only reason I’m being allowed to use declares and system tools is because I could convince them that was just “using the system”.

I thank everyone that suggests for ways to work around the limitations. I’ve thought about them all, I think, and this is still what it is. They’ve alread passed in the past from doing stuff if it didn’t fit their requirements, so I know what the deal is.

[quote=246233:@Will Shank]Here’s a couple versions of the declares. It’s not really documented for others but this may help make sense of it.
[/quote]

Thanks a lot. This plants me firmly in the right track. I’ll look for the equivalent calls in Windows and see if I can wrap them all together.

Thanks again, you’ve been enormous help.

On Windows mciSendString may get you there (perhaps?). Barry Traver had some audio applications/examples that used this to play wav, mp3, midi, avi, mpg, and audio CD’s. I haven’t seen him around in a while, but his stuff still out there. I am also pretty sure that if Andrew sees this he may come up with some nifty declares for Windows.

Try the AV Player or the MiniAv Player - http://traverrbw.blogspot.com/

Nice. I didn’t know about this one. I’m not as familiar with Windows development so I was slowly building my references. This should help.

I think I might’ve found him – not good news, tho :’(
http://www.dewalds.com/sitemaker/sites/Dewald1/obit.cgi?user=56304871_BTraver