• 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
Using the audio extraction API to extract to mixed mono?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Using the audio extraction API to extract to mixed mono?


  • Subject: Using the audio extraction API to extract to mixed mono?
  • From: Kaspar Fischer <email@hidden>
  • Date: Fri, 3 Mar 2006 18:43:11 +0100

Hi,

I need to extract the audio from a movie in such a way that
all present audio channels get mixed to a single one. I have
started with Apple's "demo" from

  http://developer.apple.com/quicktime/audioextraction.html

but have run into a problem which is not covered there (and
the documentation has not helped me either). How can I set
the channel layout to "mono"?

Thanks,
Kaspar

P.S. My code so far is the following:

+ (OSStatus)extractAudioFromQPTMovie:(Movie)qtmov
                    withSamplingRate:(int)samplingRate
             yieldingNumberOfSamples:(long *)actualSamples
{
  OSStatus                err                  = noErr;
  MovieAudioExtractionRef extractionSessionRef = nil;

  // begin extraction session:
  signed char *tmp = nil;
  err = MovieAudioExtractionBegin(qtmov, 0, &extractionSessionRef);
  if (err != noErr)
    goto bail;

  // get the size of the extraction output layout:
  AudioChannelLayout *layout  = NULL;
  UInt32             size     = 0;
  err = MovieAudioExtractionGetPropertyInfo(extractionSessionRef,
      kQTPropertyClass_MovieAudioExtraction_Audio,
      kQTMovieAudioExtractionAudioPropertyID_AudioChannelLayout,
      NULL, &size, NULL);
  if (err != noErr)
    goto bail;

  // allocate memory for the channel layout
  layout = (AudioChannelLayout *) calloc(1, size);
  if (layout == nil)  {
    err = memFullErr;
    goto bail;
  }

// get the layout for the current extraction configuration:
// (Note: this will have already been expanded into channel descriptions.)
err = MovieAudioExtractionGetProperty(extractionSessionRef,
kQTPropertyClass_MovieAudioExtraction_Audio,
kQTMovieAudioExtractionAudioPropertyID_AudioChannelLayout,
size, layout, nil);
if (err != noErr)
goto bail;


// get the default audio extraction ASBD:
AudioStreamBasicDescription asbd;
err = MovieAudioExtractionGetProperty(extractionSessionRef,
kQTPropertyClass_MovieAudioExtraction_Audio,
kQTMovieAudioExtractionAudioPropertyID_AudioStreamBasicDescription,
sizeof(asbd), &asbd, nil);
if (err != noErr)
goto bail;


// convert the ASBD to return interleaved 8-bit PCM instead of non- interleaved Float32.
asbd.mFormatFlags = kAudioFormatFlagIsSignedInteger | kAudioFormatFlagIsPacked
| kAudioFormatFlagsNativeEndian;
asbd.mBitsPerChannel = sizeof(signed char) * 8;
asbd.mBytesPerFrame = 1; // sizeof(SInt16) * asbd.mChannelsPerFrame;
asbd.mBytesPerPacket = asbd.mBytesPerFrame;
asbd.mSampleRate = samplingRate;
asbd.mFramesPerPacket = 1;
asbd.mChannelsPerFrame = 1;


// set the new audio extraction ASBD:
err = MovieAudioExtractionSetProperty(extractionSessionRef,
kQTPropertyClass_MovieAudioExtraction_Audio,
kQTMovieAudioExtractionAudioPropertyID_AudioStreamBasicDescription,
sizeof (asbd), &asbd);
if (err != noErr)
goto bail;


// extract:
tmp = malloc(NROFSAMPLESPEREXTRACTIONCALL);
AudioBufferList bflst = {1, {{1, NROFSAMPLESPEREXTRACTIONCALL, (void *)tmp}}};
UInt32 flags = 0, numFrames;
while ((flags & kQTMovieAudioExtractionComplete) == 0) {
numFrames = NROFSAMPLESPEREXTRACTIONCALL;
err = MovieAudioExtractionFillBuffer(extractionSessionRef,
&numFrames, &bflst, &flags);
if (err != noErr)
goto bail;


    // processing:
    NSLog(@"MAEFB returned %d frames", numFrames);
  }

bail:
  if (tmp != nil)
    free(tmp);
  return err;
}

_______________________________________________
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: Using the audio extraction API to extract to mixed mono?
      • From: William Stewart <email@hidden>
  • Prev by Date: Generating AAC audio for broadcasting over RTP
  • Next by Date: Re: Apple USB MIDI driver & port names
  • Previous by thread: Re: Generating AAC audio for broadcasting over RTP
  • Next by thread: Re: Using the audio extraction API to extract to mixed mono?
  • Index(es):
    • Date
    • Thread