+ //std::cout << "Current physical stream format:" << std::endl;\r
+ //std::cout << " mBitsPerChan = " << description.mBitsPerChannel << std::endl;\r
+ //std::cout << " aligned high = " << (description.mFormatFlags & kAudioFormatFlagIsAlignedHigh) << ", isPacked = " << (description.mFormatFlags & kAudioFormatFlagIsPacked) << std::endl;\r
+ //std::cout << " bytesPerFrame = " << description.mBytesPerFrame << std::endl;\r
+ //std::cout << " sample rate = " << description.mSampleRate << std::endl;\r
+\r
+ if ( description.mFormatID != kAudioFormatLinearPCM || description.mBitsPerChannel < 16 ) {\r
+ description.mFormatID = kAudioFormatLinearPCM;\r
+ //description.mSampleRate = (Float64) sampleRate;\r
+ AudioStreamBasicDescription testDescription = description;\r
+ UInt32 formatFlags;\r
+\r
+ // We'll try higher bit rates first and then work our way down.\r
+ std::vector< std::pair<UInt32, UInt32> > physicalFormats;\r
+ formatFlags = description.mFormatFlags | kLinearPCMFormatFlagIsFloat & ~kLinearPCMFormatFlagIsSignedInteger;\r
+ physicalFormats.push_back( std::pair<Float32, UInt32>( 32, formatFlags ) );\r
+ formatFlags = (description.mFormatFlags | kLinearPCMFormatFlagIsSignedInteger | kAudioFormatFlagIsPacked) & ~kLinearPCMFormatFlagIsFloat;\r
+ physicalFormats.push_back( std::pair<Float32, UInt32>( 32, formatFlags ) );\r
+ physicalFormats.push_back( std::pair<Float32, UInt32>( 24, formatFlags ) ); // 24-bit packed\r
+ formatFlags &= ~( kAudioFormatFlagIsPacked | kAudioFormatFlagIsAlignedHigh );\r
+ physicalFormats.push_back( std::pair<Float32, UInt32>( 24.2, formatFlags ) ); // 24-bit in 4 bytes, aligned low\r
+ formatFlags |= kAudioFormatFlagIsAlignedHigh;\r
+ physicalFormats.push_back( std::pair<Float32, UInt32>( 24.4, formatFlags ) ); // 24-bit in 4 bytes, aligned high\r
+ formatFlags = (description.mFormatFlags | kLinearPCMFormatFlagIsSignedInteger | kAudioFormatFlagIsPacked) & ~kLinearPCMFormatFlagIsFloat;\r
+ physicalFormats.push_back( std::pair<Float32, UInt32>( 16, formatFlags ) );\r
+ physicalFormats.push_back( std::pair<Float32, UInt32>( 8, formatFlags ) );\r
+\r
+ bool setPhysicalFormat = false;\r
+ for( unsigned int i=0; i<physicalFormats.size(); i++ ) {\r