Is there a way to specify SInt32 instead of Float for ofSoundStream? I know how to deal with RemoteIO outside of OpenFrameworks, but I’d like to start using OpenFrameworks for all my projects and want to do things in the most portable way possible. I could just simply commit some code, but I must confess to being a bit shy… First I want to understand more about the platform and coding style.
This is how I usually initialize my RemoteIO unit :
// Format preferred by the iphone (Fixed 8.24)
outFormat.mSampleRate = 44100.0;
outFormat.mFormatID = kAudioFormatLinearPCM;
outFormat.mFormatFlags = kAudioFormatFlagIsSignedInteger | kAudioFormatFlagIsPacked;
outFormat.mBitsPerChannel = sizeof(AudioSampleType) * 8; // AudioSampleType == 16 bit signed ints
outFormat.mChannelsPerFrame = 1;
outFormat.mFramesPerPacket = 1;
outFormat.mBytesPerFrame = ( outFormat.mBitsPerChannel / 8 ) * outFormat.mChannelsPerFrame;
outFormat.mBytesPerPacket = outFormat.mBytesPerFrame * outFormat.mFramesPerPacket;
outFormat.mReserved = 0;
… and process like this :
- (OSStatus)generateSamples:(AudioBufferList*)ioData
{
for(UInt32 i = 0; i < ioData->mNumberBuffers; ++i)
{
SInt32 *outBuffer = (SInt32 *) (ioData->mBuffers[i].mData);
const int mDataByteSize = ioData->mBuffers[i].mDataByteSize;
numSamples = mDataByteSize / 4;
for(UInt32 z=0; z<numSamples; z++)
{
outBuffer[z] = (SInt16) (someBuffer[z] * 32767.0);
}
}
return noErr;
}
Some of you may recognize this method, known as the ‘Zig Zag’ method, found in H.264, all of Apple’s products, and many more I suspect. A good description can be found on Google’s Protocol Buffers page.
Basically this translates to more time for processing, simpler casting, tons of headroom, and a subtle phase shift that (subjectively) increases the presence of the sound upon projection into physical space–especially when dealing with smaller mobile device speakers. Anyways, you guys get the picture… Basically I’m just trying to feel out where I should jump in. Thanks in advance for any advice.
PS. The ofMath functions are some of the most beautifully written bits of code I have ever seen. AvantGarde, even. I felt like I was tripping while reading through them.