From ed726272456ad872d8e79e74737dfc27301d6c6e Mon Sep 17 00:00:00 2001 From: coderkun Date: Sun, 26 Mar 2017 17:11:34 +0200 Subject: [PATCH] Fix reading and writing of stereo files --- src/diskreader.cxx | 25 ++++++++++++++++--------- src/diskwriter.cxx | 6 ++++-- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/src/diskreader.cxx b/src/diskreader.cxx index ac324b4..c34f957 100644 --- a/src/diskreader.cxx +++ b/src/diskreader.cxx @@ -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 bufL( infile.frames() / chnls ); - std::vector bufR( infile.frames() / chnls ); - std::vector bufTmp( infile.frames() * (chnls-2) ); + std::vector bufL( infile.frames() ); + std::vector 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 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]; } } diff --git a/src/diskwriter.cxx b/src/diskwriter.cxx index 1d0bf27..e7d036f 100644 --- a/src/diskwriter.cxx +++ b/src/diskwriter.cxx @@ -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; igetAudioFrames(); 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 {