• 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
How to avoid overhead of 30% CPU usage
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

How to avoid overhead of 30% CPU usage


  • Subject: How to avoid overhead of 30% CPU usage
  • From: Jack Schmidt <email@hidden>
  • Date: Mon, 6 Apr 2009 17:49:06 -0400
  • Resent-date: Mon, 6 Apr 2009 17:51:09 -0400
  • Resent-from: Jack Schmidt <email@hidden>
  • Resent-message-id: <email@hidden>
  • Resent-to: email@hidden

I am writing a small program that needs to do some fairly trivially tasks with data from the microphone and send some easily generated data to the speakers. The tasks are easily adapted to any sampling rate and sample data type; imagine monitoring the volume and generating white noise or a metronome. It should be able to run while larger programs are using 100% cpu.

I ran into the problem however that once I call AudioDeviceStart or AudioOutputUnitStart, CPU usage goes to 30% on a 2.4GHz MacBook, which is about 300 times higher than I would expect based on similar programs on other architectures.

Is this expected behavior?


My first attempts used PortAudio, but the overhead was too high. Then I switched to the AudioUnit framework for output and CoreAudio/ AudioHardware.h for input. Then I switched to CoreAudio/ AudioHardware.h for both input and output. I tried adjusting the sampling rate, the sampling buffer sizes, the kAudioDevicePropertyIOCycleUsage, etc. I just have my callbacks return immediately. However, the overhead remains.



Is there a lower level accessible from user space at least for reading microphone input? I don't mind using the IOAudioStream struct's specification of its sample rate and type. In particular I don't need the AppleHDADriver to convert from SInt16 to Float32, but I have a hard time imagining how that conversion could use so much CPU.



Here is a minimal example to see the overhead:

#include <unistd.h>
#include <CoreAudio/CoreAudio.h>

static OSStatus ioproc( AudioDeviceID inDevice, const AudioTimeStamp *inNow, const AudioBufferList *inInputData, const AudioTimeStamp *inInputTime, AudioBufferList *outOutputData, const AudioTimeStamp *inOutputTime, void *inClientData) { return noErr; }

int main(int argc, char*argv[]) {
AudioDeviceIOProcID ioprocid1,ioprocid2;
AudioDeviceID mic,spk;
UInt32 size;
size = sizeof(AudioDeviceID);
AudioHardwareGetProperty( kAudioHardwarePropertyDefaultInputDevice, &size, &mic);
AudioHardwareGetProperty( kAudioHardwarePropertyDefaultOutputDevice, &size, &spk);
AudioDeviceCreateIOProcID(mic, ioproc, NULL, &ioprocid1);
AudioDeviceCreateIOProcID(spk, ioproc, NULL, &ioprocid2);
AudioDeviceStart(mic, ioprocid1);
AudioDeviceStart(spk, ioprocid2);
sleep(300);
}


_______________________________________________
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: How to avoid overhead of 30% CPU usage
      • From: Jens Alfke <email@hidden>
  • Prev by Date: Re: auval and version
  • Next by Date: Re: How to avoid overhead of 30% CPU usage
  • Previous by thread: Re: ultra low latency AD interface for visualization purposes
  • Next by thread: Re: How to avoid overhead of 30% CPU usage
  • Index(es):
    • Date
    • Thread