Re: Setting input frequency on Apple Built-in Digital Input
Re: Setting input frequency on Apple Built-in Digital Input
- Subject: Re: Setting input frequency on Apple Built-in Digital Input
- From: Jeff Moore <email@hidden>
- Date: Wed, 10 Dec 2008 14:03:19 -0800
I believe that the sample rate for the input SPDIF port is determined
by the sample rate of the incoming digital data stream. I don't
believe that it is something you can necessarily change.
In fact, what I see happen on my machine is that if I set the sample
rate of the input SPDIF port, it will stick for a few seconds. Then it
reverts back to 44100 when it can't lock onto a digital signal. In all
cases, I saw the appropriate notifications about the change, so there
isn't anything hidden going on.
On Dec 10, 2008, at 12:57 PM, Marshall Houskeeper wrote:
I am trying to set the input frequency of the Apple Built-in Digital
Input device. It appears to support multiple frequencies. I am
trying to set the frequency to one of the stated supported
frequencies. I am successful setting the input frequency with the
code below. However, when I get the
kAudioUnitProperty_StreamFormat property from the associated audio
unit the mSampleRate of the AudioStreamBasicDescription is the
original audio frequency.
I have been able to successfully set the input frequency with other
devices without any problem.
Any ideas?
Thank you for the help.
Marshall
//-------------------------------------------------------------------------------
//-------------------------------------------------------------------------------
//-------------------------------------------------------------------------------
OSStatus Low_Level_Audio_Record::Setup_Input_Frequency()
{
Float64 deck_frequency = Lookup_Sample_Rate(init_data.dp-
>audio_sample_freq);
Float64 new_frequency = 0;
Float64 current_frequency = 0;
Boolean has_deck_frequency = false;
AudioValueRange* input_frequency_list = NULL;
SInt32 input_frequency_count = 0;
OSStatus error;
UInt32 theSize = 0;
// get current input frequency
theSize = sizeof(current_frequency );
ABORT_ON_ERROR(error,AudioDeviceGetProperty(inputDevice, 0,
true,kAudioDevicePropertyNominalSampleRate, &theSize,
¤t_frequency ));
if ( current_frequency != deck_frequency )
{
// get frequencies supported by the device
theSize = 0;
ABORT_ON_ERROR(error, AudioDeviceGetPropertyInfo(inputDevice, 0,
true, kAudioDevicePropertyAvailableNominalSampleRates, &theSize,
NULL));
input_frequency_count = theSize / sizeof(AudioValueRange);
input_frequency_list = (AudioValueRange*)NewPtrClear(theSize);
ABORT_ON_ERROR(error,AudioDeviceGetProperty(inputDevice, 0, true,
kAudioDevicePropertyAvailableNominalSampleRates, &theSize,
input_frequency_list));
// See if it supports the deck's frequency
for (SInt32 i = 0; i < input_frequency_count && !
has_deck_frequency; i++)
{
if (input_frequency_list[i].mMinimum == deck_frequency )
has_deck_frequency = true;
}
if ( has_deck_frequency )
{
// set new frequency to the deck's frequency
theSize = sizeof(deck_frequency );
ABORT_ON_ERROR(error,AudioDeviceSetProperty(inputDevice, NULL,
0, true,kAudioDevicePropertyNominalSampleRate, theSize,
&deck_frequency ));
ABORT_ON_ERROR(error,AudioDeviceGetProperty(inputDevice, 0,
true,kAudioDevicePropertyNominalSampleRate, &theSize,
&new_frequency ));
if ( deck_frequency != new_frequency )
{
LL_NotifyStr("(deck_frequency != new_frequency )");
ABORT_ON_ERROR(error,AudioDeviceSetProperty(inputDevice,
NULL, 0, true,kAudioDevicePropertyNominalSampleRate, theSize,
¤t_frequency ));
}
}
}
abort:
if ( input_frequency_list )
DisposePtr((Ptr)input_frequency_list);
return error;
}
//-------------------------------------------------------------------------------
//-------------------------------------------------------------------------------
//-------------------------------------------------------------------------------
OSStatus
Low_Level_Audio_Record::Prepare(AudioStreamBasicDescription&
description)
{
OSStatus error = noErr;
Component comp;
ComponentDescription desc;
AURenderCallbackStruct input;
UInt32 enableIO;
UInt32 propSize;
samples_recieved = 0;
samples_given = 0;
jobs_recieved = 0;
Close_Audio_Unit();
desc.componentType = kAudioUnitType_Output;
desc.componentSubType = kAudioUnitSubType_HALOutput;
desc.componentManufacturer = kAudioUnitManufacturer_Apple;
desc.componentFlags = 0;
desc.componentFlagsMask = 0;
comp = FindNextComponent(NULL, &desc);
ABORT_IF_NULL(error,comp);
ABORT_ON_ERROR(error,OpenAComponent(comp, &audio_unit));
enableIO = 1;
ABORT_ON_ERROR(error,AudioUnitSetProperty(audio_unit,
kAudioOutputUnitProperty_EnableIO,
kAudioUnitScope_Input,
1, // Input bus
&enableIO,
sizeof(enableIO)));
enableIO = 0;
ABORT_ON_ERROR( error,AudioUnitSetProperty(audio_unit,
kAudioOutputUnitProperty_EnableIO,
kAudioUnitScope_Output,
0, // Output bus
&enableIO,
sizeof(enableIO)));
// select input device
if ( init_data.device_id )
inputDevice = init_data.device_id;
else
{
// Get system default
propSize = sizeof(AudioDeviceID);
ABORT_ON_ERROR
(error
,AudioHardwareGetProperty(kAudioHardwarePropertyDefaultInputDevice,
&propSize, &inputDevice));
}
Setup_Input_Frequency();
ABORT_ON_ERROR(error,AudioUnitSetProperty(audio_unit,
kAudioOutputUnitProperty_CurrentDevice, kAudioUnitScope_Global, 0,
&inputDevice, sizeof(inputDevice)));
// set render callback
input.inputProc = Recieve_Data_Runner;
input.inputProcRefCon = this;
ABORT_ON_ERROR(error,AudioUnitSetProperty(
audio_unit,
kAudioOutputUnitProperty_SetInputCallback,
kAudioUnitScope_Global,
0,
&input,
sizeof(input)));
ABORT_ON_ERROR(error,AudioUnitInitialize(audio_unit));
// get the hardware format
propSize = sizeof(audio_stream_description);
ABORT_ON_ERROR(error,AudioUnitGetProperty(audio_unit,
kAudioUnitProperty_StreamFormat, kAudioUnitScope_Input, 1,
&audio_stream_description, &propSize));
//!!!! Returns original input frequency for
audio_stream_description.mSampleRate
...
}
//-------------------------------------------------------------------------------
//-------------------------------------------------------------------------------
//-------------------------------------------------------------------------------
_______________________________________________
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
--
Jeff Moore
Core Audio
Apple
_______________________________________________
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