Skip to content

Commit

Permalink
SampleBuffer -> SoundFile: Support mono files, show a warning for
Browse files Browse the repository at this point in the history
channel > 2.
  • Loading branch information
Reflexe authored and lukas-w committed Jul 30, 2018
1 parent 89046dc commit c8337dc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
2 changes: 1 addition & 1 deletion include/SampleBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ public slots:

static DataVector convertIntToFloat(int_sample_t * & _ibuf, f_cnt_t _frames, int _channels);

static DataVector decodeSampleSF( QString _f, ch_cnt_t & _channels, sample_rate_t & _sample_rate);
static DataVector decodeSampleSF(QString _f, ch_cnt_t & _channels, sample_rate_t & _sample_rate, QString &loadingWarning);
#ifdef LMMS_HAVE_OGGVORBIS
static DataVector decodeSampleOGGVorbis( QString _f,
ch_cnt_t & _channels,
Expand Down
25 changes: 14 additions & 11 deletions src/core/SampleBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ void SampleBuffer::changeAudioFile(QString audioFile)
f.close();
}

QString loadingWarning;
if( !fileLoadError ) {

#ifdef LMMS_HAVE_OGGVORBIS
Expand All @@ -200,7 +201,7 @@ void SampleBuffer::changeAudioFile(QString audioFile)
#endif
if(fileData.empty ())
{
fileData = decodeSampleSF( file, channels, samplerate );
fileData = decodeSampleSF( file, channels, samplerate, loadingWarning );
}
#ifdef LMMS_HAVE_OGGVORBIS
if( fileData.empty () )
Expand All @@ -225,10 +226,12 @@ void SampleBuffer::changeAudioFile(QString audioFile)
QString message = tr( "Audio files are limited to %1 MB "
"in size and %2 minutes of playing time"
).arg( fileSizeMax ).arg( sampleLengthMax );
if (! loadingWarning.isEmpty())
message = loadingWarning;
if( gui )
{
QMessageBox::information( NULL,
title, message, QMessageBox::Ok );
title, message, QMessageBox::Warning );
}
else
{
Expand Down Expand Up @@ -300,7 +303,8 @@ SampleBuffer::resampleData (const DataVector &inputData, sample_rate_t inputSamp

SampleBuffer::DataVector SampleBuffer::decodeSampleSF( QString _f,
ch_cnt_t & _channels,
sample_rate_t &_samplerate)
sample_rate_t &_samplerate,
QString &loadingWarning)
{
SNDFILE * snd_file;
SF_INFO sf_info;
Expand All @@ -317,18 +321,16 @@ SampleBuffer::DataVector SampleBuffer::decodeSampleSF( QString _f,
{
frames = sf_info.frames;
vector.resize (frames);
sf_rr = sf_read_float( snd_file, vector.data ()->data (), DEFAULT_CHANNELS * frames );
sf_rr = sf_read_float( snd_file, vector.data ()->data (), min(DEFAULT_CHANNELS * frames, sf_info.channels * frames));

if (sf_info.channels != DEFAULT_CHANNELS) {
if (sf_info.channels == 1) {
#ifdef DEBUG_LMMS
qDebug( "SampleBuffer::decodeSampleSF(): Not a stereo file: %s: %s", _f, sf_strerror( NULL ) );
#endif

_channels = sf_info.channels;
_samplerate = sf_info.samplerate;

sf_close( snd_file );
return vector;
vector.resize(frames / 2);
} else if (sf_info.channels > DEFAULT_CHANNELS) {
loadingWarning = tr("The file you've selected has %1 channels. LMMS support "
"Stereo and Mono.").arg(sf_info.channels);
}

if( sf_rr < sf_info.channels * frames )
Expand All @@ -349,6 +351,7 @@ SampleBuffer::DataVector SampleBuffer::decodeSampleSF( QString _f,
qDebug( "SampleBuffer::decodeSampleSF(): could not load "
"sample %s: %s", _f, sf_strerror( NULL ) );
#endif
loadingWarning = tr("SoundFile: Could not load: %1").arg(sf_strerror( NULL ));
}
f.close();

Expand Down

0 comments on commit c8337dc

Please sign in to comment.