Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: wacked TV Channel audio level display



Did you forget to enable level metering for the record device by setting the property kQTPropertyClass_SGAudioRecordDevice / kQTSGAudioPropertyID_LevelMetersEnabled to true? By default the SGAudioChannel does not turn on level metering because it pays a small cpu price for doing so. You must opt in for level metering.

-Brad Ford
QuickTime Engineering


On Oct 21, 2005, at 1:19 PM, Olivier Destrebecq wrote:

I am trying to include a VU meter in my application to display the level of the audio coming in through the mic.

I went through wakedTV sample code and pulled what i think i need to get it to work (see end of message) but when it is time to ask for kQTSGAudioPropertyID_AveragePowerLevels i always get the error kQTPropertyAskLaterErr. no matter how long i wait this is what i get.

Obviously, when i run wackedTV everything works fine:-)

Anybody has any idea of what is wrong or a sample code of how to do this?
Thanks


Olivier Destrebecq
http://otusweb.spymac.com/portfolio/

I left all the code related to the audio and stripped the rest, so if i don't do something here, that means i'm not doing it:-)

@implementation recorderWindowController
- (id) init
{
...
mMutex = QTMLCreateMutex();
[self setSequenceGrabberAudio: [[[SGAudio alloc] initWithSeqGrab: [[[SeqGrab alloc] init] autorelease]] autorelease]];
[[self sequenceGrabberAudio] setUsage: seqGrabPreview + seqGrabRecord + seqGrabPlayDuringRecord];


    if ( [[[[self sequenceGrabberAudio] grabber] channels] count] > 0)
    {
      [[[self sequenceGrabberAudio] grabber] preview];
    }
  }

  return self;
}


//===========================================================
// updateAudioLevelTimer
//===========================================================
- (NSTimer *)updateAudioLevelTimer
{
//NSLog(@"in -updateAudioLevelTimer, returned updateAudioLevelTimer = %@", updateAudioLevelTimer);


  return [[updateAudioLevelTimer retain] autorelease];
}

- (void)setUpdateAudioLevelTimer:(NSTimer *)anUpdateAudioLevelTimer
{
//NSLog(@"in -setUpdateAudioLevelTimer:, old value of updateAudioLevelTimer: %@, changed to: %@", updateAudioLevelTimer, anUpdateAudioLevelTimer);


  if (updateAudioLevelTimer != anUpdateAudioLevelTimer) {
    [updateAudioLevelTimer invalidate];
    updateAudioLevelTimer = [anUpdateAudioLevelTimer retain];
  }
}

//===========================================================
// volumeLevelValue
//===========================================================
- (float)volumeLevelValue
{
//NSLog(@"in -volumeLevelValue, returned volumeLevelValue = %i", volumeLevelValue);


  return volumeLevelValue;
}

- (void)setVolumeLevelValue:(float)aVolumeLevelValue
{
//NSLog(@"in -setVolumeLevelValue, old value of volumeLevelValue: %i, changed to: %i", volumeLevelValue, aVolumeLevelValue);


  volumeLevelValue = aVolumeLevelValue;
}

//===========================================================
// sequenceGrabberAudio
//===========================================================
- (SGAudio *)sequenceGrabberAudio
{
//NSLog(@"in -sequenceGrabberAudio, returned sequenceGrabberAudio = %@", sequenceGrabberAudio);


  return [[sequenceGrabberAudio retain] autorelease];
}

- (void)setSequenceGrabberAudio:(SGAudio *)aSequenceGrabberAudio
{
//NSLog(@"in -setSequenceGrabberAudio:, old value of sequenceGrabberAudio: %@, changed to: %@", sequenceGrabberAudio, aSequenceGrabberAudio);


  if (sequenceGrabberAudio != aSequenceGrabberAudio) {
    [sequenceGrabberAudio release];
    sequenceGrabberAudio = [aSequenceGrabberAudio retain];
  }
}

@end

@implementation recorderWindowController (privateInterface)

- (void)invalidateChannelMap
{
  QTMLGrabMutex(mMutex);

  if (mLevelsArray)
    free(mLevelsArray);
  mLevelsArray = NULL;

  QTMLReturnMutex(mMutex);
}

- (void) updateLevelIndicator: (NSTimer *) inTimer
{
#pragma unused(inTimer)

  Float32 amps = -FLT_MAX;

  QTMLGrabMutex(mMutex);
  SGAudio * myAudi = [self sequenceGrabberAudio];

  if (mLevelsArray == NULL)
  {
    UInt32 size;

[myAudi getPropertyInfoWithClass:kQTPropertyClass_SGAudioRecordDevice
id:kQTSGAudioPropertyID_ChannelMap
type:NULL size:&size flags:NULL];
if (size > 0)
{
SInt32 * map = (SInt32 *)malloc(size);


[myAudi getPropertyWithClass:kQTPropertyClass_SGAudioRecordDevice
id:kQTSGAudioPropertyID_ChannelMap
size:size
address:map sizeUsed:&size];


for (int i = 0; i < size/sizeof(SInt32); i++)
{
if (mChannelNumber == map[i])
{
mMyIndex = i;
mLevelsArraySize = size; // SInt32 and Float32 are the same size
mLevelsArray = (Float32*)malloc(mLevelsArraySize);
break;
}
}
free(map);
}
}



if (mLevelsArray) // paranoia
{
// get the avg power level
OSStatus error= [myAudi getPropertyWithClass:kQTPropertyClass_SGAudioRecordDevice
id:kQTSGAudioPropertyID_AveragePowerLevels
size:mLevelsArraySize
address:mLevelsArray sizeUsed:NULL];
if (noErr == error)
{
amps = mLevelsArray[mMyIndex];
}
}


  QTMLReturnMutex(mMutex);

  [self setVolumeLevelValue: dbamp(amps)];
}

double dbamp(double db)
{
  return pow(10., 0.05 * db);
}

double ampdb(double amp)
{
  return 20. * log10(amp);
}
@end

@implementation recorderWindowController (MTCoreAudioHardwarePropertyNotifications)
- (void) audioHardwareDeviceListDidChange
{
...
if ([devices count] 0)
{
//start the time to update the mic level indicator
//
[self setUpdateAudioLevelTimer: [NSTimer scheduledTimerWithTimeInterval: 1./20
target: self
s elector: @selector(updateLevelIndicator:)
u serInfo: nil
repeats: YES]];
}
}
@end
_______________________________________________
Do not post admin requests to the list. They will be ignored.
QuickTime-API mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/quicktime-api/email@hidden


This email sent to email@hidden


_______________________________________________ Do not post admin requests to the list. They will be ignored. QuickTime-API mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/quicktime-api/email@hidden

This email sent to email@hidden
References: 
 >wacked TV Channel audio level display (From: Olivier Destrebecq <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.