so i want to properly scale floats in the range of -1 to +1 into the format expected by an AUGraph with a stream format that is set up like this:
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 setup the graph, but when i cast a float like this:
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 is very quiet. So i'm doing the scaling wrong? Scaling by a bigger number messes up the signal. Doesn't sound like clipping, and the output volume does not get higher. I do not intend to deeply study fixed point math, all i need is a one-liner which casts into the proper format.
thank you!
edit: i had been using a different stream format before which i could not figure out how to use properly with a stereo signal. With this different setup, i have had no trouble with the output volume though, so i figure the gain problem must have to do with the scaling...