• 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
reading AudioBuffer contents
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

reading AudioBuffer contents


  • Subject: reading AudioBuffer contents
  • From: Judith Suttrup <email@hidden>
  • Date: Tue, 09 Sep 2008 23:31:16 +0200
  • Organization: http://freemail.web.de/

Hi List,

I want to use the raw data of a QTMovie to display it in an oscilloscope. I think the audio extraction works correctly but I am not exactly sure if I choose a correct way to pass the data into the arrays cause the graphs I create are not exactly the way I expected them to be. Has somebody any suggestion for me?


	soundToPlay = [[self mMovie] quickTimeMovie];

	SetMovieActive(soundToPlay, TRUE);

	error = MovieAudioExtractionBegin(soundToPlay, 0, &extractionSessionRef);


	error = MovieAudioExtractionGetProperty(extractionSessionRef,
											kQTPropertyClass_MovieAudioExtraction_Audio,
											kQTMovieAudioExtractionAudioPropertyID_AudioStreamBasicDescription,
											sizeof (asbd), &asbd, nil);


	Boolean allChannelsDicrete = TRUE;

	error = MovieAudioExtractionSetProperty(extractionSessionRef,
											kQTPropertyClass_MovieAudioExtraction_Movie,
											kQTMovieAudioExtractionMoviePropertyID_AllChannelsDiscrete,
											sizeof (Boolean), &allChannelsDicrete);

	asbd.mSampleRate = 44100;
	asbd.mFormatID = kAudioFormatLinearPCM;
	asbd.mFormatFlags = kLinearPCMFormatFlagIsNonInterleaved |
	kLinearPCMFormatFlagIsPacked |
	kLinearPCMFormatFlagIsFloat;
	asbd.mBytesPerPacket = 4;
	asbd.mFramesPerPacket = 1;
	asbd.mBytesPerFrame = 4;
	asbd.mChannelsPerFrame = 2;
	asbd.mBitsPerChannel = 32;


	error = MovieAudioExtractionSetProperty(extractionSessionRef,
											kQTPropertyClass_MovieAudioExtraction_Audio,
											kQTMovieAudioExtractionAudioPropertyID_AudioStreamBasicDescription,
											sizeof (asbd), &asbd);


	float				numFramesF				= asbd.mSampleRate * ((float) GetMovieDuration(soundToPlay) / (float) GetMovieTimeScale(soundToPlay));
	UInt32				numFrames				= (UInt32) numFramesF;
	UInt32				extractionFlags			= 0;
	AudioBufferList*	abl 					= (AudioBufferList *)malloc(sizeof(AudioBufferList) + sizeof(AudioBuffer));


	abl->mNumberBuffers = asbd.mChannelsPerFrame;

	unsigned i;
	for(i = 0; i < abl->mNumberBuffers; i++) {
		abl->mBuffers[i].mNumberChannels = 1;
		abl->mBuffers[i].mDataByteSize = sizeof(Float32) * abl->mBuffers[0].mNumberChannels * numFrames;
		abl->mBuffers[i].mData = malloc(abl->mBuffers[i].mDataByteSize);
	}

	[self setSampleCount: numFrames / 2];
	[self setSamples:calloc(abl->mBuffers[0].mDataByteSize, 1)];
	abl->mBuffers[0].mData = samples;

	[self setSecSampleCount: numFrames / 2];
	[self setSecSamples:calloc(abl->mBuffers[1].mDataByteSize, 1)];
	abl->mBuffers[1].mData = secSamples;


	error = MovieAudioExtractionFillBuffer(extractionSessionRef, &numFrames, abl, &extractionFlags);

	error = MovieAudioExtractionEnd(extractionSessionRef);

	ExitMovies();


}

- (void)compressScopeSweeps
{

	int i = 0;
	int j = 0;

	if (ipbuf == NULL) {

		[self setIpbuf:[[NSMutableArray alloc] init]];
	}

	if (idbuf == NULL) {
		[self setIdbuf:[[NSMutableArray alloc] init]];
	}


	for (i = 0; i < (sampleCount); i++) {
		[ipbuf addObject:[NSNumber numberWithFloat:(Float32)samples[i]]];
	}

	for (j = 0; j < (secSampleCount); j++) {
		[idbuf addObject:[NSNumber numberWithFloat:(Float32)secSamples[j]]];
		}

}

- (void) drawScopeSweep: (NSRect)rect
{

	[self importAudioFromFile:self];
	[self compressScopeSweeps];


	NSBezierPath* aPath = [NSBezierPath bezierPath];
	NSBezierPath* secPath = [NSBezierPath bezierPath];
	[aPath setLineWidth:1.0];
	[secPath setLineWidth:1.0];
	[aPath moveToPoint:NSMakePoint(0, 0)];
	[secPath moveToPoint:NSMakePoint(0, 300)];

	int timer = 0;
	int i = 0;
	float x = 0.0, y = 0.0;

	for(; i < [ipbuf count]; i++){
		timer++;
		x =	timer;
		y = [[ipbuf objectAtIndex:i] floatValue] / 2;
		[aPath lineToPoint:NSMakePoint(x, y)];
	}


	timer = 0;
	i = 0;
	x = 0;
	y = 0;

	for(; i < [idbuf count]; i++){
		timer++;
		x =	timer;
		y = [[idbuf objectAtIndex:i] floatValue] / 2 + 300;
		[secPath lineToPoint:NSMakePoint(x, y)];
	}

	[[NSColor yellowColor] setStroke];
	[aPath stroke];
	[secPath stroke];
	[aPath closePath];
	[secPath closePath];
}

Thanks a lot,
Judith Suttrup


_____________________________________________________________________
Der WEB.DE SmartSurfer hilft bis zu 70% Ihrer Onlinekosten zu sparen!
http://smartsurfer.web.de/?mc=100071&distributionid=000000000066

 _______________________________________________
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

  • Prev by Date: Re: Examples for AudioFileStream and AudioConverter?
  • Next by Date: Re: Error 0xE00002EE with PCI audio driver
  • Previous by thread: Re: Examples for AudioFileStream and AudioConverter?
  • Next by thread: behaviour of MIDIFlushOutput
  • Index(es):
    • Date
    • Thread