Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some issues with large files #3293

Merged
merged 3 commits into from
Feb 9, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 50 additions & 18 deletions src/core/SampleBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
*
*/


#include "SampleBuffer.h"


Expand Down Expand Up @@ -58,6 +57,7 @@
#include "DrumSynth.h"
#include "endian_handling.h"
#include "Engine.h"
#include "GuiApplication.h"
#include "interpolation.h"
#include "Mixer.h"
#include "templates.h"
Expand Down Expand Up @@ -173,6 +173,7 @@ void SampleBuffer::update( bool _keep_settings )
MM_FREE( m_data );
}

bool fileLoadError = false;
if( m_audioFile.isEmpty() && m_origData != NULL && m_origFrames > 0 )
{
// TODO: reverse- and amplification-property is not covered
Expand Down Expand Up @@ -203,12 +204,27 @@ void SampleBuffer::update( bool _keep_settings )
const QFileInfo fileInfo( file );
if( fileInfo.size() > 100*1024*1024 )
{
qWarning( "refusing to load sample files bigger "
"than 100 MB" );
fileLoadError = true;
}
else
{
SNDFILE * snd_file;
SF_INFO sf_info;
sf_info.format = 0;
if( ( snd_file = sf_open( f, SFM_READ, &sf_info ) ) != NULL )
{
f_cnt_t frames = sf_info.frames;
int rate = sf_info.samplerate;
if( frames / rate > 60 * 60 ) // 60 minutes
{
fileLoadError = true;
}
sf_close( snd_file );
}
}

if( !fileLoadError )
{
#ifdef LMMS_HAVE_OGGVORBIS
// workaround for a bug in libsndfile or our libsndfile decoder
// causing some OGG files to be distorted -> try with OGG Vorbis
Expand Down Expand Up @@ -237,22 +253,21 @@ void SampleBuffer::update( bool _keep_settings )
}

delete[] f;
}

if ( m_frames == 0 ) // if still no frames, bail
{
// sample couldn't be decoded, create buffer containing
// one sample-frame
m_data = MM_ALLOC( sampleFrame, 1 );
memset( m_data, 0, sizeof( *m_data ) );
m_frames = 1;
m_loopStartFrame = m_startFrame = 0;
m_loopEndFrame = m_endFrame = 1;
}
else // otherwise normalize sample rate
{
normalizeSampleRate( samplerate, _keep_settings );
}

if ( m_frames == 0 || fileLoadError ) // if still no frames, bail
{
// sample couldn't be decoded, create buffer containing
// one sample-frame
m_data = MM_ALLOC( sampleFrame, 1 );
memset( m_data, 0, sizeof( *m_data ) );
m_frames = 1;
m_loopStartFrame = m_startFrame = 0;
m_loopEndFrame = m_endFrame = 1;
}
else // otherwise normalize sample rate
{
normalizeSampleRate( samplerate, _keep_settings );
}
}
else
Expand All @@ -273,6 +288,23 @@ void SampleBuffer::update( bool _keep_settings )
}

emit sampleUpdated();

if( fileLoadError )
{
QString message = "Audio files are limited to 100 MB "
"in size and 1 hour of playing time";
if( gui )
{
QMessageBox::information( NULL,
"Fail to open file", message,
QMessageBox::Ok );
}
else
{
fprintf( stderr, "%s\n", message.toUtf8().constData() );
exit( EXIT_FAILURE );
PhysSong marked this conversation as resolved.
Show resolved Hide resolved
}
}
}


Expand Down