如何AudioObjectGetPropertyData在OS X中使用以检索系统输入设备的列表?我目前有以下用于检索全局设备列表的虚拟代码:
AudioDeviceID devices[12];
UInt32 arraySize = sizeof(devices);
AudioObjectPropertyAddress thePropertyAddress = { kAudioHardwarePropertyDevices,
kAudioObjectPropertyScopeGlobal,
kAudioObjectPropertyElementMaster };
AudioObjectGetPropertyData(kAudioObjectSystemObject,
&thePropertyAddress,
0,
NULL,
&arraySize,
&devices);
Run Code Online (Sandbox Code Playgroud) 我正在使用以下代码在 Mac 上测试录音
OSStatus error;
AudioDeviceID deviceID = 0;
AudioObjectPropertyAddress propertyAddress;
UInt32 propertySize;
propertyAddress.mSelector = kAudioHardwarePropertyDefaultInputDevice;
propertyAddress.mScope = kAudioObjectPropertyScopeGlobal;
propertyAddress.mElement = 0;
propertySize = sizeof(AudioDeviceID);
error = AudioHardwareServiceGetPropertyData(kAudioObjectSystemObject,
&propertyAddress,
0,
NULL,
&propertySize,
&deviceID);
if(error)
return error;
propertyAddress.mSelector = kAudioDevicePropertyNominalSampleRate;
propertyAddress.mScope = kAudioObjectPropertyScopeGlobal;
propertyAddress.mElement = 0;
propertySize = sizeof(Float64);
error = AudioHardwareServiceGetPropertyData(deviceID,
&propertyAddress,
0,
NULL,
&propertySize,
outSampleRate);
Run Code Online (Sandbox Code Playgroud)
但是 Xcode 告诉我 AudioHardwareService*** 从 OS X 10.11 被弃用。
我查看了 Apple 的 API 指南,但找不到这些 API 的替代品。
我知道它有效,但所有这些警告都很烦人。我该怎么办?
这是上一个问题的后续问题: OSX CoreAudio:提前获取 inNumberFrames - 初始化时?
我试图找出 AudioUnit API 可能用于设置inNumberFrames或OSX中单个HAL音频组件实例的输入回调的首选 IO 缓冲区持续时间(不是插件!)。虽然我知道有一个关于如何通过AVAudioSession API 在 iOS 中实现此目的的综合文档,但我既无法弄清楚也找不到有关在 OSX 中设置这些值的文档,无论是哪个 API。网络上充满了专家但相互矛盾的陈述,从“有一个音频单元 API 来请求采样率和首选缓冲持续时间...... ”,到“您绝对可以获得帧数,但仅限于当前的帧数”。回拨电话... ”。
对于 OSX 中输入选择的采样率,是否有一种方法至少可以获取(并适应)系统提供的inNumberFrames或音频缓冲区长度?例如,对于 44.1k 及其倍数(这似乎部分有效),以及 48k 及其倍数(这似乎根本不起作用,我不知道允许调整缓冲区的 hack 在哪里这些值的长度)?这是控制台打印输出:
Available 7 Sample Rates
Available Sample Rate value : 8000.000000
Available Sample Rate value : 16000.000000
Available Sample Rate value : 32000.000000
Available Sample Rate value : 44100.000000
Available Sample Rate value : …Run Code Online (Sandbox Code Playgroud) 我对limits.h中的CHAR_BIT感到困惑.我已经阅读了一些文章,说宏的CHAR_BIT是为了便携性.要在代码中使用宏而不是像8这样的幻数,这是合理的.但limits.h来自glibc-headers,它的值固定为8.如果glibc-headers安装在一个字节超过8位(比如16位)的系统上,编译时错误是什么?'char'被分配8位还是16位?
当我在limits.h中将CHAR_BIT修改为9时,下面的代码仍然打印'8',怎么样?
#include <stdio.h>
#include <limits.h>
int
main(int argc, char **argv)
{
printf("%d\n", CHAR_BIT);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
以下是补充:我已阅读所有回复,但仍不清楚.在实践中,#include <limits.h>并使用CHAR_BIT,我可以遵守.但那是另一回事.在这里,我想知道为什么它会出现这种情况,首先它是glibc /usr/include/limits.h中的固定值'8',当那些具有1字节!= 8位的系统与glibc一起安装时会发生什么; 然后我发现值'8'甚至不是代码使用的实际值,所以'8'表示什么都没有?如果没有使用该值,为什么要将'8'放在那里?
谢谢,
void printInstructions();
char *getUserWord();
int main()
{
printInstructions();
char *baseWord = getUserWord();
printf("%s", baseWord);
return 0;
}
void printInstructions()
{
printf(" Instructions: \n"
"===================================================================\n"
"= This program is a hangman game. =\n"
"= The first user will enter the name to be guessed =\n"
"= After that, the second user will guess the letters of the word =\n"
"= the second user will loose if they have three strikes =\n"
"===================================================================\n");
return;
}
char *getUserWord()
{
static char str[20];
scanf("%s", …Run Code Online (Sandbox Code Playgroud) 使用printf语句printf("new s3 string (in locate function) is \"%s\" \n",s3),代码可以正常工作
但是当printf("new s3 string (in locate function) is \"%s\" \n",s3)评论时,代码返回null
如何printf影响return价值?
#include <stdio.h>
#include <string.h>
char * locate(char * s1,char * s2,int index)
{
printf("s1 string is \"%s\" \n",s1);
printf("s2 string is \"%s\" \n",s2);
int i=0,j=0, k;
char s3[100];
while(i<=index)
{
s3[i]=s1[i];
i++;
}
k=i;
while(s2[j]!='\0')
{
s3[i]=s2[j];
i++; j++;
}
while(s1[k]!='\0')
{
s3[i]=s1[k];
i++;k++;
}
s3[i]='\0';
//printf("new s3 string (in locate function) …Run Code Online (Sandbox Code Playgroud)