我目前正在查看 PortAudio 代码示例,尤其是 paex_record.c一个。
在看起来过时的预处理器指令中,有一个 typedef PaSampleType
,它采用 portaudio.h
中定义的 PaSampleFormat
值/p>
我知道采样率是什么,但我不知道采样格式是什么。
在头文件中,定义为
/** The sample format of the buffer provided to the stream callback,
a_ReadStream() or Pa_WriteStream(). It may be any of the formats described
by the PaSampleFormat enumeration.
*/
但这并没有让我更清楚。
如果有人能阐明这个概念以及它如何应用于我的案例,我将不胜感激。
谢谢,
最佳答案
来自 portaudio.h:
typedef unsigned long PaSampleFormat;
#define paFloat32 ((PaSampleFormat) 0x00000001)
#define paInt32 ((PaSampleFormat) 0x00000002)
#define paInt24 ((PaSampleFormat) 0x00000004)
#define paInt16 ((PaSampleFormat) 0x00000008)
#define paInt8 ((PaSampleFormat) 0x00000010)
#define paUInt8 ((PaSampleFormat) 0x00000020)
#define paCustomFormat ((PaSampleFormat) 0x00010000)
#define paNonInterleaved ((PaSampleFormat) 0x80000000)
看起来 portaudio 库使用 PaSampleFormat 作为代表不同样本格式的位域。所以如果你想使用交错的 float ,你会这样做:
PaSampleFormat myFormat = paFloat32;
或者,如果您想使用非交错签名短裤,您可以这样做:
PaSampleFormat myFormat = paInt16 | paNonInterleaved;
然后,该库有许多函数将 PaSampleFormat 作为参数,以便这些函数知道如何在内部处理样本。这是使用此位域获取样本大小的库的另一个摘录。
PaError Pa_GetSampleSize( PaSampleFormat format )
{
int result;
PA_LOGAPI_ENTER_PARAMS( "Pa_GetSampleSize" );
PA_LOGAPI(("\tPaSampleFormat format: %d\n", format ));
switch( format & ~paNonInterleaved )
{
case paUInt8:
case paInt8:
result = 1;
break;
case paInt16:
result = 2;
break;
case paInt24:
result = 3;
break;
case paFloat32:
case paInt32:
result = 4;
break;
default:
result = paSampleFormatNotSupported;
break;
}
PA_LOGAPI_EXIT_PAERROR_OR_T_RESULT( "Pa_GetSampleSize", "int: %d", result );
return (PaError) result;
}
关于c++ - 什么是样本格式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47961954/