Jak*_*kob 4 fixed-point core-audio ios
所以我想正确地将-1到+1范围内的浮点数缩放为AUGraph所期望的格式,其格式设置如下:
size_t bytesPerSample = sizeof (AudioUnitSampleType); // is 4 bytes
stereoStreamFormat.mFormatID = kAudioFormatLinearPCM;
stereoStreamFormat.mFormatFlags = kAudioFormatFlagsAudioUnitCanonical;
stereoStreamFormat.mBytesPerPacket = bytesPerSample;
stereoStreamFormat.mFramesPerPacket = 1;
stereoStreamFormat.mBytesPerFrame = bytesPerSample;
stereoStreamFormat.mChannelsPerFrame = 2;
stereoStreamFormat.mBitsPerChannel = 8 * bytesPerSample;
stereoStreamFormat.mSampleRate = graphSampleRate; // 44.1k
Run Code Online (Sandbox Code Playgroud)
这个问题帮助我设置了图形,但是当我像这样抛出一个浮点数:
sampleValueLeft = (Fixed) (floatVal * 32767.0f);
// there doesn't seem to be any difference whether i cast into
// SInt16 or SInt32 (which the Fixed type is defined to be)..
Run Code Online (Sandbox Code Playgroud)
它工作,信号听起来不错,但非常安静.所以我做错了吗?通过更大的数字缩放会使信号变得混乱.听起来不像剪辑,输出量不会更高.我不打算深入研究定点数学,我所需要的只是一个单线程,它投入到正确的格式.
谢谢!
编辑:我一直在使用不同的流格式,之前我无法弄清楚如何正确使用立体声信号.有了这个不同的设置,我对输出音量没有任何问题,所以我认为增益问题必须与缩放...
阅读这篇文章,这是对iOS 8.24格式的一个非常好的解释.
以下是它的结论:
基本上它告诉你第一个(左)8位专用于(+/-)符号,其余24位是声音.
因此,如果您想将其转换为Sint16移位,则位9向右移动并进行转换.这样,(+/-)符号作为第一位保留,声音数据减少到较低的精度.
如果要将它作为(+/-)1到0范围内的浮点数,请将其除以最大可能值32768.
这是代码:
SInt16 sampleInt16 = (SInt16)(samples[i] >> 9);
float sampleFloat = sampleInt16 / 32768.0;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1839 次 |
| 最近记录: |