Correct way to read int24 aiff/wav file?

Hey all,

I’m attempting to read a 24bit fixed point SDIR file (aiff, big endian) using an AudioFormatReader and my result is garbled. My question is that I’ve looked at the convertFixedToFloat function the reader is using and I’m not sure why that wouldn’t be sufficient - is my problem elsewhere? I’ve isolated the problem occurring in just the reading of the input file. Is this not the best method for reading an int into an AudioBuffer?

AudioFormatReader* reader = formatManager.createReaderFor (inputfile);
            
            //wav produced no errors
            if (reader != nullptr)
            {
                //correct channel count
                if (reader->numChannels == 22)
                {
                    reader->usesFloatingPointData = false;
                    
                    dataBuffer.setSize (reader->numChannels, (int)reader->lengthInSamples);
                    
                    bitDepth = reader->bitsPerSample;
                    sampleRate = reader->sampleRate;
                    
                    reader->read(dataBuffer.getArrayOfWritePointers(), dataBuffer.getNumChannels(), 0, dataBuffer.getNumSamples());
                   
                }
                
            }

edit: formatting

I believe you are not supposed to set usesFloatingPointData, it is read from the audio file header. If you set that, it might convert wrong.

Hey Daniel, thanks for the reply - the reason I was setting it is that it wasn’t converting from floating to fixed point and the output was not within the -1.0 to +1.0 range - like 6.xxx

Setting the flag converted from fixed to float but the output is distorted. No errors from the call to read either btw

Feel free to close this - my I/O was is on the fritz, function works like a charm - my bad. And @daniel, you were correct about the flag.