• 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: Input level meter
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Input level meter


  • Subject: Re: Input level meter
  • From: Olivier Destrebecq <email@hidden>
  • Date: Thu, 27 Oct 2005 10:59:37 -0400

For the benefit of other who will maybe search the list for such code, here is what i came up with. Hope it will be helpful


@interface ....

UInt32 mChannelNumber;
Float32 * mLevelsArray;
UInt32 mLevelsArraySize;
UInt32 mMyIndex; // the index of _this_ channel in the mLevelsArray
...
@end


@implementation ....

- (id) init
{....

    mMutex = QTMLCreateMutex();
...}

- (void) startUpdatingMeter
{
//set up everything we need to monitor the audio level
//
[self setSequenceGrabberAudio: [[[SGAudio alloc] initWithSeqGrab: [[[SeqGrab alloc] init] autorelease]] autorelease]];
[[self sequenceGrabberAudio] setUsage: seqGrabPreview + seqGrabRecord + seqGrabPlayDuringRecord];


//make sure we display the device the user selected
//
NSString * uid = [[[self document] recordingDevice] deviceUID];
NSAssert([[self sequenceGrabberAudio] setPropertyWithClass: kQTPropertyClass_SGAudioRecordDevice
id: kQTSGAudioPropertyID_DeviceUID
size: sizeof(uid)
address: &uid] == noErr, @"could not set our device as the device to monitor");


      Float32 masterVolume = 0.05;

[[self sequenceGrabberAudio] setPropertyWithClass: kQTPropertyClass_SGAudioPreviewDevice
id: kQTSGAudioPropertyID_MasterGain
size: sizeof (Float32)
address: &masterVolume];


BOOL doEnable = YES;
NSAssert([[self sequenceGrabberAudio] setPropertyWithClass: kQTPropertyClass_SGAudioRecordDevice
id: kQTSGAudioPropertyID_LevelMetersEnabled
size: sizeof(doEnable)
address: &doEnable] == noErr, @"could not turn metering on");


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


//start the time to update the mic level indicator
//
[self setUpdateAudioLevelTimer: [NSTimer scheduledTimerWithTimeInterval: 1./20
target: self
selector: @selector(updateLevelIndicator:)
userInfo: nil
r epeats: YES]];
}



- (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) * 50];
}




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


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


On Oct 13, 2005, at 4:01 PM, Olivier Destrebecq wrote:

I'm using MTCoreAudio and Core audio to record audio to file. i would like to be able to show the audio level (too loud or not enough, as in ichat and system pref) so that the user can see if sound is coming in onn the mic. I lloked through the mailing and the examples but could find anything that pointed me toward a solution.

I'm a beginner, so don't hesitate to point me to obvious stuff.

Olivier
http://otusweb.spymac.com/home/


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


This email sent to email@hidden

!DSPAM:434ebf2c170491070910932!


_______________________________________________ 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
References: 
 >Input level meter (From: Olivier Destrebecq <email@hidden>)

  • Prev by Date: Re: Channels and frames
  • Next by Date: possible audio buffer underrun & load balancing
  • Previous by thread: Input level meter
  • Next by thread: Is it possible Music Track - Voice Track volume adaption
  • Index(es):
    • Date
    • Thread