• 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: Question about setting sampling rate of sound input
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Question about setting sampling rate of sound input


  • Subject: Re: Question about setting sampling rate of sound input
  • From: Jeff Moore <email@hidden>
  • Date: Fri, 24 Oct 2003 11:56:07 -0700

In the new sample code installed with the Panther Developer Tools we added a few new C++ wrapper classes for doing stuff with the HAL. Plus, there a new tool called HALLab (found in /Developer/Examples/CoreAudio/HAL/HALLab) that shows these classes in action inside of a Cocoa app that provides a GUI for a lot of the HAL's API.

Here's how you get and set the available sample rate ranges (taken from /Developer/Examples/CoreAudio/PublicUtility/CAAudioHardwareDevice.*):

Float64 CAAudioHardwareDevice::GetNominalSampleRate() const
{
Float64 theAnswer = 0;
UInt32 theSize = sizeof(Float64);
GetPropertyData(0, kAudioDeviceSectionGlobal, kAudioDevicePropertyNominalSampleRate, theSize, &theAnswer);
return theAnswer;
}

void CAAudioHardwareDevice::SetNominalSampleRate(Float64 inSampleRate)
{
UInt32 theSize = sizeof(Float64);
SetPropertyData(0, kAudioDeviceSectionGlobal, kAudioDevicePropertyNominalSampleRate, theSize, &inSampleRate);
}

UInt32 CAAudioHardwareDevice::GetNumberNominalSampleRateRanges() const
{
UInt32 theSize = GetPropertyDataSize(0, kAudioDeviceSectionGlobal, kAudioDevicePropertyAvailableNominalSampleRates);
return theSize / sizeof(AudioValueRange);
}

void GetNominalSampleRateRanges(UInt32& ioNumberRanges, AudioValueRange* outRanges) const
{
UInt32 theSize = ioNumberRanges * sizeof(AudioValueRange);
GetPropertyData(0, kAudioDeviceSectionGlobal, kAudioDevicePropertyAvailableNominalSampleRates, theSize, outRanges);
ioNumberRanges = theSize / sizeof(AudioValueRange);
}

UInt32 CAAudioHardwareDevice::GetPropertyDataSize(UInt32 inChannel, CAAudioHardwareDeviceSectionID inSection, AudioHardwarePropertyID inPropertyID) const
{
UInt32 theSize = 0;
OSStatus theError = AudioDeviceGetPropertyInfo(mAudioDeviceID, inChannel, inSection, inPropertyID, &theSize, NULL);
ThrowIfError(theError, CAException(theError), "CAAudioHardwareDevice::GetPropertyDataSize: got an error getting info about a property");
return theSize;
}

void CAAudioHardwareDevice::GetPropertyData(UInt32 inChannel, CAAudioHardwareDeviceSectionID inSection, AudioHardwarePropertyID inPropertyID, UInt32& ioDataSize, void* outData) const
{
OSStatus theError = AudioDeviceGetProperty(mAudioDeviceID, inChannel, inSection, inPropertyID, &ioDataSize, outData);
ThrowIfError(theError, CAException(theError), "CAAudioHardwareDevice::GetPropertyData: got an error getting the value of a property");
}

void CAAudioHardwareDevice::SetPropertyData(UInt32 inChannel, CAAudioHardwareDeviceSectionID inSection, AudioHardwarePropertyID inPropertyID, UInt32 inDataSize, const void* inData, const AudioTimeStamp* inWhen)
{
OSStatus theError = AudioDeviceSetProperty(mAudioDeviceID, inWhen, inChannel, inSection, inPropertyID, inDataSize, inData);
ThrowIfError(theError, CAException(theError), "CAAudioHardwareDevice::SetPropertyData: got an error setting the value of a property");
}


On Oct 23, 2003, at 10:07 PM, Michael Bonnice wrote:

My application listens to the default input device (either line in or
internal microphone) and does an FFT on it to know the frequency
content. It works but lacks resolution at low frequencies. I've
just been learning CoreAudio so there are some things that are not
clear to me yet.

I want to change the sampling rate from within my code. Somehow there
must be some sort of function call that does this. However, the
AudioDeviceSetProperty routine doesn't have a selector to set the
sample rate of the input device. The AudioUnits section of the
documentation says I can set the sample rate, but I can't find a
Component Manager selector for the default input device so I don't have
a way to use AudioUnitSetProperty.

I've tried asking the device to match to a format that has a lower
sampling rate (10000), but it picks 44100. It only has one format
(44100) when I use this:

count = sizeof(indevice);
err =
AudioHardwareGetProperty(kAudioHardwarePropertyDefaultInputDevice,
&count, (void *) &indevice);
err = AudioDeviceGetPropertyInfo ( indevice, 0, true,

kAudioDevicePropertyStreamFormats, &count, NULL );
numDescriptions = count / sizeof(AudioStreamBasicDescription);
fprintf (stderr, "found %ld formats\n", numDescriptions );

I know I have seen other programs do this because they have an
interface where you pick 44100 or 22000 or whatever. How do I do this
in software?

Mike

--

Jeff Moore
Core Audio
Apple
_______________________________________________
coreaudio-api mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/coreaudio-api
Do not post admin requests to the list. They will be ignored.

References: 
 >Question about setting sampling rate of sound input (From: Michael Bonnice <email@hidden>)

  • Prev by Date: CD audio playback question
  • Next by Date: [OT] CD Spin Doctor 2
  • Previous by thread: Question about setting sampling rate of sound input
  • Next by thread: Re: Question about setting sampling rate of sound input
  • Index(es):
    • Date
    • Thread