How to use native fixed-point type (8.24) to process iOS sound

so I want to scale the float correctly in the range of -1 to +1 in the format expected by AUGraph with a stream format that is configured as follows:

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 

this question helped me set up a chart, but when I do a float as follows:

 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).. 

it works, the signal sounds good, but very quiet. So what am I doing scaling wrong? Scaling more will interfere with the signal. Not like clipping, but the output volume does not increase. I do not intend to study mathematics with fixed points in depth, all I need is a single-line insert that fits in the correct format.

Thank you!

edit: I used a different stream format before which I could not figure out how to use the stereo signal correctly. With this other setting, I had no problems with the output volume, so I believe that the gain problem should be related to scaling ...

+4
source share
2 answers

I hate 8.24 because I don’t think there are convenient functions to do the math with it.

Counter proposal: put the converter block (AUConverter) at the beginning of the chart and set the ASBD input to you more convenient, for example, 16-bit ints or any other (I always use ints on iOS .. floating can work in the converter, but I won’t count on it ) Do not set the output of the ASBD converter; it will use the canonical sound block (8.24) by default. In fact, see if you can install a convenient ASBD on your first device without using AUConverter.

+3
source

Read this post , this is a really good explanation in iOS 8.24 format.

Here is his conclusion:
Basically this tells you that the first (left) 8 bits are only for the sign (+/-), the remaining 24 bits are sound.
Therefore, if you want to convert it to a Sint16 shift, bit 9 is put to the right and discarded. Thus, the sign (+/-) is stored as the first bit, and the audio data is reduced to less accuracy.
If you want it to be like a float in the range (+/-) from 1 to 0, divide it by the maximum possible value equal to 32768.

Here is the code:

  SInt16 sampleInt16 = (SInt16)(samples[i] >> 9); float sampleFloat = sampleInt16 / 32768.0; 
+4
source

All Articles