• 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: Coreaudio-api Digest, Vol 8, Issue 330
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Coreaudio-api Digest, Vol 8, Issue 330


  • Subject: Re: Coreaudio-api Digest, Vol 8, Issue 330
  • From: email@hidden
  • Date: Sat, 12 Nov 2011 10:28:43 +0000

Hi Kamaldeep

Not sure if any one has helped you yet, but I wrote this for printing a list of all audio devices. For me this was a great way of finding out how to acquire other properties for audio objects.

There are several properties acquired with global scope, so I made a class with the class method getPropertyAddressWithGlobalScope. Make sure you make a corresponding .h file.

ACpGetProperty.m:

#import "AcpGetProperty.h"

@implementation AcpGetProperty

+(AudioObjectPropertyAddress)getPropertyAddressWithGlobalScope:(AudioObjectPropertySelector)property {
AudioObjectPropertyAddress propertyAddress;
propertyAddress.mSelector = property;
propertyAddress.mScope = kAudioObjectPropertyScopeGlobal;
propertyAddress.mElement = kAudioObjectPropertyElementMaster;
return propertyAddress;
}
@end


audioNose.m:

#import "audioNose.h"

@implementation audioNose

+(void)getAllDevices{
NSMutableArray* deviceNames = [[NSMutableArray alloc] init]; 
NSMutableArray* deviceManufacturers = [[NSMutableArray alloc] init]; 
NSMutableArray* deviceUIDs = [[NSMutableArray alloc] init]; 
NSMutableArray* deviceAudioDeviceIDs = [[NSMutableArray alloc] init]; 
NSString* deviceDetail; 
AudioObjectPropertyAddress propertyAddress = [AcpGetProperty getPropertyAddressWithGlobalScope:kAudioHardwarePropertyDevices]; // identifies which property is being queried
AudioObjectID *deviceIDs; // array to store device IDs
UInt32 propertySize; // the size of the returned property information, needed to allocate the correct amount of memory
NSInteger numDevices; // needed to know the size of the device ID array
if (AudioObjectGetPropertyDataSize(kAudioObjectSystemObject, &propertyAddress, 0, NULL, &propertySize) == noErr) {  // find the size of the property, kAudioSystemObject is a generic AudioDevice to use
numDevices = propertySize / sizeof(AudioDeviceID); // find the number of devices (by dividing returned size by the known size of each device
deviceIDs = (AudioDeviceID*)calloc(numDevices, sizeof(AudioDeviceID)); // allocate memory for the deviceIDs array, based on the number of devices and the size of one audio device ID
if (AudioObjectGetPropertyData(kAudioObjectSystemObject, &propertyAddress, 0, NULL, &propertySize, deviceIDs) == noErr) { // get the property data into the memory allocated for what this queried property returns (an array of audioDeviceIDs)
CFStringRef deviceName;
CFStringRef deviceManufacturer;
CFStringRef deviceUID;
for (NSInteger index = 0; index < numDevices; index++) {
// get device name
propertySize = sizeof(deviceName);
AudioObjectPropertyAddress deviceNameAddress = [AcpGetProperty getPropertyAddressWithGlobalScope:kAudioObjectPropertyName];
if (AudioObjectGetPropertyData(deviceIDs[index], &deviceNameAddress, 0, NULL, &propertySize, &deviceName) == noErr) {
deviceDetail = (NSString*)deviceName; // toll free bridge
[deviceNames addObject: deviceDetail];
// get device manufacturer
propertySize = sizeof(deviceManufacturer);
AudioObjectPropertyAddress deviceManufacturerAddress = [AcpGetProperty getPropertyAddressWithGlobalScope:kAudioObjectPropertyManufacturer];
if (AudioObjectGetPropertyData(deviceIDs[index], &deviceManufacturerAddress, 0, NULL, &propertySize, &deviceManufacturer) == noErr) {
deviceDetail = (NSString*)deviceManufacturer; // toll free bridge
[deviceManufacturers addObject: deviceDetail];
// get UID of device
propertySize = sizeof(deviceUID);
AudioObjectPropertyAddress deviceUIDAddress = [AcpGetProperty getPropertyAddressWithGlobalScope:kAudioDevicePropertyDeviceUID];
if (AudioObjectGetPropertyData(deviceIDs[index], &deviceUIDAddress, 0, NULL, &propertySize, &deviceUID) == noErr) {
deviceDetail = (NSString*)deviceUID;
[deviceUIDs addObject:deviceDetail];
// get number which represents AudioDeviceID
[deviceAudioDeviceIDs addObject:[NSNumber numberWithInt:((UInt32)deviceIDs[index]) ] ];


} else {
NSLog(@"Error getting UID");
}
} else {
NSLog(@"Error getting device manufacturer");
}
} else {
NSLog(@"Error getting device name");
}
};
CFRelease(deviceName);
CFRelease(deviceManufacturer);
CFRelease(deviceUID);
};
};
// print information to console
for (NSInteger index = 0; index < numDevices; index++) { 
NSLog(@"Audio Object #%i:\nDevice Name: %@\nManufacturer: %@\nUID: %@\naudioDeviceID: %@\n\n", 
  index,
  [deviceNames objectAtIndex:index], 
  [deviceManufacturers objectAtIndex:index],
  [deviceUIDs objectAtIndex:index], 
  [deviceAudioDeviceIDs objectAtIndex:index] );
}
// clean up
[deviceNames release];
[deviceManufacturers release];
[deviceUIDs release];
[deviceAudioDeviceIDs release];
[deviceDetail release];
free(deviceIDs);
};

@end


Hope this helps / works. Give me a shout if you need the .h files as well.

Cheers

Simon





Message: 8
Date: Fri, 04 Nov 2011 20:32:52 -0700
From: kamaldeep tumkur <email@hidden>
Subject: Analog audio capture question
To: email@hidden
Message-ID:
<CALqS2BhOLFdv8uixmf=email@hidden">CALqS2BhOLFdv8uixmf=email@hidden>
Content-Type: text/plain; charset="utf-8"

Hello,

I am using CoreAudio APIs to capture analog audio through the line in jack
and write out a file.
Just realized that my recorded file is from the built in microphone instead
of the line in jack.
I have a Macbook Pro7,1.

I had used the AudioObjectGetPropertyData call to get the property
kAudioHardwarePropertyDefaultInputDevice and set it as the current device
on the AudioUnit.
How do I select the line in device to be the default device?

I went into System Preferences -> Sound and changed the audio port to be
input type instead of output type.
When I went back to debugging my code, it still seemed to be picking the
built in microphone as the default input.
What am I missing here?

I tried enumerating the devices available to the system using
kAudioHardwarePropertyDevices in the AudioObjectGetPropertyData call.
Not sure if this is the correct way of doing it, as I am not sure how to
tell if a device is actually the line in input device?
Appreciate your help with this.

Thanks
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.apple.com/mailman/private/coreaudio-api/attachments/20111104/844859b8/attachment.html

------------------------------

_______________________________________________
Coreaudio-api mailing list
email@hidden
http://lists.apple.com/mailman/listinfo/coreaudio-api

End of Coreaudio-api Digest, Vol 8, Issue 330
*********************************************


 _______________________________________________
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: MusicPlayerPreroll() - not working?
  • Next by Date: Collision between NSView subclasses
  • Previous by thread: MusicPlayerPreroll() - not working?
  • Next by thread: Collision between NSView subclasses
  • Index(es):
    • Date
    • Thread