From 822a3c52bb58f2fd8f109353b387b02474c01bdd Mon Sep 17 00:00:00 2001 From: Garrett Date: Sun, 9 Nov 2014 21:06:48 -0800 Subject: [PATCH] Convert 24-bit data if on big endian system This is needed since libgig returns 24-bit data in a little endian. Note: untested as I don't have a big endian system. --- plugins/GigPlayer/GigPlayer.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/plugins/GigPlayer/GigPlayer.cpp b/plugins/GigPlayer/GigPlayer.cpp index 0c439464d..f678bf7bc 100644 --- a/plugins/GigPlayer/GigPlayer.cpp +++ b/plugins/GigPlayer/GigPlayer.cpp @@ -43,6 +43,7 @@ #include "knob.h" #include "song.h" #include "ConfigManager.h" +#include "endian_handling.h" #include "PatchesDialog.h" #include "tooltip.h" @@ -494,9 +495,12 @@ void GigInstrument::play( sampleFrame * _working_buffer ) for( int i = 0; i < samples; ++i ) { - int32_t valueLeft = ( pInt[ 3 * sample->sample->Channels * i ] << 8 ) | + // libgig gives 24-bit data as little endian, so we must + // convert if on a big endian system + int32_t valueLeft = swap32IfBE( + ( pInt[ 3 * sample->sample->Channels * i ] << 8 ) | ( pInt[ 3 * sample->sample->Channels * i + 1 ] << 16 ) | - ( pInt[ 3 * sample->sample->Channels * i + 2 ] << 24 ); + ( pInt[ 3 * sample->sample->Channels * i + 2 ] << 24 ) ); // Store the notes to this buffer before saving to output // so we can fade them out as needed @@ -508,9 +512,10 @@ void GigInstrument::play( sampleFrame * _working_buffer ) } else { - int32_t valueRight = ( pInt[ 3 * sample->sample->Channels * i + 3 ] << 8 ) | + int32_t valueRight = swap32IfBE( + ( pInt[ 3 * sample->sample->Channels * i + 3 ] << 8 ) | ( pInt[ 3 * sample->sample->Channels * i + 4 ] << 16 ) | - ( pInt[ 3 * sample->sample->Channels * i + 5 ] << 24 ); + ( pInt[ 3 * sample->sample->Channels * i + 5 ] << 24 ) ); sampleData[i][1] = 1.0 / 0x100000000 * sample->attenuation * valueRight; }