Changeset 1369

Show
Ignore:
Timestamp:
04/26/08 15:17:30 (7 months ago)
Author:
stephen_booth
Message:

Correct 24-bit audio handling for PPC.
Fixes #6.

Location:
trunk
Files:
12 modified

Legend:

Unmodified
Added
Removed
  • trunk/Decoders/FLACDecoder.m

    r1366 r1369  
    3535writeCallback(const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data) 
    3636{ 
    37         FLACDecoder             *source                                 = (FLACDecoder *)client_data; 
    38  
    39         unsigned                        spaceRequired                   = 0; 
    40          
     37        FLACDecoder                     *source                                 = (FLACDecoder *)client_data; 
     38 
    4139        int8_t                          *alias8                                 = NULL; 
    4240        int16_t                         *alias16                                = NULL; 
     
    4745                 
    4846        // Calculate the number of audio data points contained in the frame (should be one for each channel) 
    49         spaceRequired = frame->header.blocksize * frame->header.channels * (frame->header.bits_per_sample / 8); 
     47        unsigned spaceRequired = frame->header.blocksize * frame->header.channels * (frame->header.bits_per_sample / 8); 
    5048 
    5149        // Increase buffer size as required 
     
    8987                        for(sample = 0; sample < frame->header.blocksize; ++sample) { 
    9088                                for(channel = 0; channel < frame->header.channels; ++channel) { 
    91                                         audioSample     = OSSwapHostToBigInt32(buffer[channel][sample]); 
    92                                         // Skip the lowest byte 
     89                                        audioSample     = buffer[channel][sample]; 
     90                                         
     91                                        // Skip the highest byte 
     92                                        *alias8++       = (int8_t)((audioSample & 0x00ff0000) >> 16); 
    9393                                        *alias8++       = (int8_t)((audioSample & 0x0000ff00) >> 8); 
    94                                         *alias8++       = (int8_t)((audioSample & 0x00ff0000) >> 16); 
    95                                         *alias8++       = (int8_t)((audioSample & 0xff000000) >> 24); 
     94                                        *alias8++       = (int8_t)((audioSample & 0x000000ff) /*>> 0*/);                                         
    9695                                } 
    9796                        } 
  • trunk/Decoders/LibsndfileDecoder.m

    r1366 r1369  
    166166                                        alias8 = [buffer exposeBufferForWriting]; 
    167167                                        for(sample = 0; sample < frameCount * [self pcmFormat].mChannelsPerFrame; ++sample) { 
    168                                                 audioSample     = OSSwapHostToBigInt32(doubleBuffer[sample] * (1 << 23)); 
    169                                                 // Skip the lowest byte 
     168                                                audioSample     = doubleBuffer[sample] * (1 << 23); 
     169                                                 
     170                                                // Skip the highest byte 
     171                                                *alias8++       = (int8_t)((audioSample & 0x00ff0000) >> 16); 
    170172                                                *alias8++       = (int8_t)((audioSample & 0x0000ff00) >> 8); 
    171                                                 *alias8++       = (int8_t)((audioSample & 0x00ff0000) >> 16); 
    172                                                 *alias8++       = (int8_t)((audioSample & 0xff000000) >> 24); 
     173                                                *alias8++       = (int8_t)((audioSample & 0x000000ff) /*>> 0*/);                                         
    173174                                        } 
    174175                                                 
  • trunk/Decoders/MusepackDecoder.m

    r1339 r1369  
    143143                                        audioSample             = mpcBuffer[sample] * (1 << 23); 
    144144                                        audioSample             = (audioSample < clipMin ? clipMin : (audioSample > clipMax ? clipMax : audioSample)); 
    145 #if __BIG_ENDIAN__ 
    146                                         *alias8++               = (int8_t)(audioSample >> 16); 
    147                                         *alias8++               = (int8_t)(audioSample >> 8); 
    148                                         *alias8++               = (int8_t)audioSample; 
    149 #else 
    150                                         *alias8++               = (int8_t)audioSample; 
    151                                         *alias8++               = (int8_t)(audioSample >> 8); 
    152                                         *alias8++               = (int8_t)(audioSample >> 16); 
    153 #endif 
     145 
     146                                        // Skip the highest byte 
     147                                        *alias8++       = (int8_t)((audioSample & 0x00ff0000) >> 16); 
     148                                        *alias8++       = (int8_t)((audioSample & 0x0000ff00) >> 8); 
     149                                        *alias8++       = (int8_t)((audioSample & 0x000000ff) /*>> 0*/);                                         
    154150                                } 
    155151                                         
  • trunk/Decoders/OggFLACDecoder.m

    r1366 r1369  
    8989                        for(sample = 0; sample < frame->header.blocksize; ++sample) { 
    9090                                for(channel = 0; channel < frame->header.channels; ++channel) { 
    91                                         audioSample     = OSSwapHostToBigInt32(buffer[channel][sample]); 
    92                                         // Skip the lowest byte 
     91                                        audioSample     = buffer[channel][sample]; 
     92                                         
     93                                        // Skip the highest byte 
     94                                        *alias8++       = (int8_t)((audioSample & 0x00ff0000) >> 16); 
    9395                                        *alias8++       = (int8_t)((audioSample & 0x0000ff00) >> 8); 
    94                                         *alias8++       = (int8_t)((audioSample & 0x00ff0000) >> 16); 
    95                                         *alias8++       = (int8_t)((audioSample & 0xff000000) >> 24); 
     96                                        *alias8++       = (int8_t)((audioSample & 0x000000ff) /*>> 0*/);                                         
    9697                                } 
    9798                        } 
  • trunk/Decoders/WavPackDecoder.m

    r1366 r1369  
    122122                                alias8 = [buffer exposeBufferForWriting]; 
    123123                                for(sample = 0; sample < samplesRead * [self pcmFormat].mChannelsPerFrame; ++sample) { 
    124                                         audioSample     = OSSwapHostToBigInt32(inputBuffer[sample]); 
    125                                         // Skip the lowest byte 
     124                                        audioSample     = inputBuffer[sample]; 
     125                                         
     126                                        // Skip the highest byte 
     127                                        *alias8++       = (int8_t)((audioSample & 0x00ff0000) >> 16); 
    126128                                        *alias8++       = (int8_t)((audioSample & 0x0000ff00) >> 8); 
    127                                         *alias8++       = (int8_t)((audioSample & 0x00ff0000) >> 16); 
    128                                         *alias8++       = (int8_t)((audioSample & 0xff000000) >> 24); 
     129                                        *alias8++       = (int8_t)((audioSample & 0x000000ff) /*>> 0*/);                                         
    129130                                } 
    130131                                         
  • trunk/Encoders/FLACEncoder.m

    r1366 r1369  
    383383                                buffer8 = chunk->mBuffers[0].mData; 
    384384                                for(wideSample = sample = 0; wideSample < frameCount; ++wideSample) { 
    385                                         for(channel = 0; channel < chunk->mBuffers[0].mNumberChannels; ++channel, ++sample) { 
    386                                                 // Read three bytes and reconstruct them as a 32-bit BE integer 
    387                                                 constructedSample = (((int32_t)buffer8[sample] << 8) & 0x0000ff00) | (((int32_t)buffer8[++sample] << 16) & 0x00ff0000) | (((int32_t)buffer8[++sample] << 24) & 0xff000000); 
    388                                                 constructedSample = OSSwapBigToHostInt32(constructedSample); 
    389  
     385                                        for(channel = 0; channel < chunk->mBuffers[0].mNumberChannels; ++channel) { 
     386                                                constructedSample = (int8_t)*buffer8++; constructedSample <<= 8; 
     387                                                constructedSample |= (uint8_t)*buffer8++; constructedSample <<= 8; 
     388                                                constructedSample |= (uint8_t)*buffer8++; 
     389                                                 
    390390                                                buffer[channel][wideSample] = constructedSample; 
    391391                                        } 
  • trunk/Encoders/LibsndfileEncoder.m

    r1366 r1369  
    175175                                        buffer8 = bufferList.mBuffers[0].mData; 
    176176                                        for(wideSample = sample = 0; wideSample < frameCount; ++wideSample) { 
    177                                                 for(channel = 0; channel < bufferList.mBuffers[0].mNumberChannels; ++channel, ++sample) { 
    178                                                         // Read three bytes and reconstruct them as a 32-bit BE integer 
    179                                                         constructedSample = (((int32_t)buffer8[sample] << 8) & 0x0000ff00) | (((int32_t)buffer8[++sample] << 16) & 0x00ff0000) | (((int32_t)buffer8[++sample] << 24) & 0xff000000); 
    180                                                         constructedSample = OSSwapBigToHostInt32(constructedSample); 
     177                                                for(channel = 0; channel < bufferList.mBuffers[0].mNumberChannels; ++channel) { 
     178                                                        constructedSample = (int8_t)*buffer8++; constructedSample <<= 8; 
     179                                                        constructedSample |= (uint8_t)*buffer8++; constructedSample <<= 8; 
     180                                                        constructedSample |= (uint8_t)*buffer8++; 
    181181                                                         
    182                                                         buf[(bufferList.mBuffers[0].mNumberChannels * wideSample) + channel] = ((constructedSample << 8) | constructedSample); 
     182                                                        buf[(bufferList.mBuffers[0].mNumberChannels * wideSample) + channel] = constructedSample << 8; 
    183183                                                } 
    184184                                        } 
  • trunk/Encoders/MP3Encoder.m

    r1366 r1369  
    418418                                buffer8 = chunk->mBuffers[0].mData; 
    419419                                for(wideSample = sample = 0; wideSample < frameCount; ++wideSample) { 
    420                                         for(channel = 0; channel < chunk->mBuffers[0].mNumberChannels; ++channel, ++sample) { 
     420                                        for(channel = 0; channel < chunk->mBuffers[0].mNumberChannels; ++channel) { 
    421421                                                // Read three bytes and reconstruct them as a 32-bit BE integer 
    422                                                 constructedSample = (((int32_t)buffer8[sample] << 8) & 0x0000ff00) | (((int32_t)buffer8[++sample] << 16) & 0x00ff0000) | (((int32_t)buffer8[++sample] << 24) & 0xff000000); 
    423                                                 constructedSample = OSSwapBigToHostInt32(constructedSample); 
    424                                                  
     422                                                constructedSample = (int8_t)*buffer8++; constructedSample <<= 8; 
     423                                                constructedSample |= (uint8_t)*buffer8++; constructedSample <<= 8; 
     424                                                constructedSample |= (uint8_t)*buffer8++; 
     425                                                                                                 
    425426                                                // Convert to 32-bit sample scaling 
    426427                                                channelBuffers32[channel][wideSample] = (long)((constructedSample << 8) | (constructedSample & 0x000000ff)); 
  • trunk/Encoders/OggFLACEncoder.m

    r1366 r1369  
    343343                                buffer8 = chunk->mBuffers[0].mData; 
    344344                                for(wideSample = sample = 0; wideSample < frameCount; ++wideSample) { 
    345                                         for(channel = 0; channel < chunk->mBuffers[0].mNumberChannels; ++channel, ++sample) {                                            
    346                                                 // Read three bytes and reconstruct them as a 32-bit BE integer 
    347                                                 constructedSample = (((int32_t)buffer8[sample] << 8) & 0x0000ff00) | (((int32_t)buffer8[++sample] << 16) & 0x00ff0000) | (((int32_t)buffer8[++sample] << 24) & 0xff000000); 
    348                                                 constructedSample = OSSwapBigToHostInt32(constructedSample); 
     345                                        for(channel = 0; channel < chunk->mBuffers[0].mNumberChannels; ++channel) {                                              
     346                                                constructedSample = (int8_t)*buffer8++; constructedSample <<= 8; 
     347                                                constructedSample |= (uint8_t)*buffer8++; constructedSample <<= 8; 
     348                                                constructedSample |= (uint8_t)*buffer8++; 
    349349                                                 
    350350                                                buffer[channel][wideSample] = constructedSample; 
  • trunk/Encoders/OggSpeexEncoder.m

    r1366 r1369  
    423423                                        buffer8 = bufferList.mBuffers[0].mData; 
    424424                                        for(wideSample = sample = 0; wideSample < frameCount && sample < bufferList.mBuffers[0].mDataByteSize; ++wideSample, ++sample) { 
    425                                                 // Read three bytes and reconstruct them as a 32-bit BE integer 
    426                                                 constructedSample = (((int32_t)buffer8[sample] << 8) & 0x0000ff00) | (((int32_t)buffer8[++sample] << 16) & 0x00ff0000) | (((int32_t)buffer8[++sample] << 24) & 0xff000000); 
    427                                                 constructedSample = OSSwapBigToHostInt32(constructedSample); 
     425                                                constructedSample = (int8_t)*buffer8++; constructedSample <<= 8; 
     426                                                constructedSample |= (uint8_t)*buffer8++; constructedSample <<= 8; 
     427                                                constructedSample |= (uint8_t)*buffer8++; 
    428428                                                 
    429429                                                floatBuffer[wideSample] = (constructedSample / 8388608.); 
  • trunk/Encoders/OggVorbisEncoder.m

    r1366 r1369  
    233233                                        buffer8 = bufferList.mBuffers[0].mData; 
    234234                                        for(wideSample = sample = 0; wideSample < frameCount; ++wideSample) { 
    235                                                 for(channel = 0; channel < bufferList.mBuffers[0].mNumberChannels; ++channel, ++sample) { 
    236                                                         // Read three bytes and reconstruct them as a 32-bit BE integer 
    237                                                         constructedSample = (((int32_t)buffer8[sample] << 8) & 0x0000ff00) | (((int32_t)buffer8[++sample] << 16) & 0x00ff0000) | (((int32_t)buffer8[++sample] << 24) & 0xff000000); 
    238                                                         constructedSample = OSSwapBigToHostInt32(constructedSample); 
     235                                                for(channel = 0; channel < bufferList.mBuffers[0].mNumberChannels; ++channel) { 
     236                                                        constructedSample = (int8_t)*buffer8++; constructedSample <<= 8; 
     237                                                        constructedSample |= (uint8_t)*buffer8++; constructedSample <<= 8; 
     238                                                        constructedSample |= (uint8_t)*buffer8++; 
    239239                                                         
    240240                                                        buffer[channel][wideSample] = (constructedSample / 8388608.); 
  • trunk/Encoders/WavPackEncoder.m

    r1366 r1369  
    221221                                        for(wideSample = sample = 0; wideSample < frameCount; ++wideSample) { 
    222222                                                for(channel = 0; channel < bufferList.mBuffers[0].mNumberChannels; ++channel, ++sample) { 
    223                                                         // Read three bytes and reconstruct them as a 32-bit BE integer 
    224                                                         constructedSample = (((int32_t)buffer8[sample] << 8) & 0x0000ff00) | (((int32_t)buffer8[++sample] << 16) & 0x00ff0000) | (((int32_t)buffer8[++sample] << 24) & 0xff000000); 
    225                                                         constructedSample = OSSwapBigToHostInt32(constructedSample); 
     223                                                        constructedSample = (int8_t)*buffer8++; constructedSample <<= 8; 
     224                                                        constructedSample |= (uint8_t)*buffer8++; constructedSample <<= 8; 
     225                                                        constructedSample |= (uint8_t)*buffer8++; 
    226226                                                         
    227227                                                        wpBuf[(bufferList.mBuffers[0].mNumberChannels * wideSample) + channel] = constructedSample;