• 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: Getting the PreferedHardwareIOBufferDuration
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Getting the PreferedHardwareIOBufferDuration


  • Subject: Re: Getting the PreferedHardwareIOBufferDuration
  • From: Mark's Studio <email@hidden>
  • Date: Thu, 26 Feb 2009 10:17:51 +0100

Hi Greg,


i have tried a few things but can't get it to work. unless i make a without making
here is my listener functions,


you should be able to paste them into the aurioTouchAppDelegate.mm
and remove the rioInterruptionListener() from the aurio_helper.cpp

bufferSize 0.005805
routeChangeReason 1
kAudioSessionProperty_AudioCategory'plar'
kAudioSessionProperty_OtherAudioIsPlaying 1
bufferSize 0.005805
Session interrupted! 1--- Begin Interruption --- iPod app starts playing
routeChangeReason 3
kAudioSessionProperty_AudioCategory'plar'
kAudioSessionProperty_OtherAudioIsPlaying 0
bufferSize 0.023220
routeChangeReason 3 AVAudioPlayer starts and iPod fades out (you need to add a similar function to the sample code)
kAudioSessionProperty_AudioCategory'plar'
kAudioSessionProperty_OtherAudioIsPlaying 1
bufferSize 0.023220
routeChangeReason 2 Line out plug from iPhone dock removed
kAudioSessionProperty_AudioCategory'plar'
kAudioSessionProperty_OtherAudioIsPlaying 1
Error: couldn't initialize the remote I/O unit ('!act')
Error: couldn't start unit ('!act')
bufferSize 0.005805
routeChangeReason 1 Line out plug from iPhone dock plugged in
kAudioSessionProperty_AudioCategory'plar'
kAudioSessionProperty_OtherAudioIsPlaying 0
bufferSize 0.005805





the app is actually already on the App Store.

http://irock.marks-studio.dk





void rioInterruptionListener( void *inUserData,
UInt32 inInterruption)
{
// NSLog(@"Session interrupted! --- %s ---", inInterruption == kAudioSessionBeginInterruption ? "Begin Interruption" : "End Interruption");
printf("Session interrupted! %d--- %s ---\n",inInterruption, inInterruption == kAudioSessionBeginInterruption ? "Begin Interruption" : "End Interruption");

// AudioUnit *remoteIO = (AudioUnit*)inUserData;
AudioControl *THIS = (AudioControl*)inUserData;

if (inInterruption == kAudioSessionEndInterruption)
{
// make sure we are again the active session
AudioSessionSetActive(true);
AudioOutputUnitStart(THIS->rioUnit);
}

if (inInterruption == kAudioSessionBeginInterruption){
if(THIS->rioUnit !=nil)
AudioOutputUnitStop(THIS->rioUnit);
}
}




void propListener( void * inClientData,
AudioSessionPropertyID inID,
UInt32 inDataSize,
const void * inData)
{
// Print4CharCode("AudioSessionPropertyID",inID);
AudioControl *THIS = (AudioControl*)inClientData;
CFDictionaryRef routeChangeDictionary = (CFDictionaryRef)inData;
CFNumberRef routeChangeReasonRef =
(CFNumberRef) CFDictionaryGetValue (routeChangeDictionary,CFSTR (kAudioSession_AudioRouteChangeKey_Reason));
Float32 bufferSize;//.005 020
UInt32 siz = sizeof(bufferSize);

SInt32 routeChangeReason; // 9

CFNumberGetValue (routeChangeReasonRef,kCFNumberSInt32Type,&routeChangeReason);
printf("routeChangeReason %d\n",routeChangeReason);
UInt32 audioCategory;
UInt32 size = sizeof(audioCategory);
AudioSessionGetProperty(kAudioSessionProperty_AudioCategory, &size, &audioCategory);
Print4CharCode("kAudioSessionProperty_AudioCategory",audioCategory);
UInt32 otherAudioIsPlaying;
AudioSessionGetProperty(kAudioSessionProperty_OtherAudioIsPlaying, &size, &otherAudioIsPlaying);
printf("kAudioSessionProperty_OtherAudioIsPlaying %d \n",otherAudioIsPlaying);

// if(routeChangeReason != kAudioSessionRouteChangeReason_CategoryChange) {
if(otherAudioIsPlaying && routeChangeReason == kAudioSessionRouteChangeReason_CategoryChange) {
try {
UInt32 audioCategory = kAudioSessionCategory_PlayAndRecord;// kAudioSessionCategory_PlayAndRecord kAudioSessionCategory_RecordAudio
XThrowIfError (AudioSessionSetProperty(kAudioSessionProperty_AudioCategory, sizeof(audioCategory), &audioCategory), "couldn't set audio category");
Float32 preferredBufferSize = kPreferredBufferSize;//.005 020
XThrowIfError (AudioSessionSetProperty (kAudioSessionProperty_PreferredHardwareIOBufferDuration, sizeof(preferredBufferSize), &preferredBufferSize), "couldn't set i/o buffer duration");
XThrowIfError(AudioSessionSetActive(true), "couldn't set audio session active\n");
AudioSessionGetProperty (kAudioSessionProperty_CurrentHardwareIOBufferDuration, &siz, &bufferSize);
if(bufferSize > kPreferredBufferSize){
AudioSessionSetActive(false);
AudioSessionSetActive(true);
// XThrowIfError(AudioSessionSetActive(true), "couldn't set audio session active\n");
}
XThrowIfError(AudioOutputUnitStart(THIS->rioUnit), "couldn't start unit");
}
catch (CAXException e) {
char buf[256];
fprintf(stderr, "Error: %s (%s)\n", e.mOperation, e.FormatError(buf));
}

}else if (inID == kAudioSessionProperty_AudioRouteChange && routeChangeReason != kAudioSessionRouteChangeReason_CategoryChange) {

try {
UInt32 audioCategory = kAudioSessionCategory_PlayAndRecord;// kAudioSessionCategory_PlayAndRecord kAudioSessionCategory_RecordAudio
XThrowIfError (AudioSessionSetProperty(kAudioSessionProperty_AudioCategory, sizeof(audioCategory), &audioCategory), "couldn't set audio category");
Float32 preferredBufferSize = kPreferredBufferSize;//.005 020
XThrowIfError (AudioSessionSetProperty (kAudioSessionProperty_PreferredHardwareIOBufferDuration, sizeof(preferredBufferSize), &preferredBufferSize), "couldn't set i/o buffer duration");
XThrowIfError(AudioSessionSetActive(true), "couldn't set audio session active\n");
AudioSessionGetProperty (kAudioSessionProperty_CurrentHardwareIOBufferDuration, &siz, &bufferSize);
if(bufferSize > kPreferredBufferSize){
AudioSessionSetActive(false);
AudioSessionSetActive(true);
// XThrowIfError(AudioSessionSetActive(true), "couldn't set audio session active\n");
}
// if there was a route change, we need to dispose the current rio unit and create a new one
XThrowIfError(AudioComponentInstanceDispose(THIS->rioUnit), "couldn't dispose remote i/o unit");
SetupRemoteIO(THIS->rioUnit, THIS->inputProc, THIS->thruFormat);

UInt32 size = sizeof(THIS->hwSampleRate);
XThrowIfError (AudioSessionGetProperty (kAudioSessionProperty_CurrentHardwareSampleRate, &size, &THIS- >hwSampleRate), "couldn't get new sample rate");

// UInt32 audioRouteOverride = kAudioSessionOverrideAudioRoute_Speaker; // 1
// XThrowIfError (AudioSessionSetProperty (kAudioSessionProperty_OverrideAudioRoute,sizeof (audioRouteOverride),&audioRouteOverride), "couldn't set audioRouteOverride");

XThrowIfError(AudioOutputUnitStart(THIS->rioUnit), "couldn't start unit");

// we need to rescale the sonogram view's color thresholds for different input
CFStringRef newRoute;
size = sizeof(CFStringRef);
XThrowIfError (AudioSessionGetProperty(kAudioSessionProperty_AudioRoute, &size, &newRoute), "couldn't get new audio route");
if (newRoute)
{
//NSLog(@"newRoute %@", newRoute);
if (CFStringCompare(newRoute, CFSTR("HeadsetInOut"), NULL) == kCFCompareEqualTo) // headset plugged in
{
THIS->inputType = kInputType_HeadsetInOut;
}
else if (CFStringCompare(newRoute, CFSTR("ReceiverAndMicrophone"), NULL) == kCFCompareEqualTo) // headset plugged in
{
THIS->inputType = kInputType_ReceiverAndMicrophone;
}
else if (CFStringCompare(newRoute, CFSTR("HeadphonesAndMicrophone"), NULL) == kCFCompareEqualTo) // headset plugged in
{
THIS->inputType = kInputType_HeadphonesAndMicrophone;
}
else if (CFStringCompare(newRoute, CFSTR("LineOut"), NULL) == kCFCompareEqualTo) // headset plugged in
{
THIS->inputType = kInputType_LineOut;
}
else
{

}
// CFRelease(newRoute);
}
}
catch (CAXException e) {
char buf[256];
fprintf(stderr, "Error: %s (%s)\n", e.mOperation, e.FormatError(buf));
}

}
AudioSessionGetProperty (kAudioSessionProperty_CurrentHardwareIOBufferDuration, &siz, &bufferSize);
printf("bufferSize %f\n",bufferSize);

}






On 25/02/2009, at 19.30, Greg Chapman wrote:

On Feb 25, 2009, at 4:08 AM, Mark's Studio wrote:

I set kAudioSessionProperty_PreferedHardwareIOBufferDuration to 0.005
and kAudioSessionProperty_CurrentHardwareIOBufferDuration returns 0.005805,
so that is fine


But if the iPod app is started the buffer duration change to 0.023220
and when restarting my audio (i do this by starting an AVAudioPlayer,so the iPod fades out) the buffer duration stay there,
if i trigger another restart by removing the headset it goes back
to the prefered duration.

This seems like a bug... if you have interrupted the iPod app, you should get all your hardware settings back (unless something else weird is going on, like a phone call or something).


Can you write a bug please? If possible, include source code we can build to reproduce the problem.

Is there anyway i can make sure i get the prefered duration ?

To try to work around the bug, you could try calling AudioSessionSetActive(true) again before restarting; that might get us to do the right thing. (I'm just guessing, though... I don't know yet what the bug is.)


Greg

Peter Mark

Mark's Recording Studio A/S
Lundeskovsvej 3
2900 Hellerup
Denmark
Tel: +45 35366078
Fax: +45 35366038
Mobile: +45 20416018
www.marks-studio.dk
email@hidden

_______________________________________________
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: Getting the PreferedHardwareIOBufferDuration
      • From: Greg Chapman <email@hidden>
References: 
 >Getting the PreferedHardwareIOBufferDuration (From: Mark's Studio <email@hidden>)
 >Re: Getting the PreferedHardwareIOBufferDuration (From: Greg Chapman <email@hidden>)

  • Prev by Date: Update on AURender Call back function
  • Next by Date: Re: AURender Call back function
  • Previous by thread: How to Auto-Start Generators in AULab
  • Next by thread: Re: Getting the PreferedHardwareIOBufferDuration
  • Index(es):
    • Date
    • Thread