Fix reading and writing of stereo files

main
coderkun 2017-03-26 17:11:34 +02:00 committed by Harry van Haaren
parent 6a6431242f
commit ed72627245
2 changed files with 20 additions and 11 deletions

View File

@ -165,9 +165,9 @@ int DiskReader::loadSample( int track, int scene, string path )
/// load the sample
SndfileHandle infile( path, SFM_READ );
int chnls = infile.channels();
std::vector<float> bufL( infile.frames() / chnls );
std::vector<float> bufR( infile.frames() / chnls );
std::vector<float> bufTmp( infile.frames() * (chnls-2) );
std::vector<float> bufL( infile.frames() );
std::vector<float> bufR( infile.frames() );
float frameBuf[ sizeof(float) * chnls ];
if ( infile.error() ) {
LUPPP_ERROR("File %s, Error %s", path.c_str(), infile.strError() );
@ -177,13 +177,20 @@ int DiskReader::loadSample( int track, int scene, string path )
LUPPP_NOTE("Loading file with %i chnls, frames %i, bufferL size %i bufferR size %i", infile.channels(), infile.frames(), bufL.size(), bufR.size() );
// Read data
for(int f=0; f<infile.frames()/chnls; f++) {
infile.read( (float*)&bufL[f] , 1 );
infile.read( (float*)&bufR[f] , 1 );
for(int f=0; f<infile.frames(); f++) {
infile.readf( frameBuf, 1 );
// Read (and ignore) remaining channels
for(int c=0; c<chnls-2; c++) {
infile.read( (float*)&bufTmp[f], 1);
// Frist sapmle
// used for both channels when file is mono
// used for left channel when file is stereo
if(chnls > 0) {
bufL[f] = frameBuf[0];
bufR[f] = frameBuf[0];
}
// Second sample
// used for right channel when file is stereo
if(chnls > 1) {
bufR[f] = frameBuf[1];
}
}

View File

@ -321,9 +321,11 @@ int DiskWriter::writeAudioBuffer(int track, int scene, AudioBuffer* ab,
// FIXME: the size of the buffer is bigger than the audio contained in it:
// calculate the length that needs saving using getBeats() * framesPerBeat
if ( ab->getAudioFrames() > 0 ) {
float frameBuf[ sizeof(float) * 2 ];
for(int i=0; i<ab->getAudioFrames(); i++) {
outfile.writef( &ab->getDataL()[i], 1); //sizeof(ab->getDataL()[i]));
outfile.writef( &ab->getDataR()[i], 1); //sizeof(ab->getDataR()[i]));
frameBuf[0] = ab->getDataL()[i];
frameBuf[1] = ab->getDataR()[i];
outfile.writef( frameBuf, 1);
}
}
else {