• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Convert an in-memory AAC file to LPCM
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Convert an in-memory AAC file to LPCM


  • Subject: Re: Convert an in-memory AAC file to LPCM
  • From: Richard <email@hidden>
  • Date: Fri, 26 Sep 2014 17:00:57 -0400

Chris,

I integrated your sample code into my app and it is working, I am getting the properties, 
including the ASBD, and the data packets out of the downloaded file, and I can play 
them through the Audio Queue. I now need do the conversion to LPCM (because I 
need to process the LPCM audio rather than just play it), and I am now going to use 
the Audio Converter Services to do that. I am going to take the example code from 
chapter 6 of your book and feed the data and packet descriptions from the packets 
callback process into it.

Many thanks for your help.

Richard



On Thu, Sep 25, 2014 at 2:58 AM, Richard <email@hidden> wrote:
Chris,

I quickly went through the source of your web radio app, and I think I can
adapt it for my app. I will try it out tomorrow.

Thanks,
Richard


On Wed, Sep 24, 2014 at 7:44 PM, Chris Adamson <email@hidden> wrote:
Looks like the latest version of the WebRadioApp demo is from a CocoaConf Boston class last year. I just ran it in the iPhone 6 simulator and it still works, so maybe start there:

<https://dl.dropboxusercontent.com/u/12216224/conferences/cocoaconfboston13/CCF Boston Core Audio class.zip>

I don't really have any slides or anything to go with it. The basic idea is that you start downloading with an NSURLConnection (yeah, I wrote this before NSURLSession), hand the raw NSData's over to an AudioFileStreamRef, it calls back to a properties proc (which receives format and "ready to produce packets"), and a packets proc (which feeds the AAC or MP3 packets to an AudioQueue for playback).

If you need a look at the LPCM data before it gets played, then we're talking about integrating an Audio Queue Processing Tap.

—Chris


On Sep 24, 2014, at 7:34 PM, Richard <email@hidden> wrote:

Hi Chris,

Yes it is a streaming app. After converting the AAC file to LPCM, I run it through
my main app which does some content analysis on the audio.

Does your sample allow me to avoid saving the received file data to a disk file?
That sounds like it matches what I am trying to do. I'd much appreciate any
pointers or sample code you could provide.

Richard


On Wed, Sep 24, 2014 at 6:11 PM, Chris Adamson <email@hidden> wrote:
Is this streaming? Audio File Stream services would be a nice way to parse the format for you. We don't cover it in the book, but I do show it in my CocoaConf class (I can send you the web radio player sample code) or that "live lessons" video thing I did for Pearson.

Only thing is, once you start using Audio File Stream, you're kind of locked into it: you feed raw blocks of NSData to it, and it calls you back with metadata and parsed packets. Maybe that'll work for you, maybe not.

-Chris

Sent from my iPad

On Sep 24, 2014, at 5:25 PM, Richard <email@hidden> wrote:

Chris,

Yes, I can change the callback function as you suggest. However, my app does not 
know in advance how the AAC file was encoded ( e.g. the  sampling rate). 

My understanding that the AAC file starts with a header that describes the format of
the rest of the audio data and this header needs to be parsed and mapped into an
ASBD. I know that the Audio File services API does this - is there any other API that 
can do the same thing but from an NSData object rather than by reading an actual file? 
I would like to avoid having to write code to parse the header of the AAC file myself.

Also, I guess the audio bytes start after this header, So I need to know the size of this
header so that I can skip past it to get to the audio data.

Once those two problems (getting the ASBD and figuring out how many bytes to skip 
over), are out of the way, I can do as you say and read out the rest of the audio bytes 
in my callback function.

Also, you mentioned using Audio Queue for conversions - I haven't used Audio Queue
myself, but I can go and look it up. However, I presume that the Audio Queue APIs also
need an ASBD so wouldn't I run into the same problem - how to generate an ASBD and 
how to know how many bytes of header to skip over.

Richard


On Wed, Sep 24, 2014 at 3:45 PM, Chris Adamson <email@hidden> wrote:
Should work a lot like that example, except that in your case the callback function that provides the data to convert (MyAudioConverterCallback() in that example) would just be advancing a pointer through your NSData, rather than calling AudioFileReadPackets().

FWIW, I freaking hate Audio Converter Services, and when I've had to do this myself, I sometimes will just use an offline AudioQueue to do format conversions. It simplifies buffering and is more streaming-friendly.

Hope this helps.

—Chris

On Sep 24, 2014, at 3:33 PM, Richard <email@hidden> wrote:

I have an iOS app that receives an AAC file over the network into an NSData buffer, and I would like to convert the received file to LPCM.

I saw the example in chapter 6 of the Core audio book using the Audio File services API.  This does what I want except for one thing; it expects the AAC file data to be in a file.

I could possibly save the received AAC bytes that from the NSData object into a file and then use the example from the CoreAudio book. However, I would like to avoid that step as I really have no use for that file apart from that conversion. It seems like a waste and it would also increase the latency for the AAC to LPCM conversion.

When I looked at the Audio File Services document,

https://developer.apple.com/library/ios/documentation/MusicAudio/Reference/AudioFileConvertRef/index.html

I saw this line:

This document describes Audio File Services, a C programming interface that enables you to read or write a wide variety of audio data to or from disk or a memory buffer.

But when I looked at the documentation, the functions seems to require a file id. They appear to be memory to file or file to memory conversions, and not memory to memory (I know that you can do memory to memory conversions from one LPCM format to another, but that is not what I need).

Is there any way to do this conversion without using a file as a staging area?

Richard


 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Coreaudio-api mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Convert an in-memory AAC file to LPCM
      • From: Chris Adamson <email@hidden>
References: 
 >Convert an in-memory AAC file to LPCM (From: Richard <email@hidden>)
 >Re: Convert an in-memory AAC file to LPCM (From: Chris Adamson <email@hidden>)
 >Re: Convert an in-memory AAC file to LPCM (From: Richard <email@hidden>)
 >Re: Convert an in-memory AAC file to LPCM (From: Chris Adamson <email@hidden>)
 >Re: Convert an in-memory AAC file to LPCM (From: Richard <email@hidden>)
 >Re: Convert an in-memory AAC file to LPCM (From: Chris Adamson <email@hidden>)
 >Re: Convert an in-memory AAC file to LPCM (From: Richard <email@hidden>)

  • Prev by Date: Re: What could cause error -4 in Logic validation?
  • Next by Date: Re: Convert an in-memory AAC file to LPCM
  • Previous by thread: Re: Convert an in-memory AAC file to LPCM
  • Next by thread: Re: Convert an in-memory AAC file to LPCM
  • Index(es):
    • Date
    • Thread