@@ -187,11 +187,6 @@ void SampleBuffer::update( bool _keep_settings )
187187 else if ( !m_audioFile.isEmpty () )
188188 {
189189 QString file = tryToMakeAbsolute ( m_audioFile );
190- #ifdef LMMS_BUILD_WIN32
191- char * f = qstrdup ( file.toLocal8Bit ().constData () );
192- #else
193- char * f = qstrdup ( file.toUtf8 ().constData () );
194- #endif
195190 int_sample_t * buf = NULL ;
196191 sample_t * fbuf = NULL ;
197192 ch_cnt_t channels = DEFAULT_CHANNELS ;
@@ -205,10 +200,13 @@ void SampleBuffer::update( bool _keep_settings )
205200 }
206201 else
207202 {
203+ // Use QFile to handle unicode file names on Windows
204+ QFile f (file);
205+ f.open (QIODevice::ReadOnly);
208206 SNDFILE * snd_file;
209207 SF_INFO sf_info;
210208 sf_info.format = 0 ;
211- if ( ( snd_file = sf_open ( f, SFM_READ , &sf_info ) ) != NULL )
209+ if ( ( snd_file = sf_open_fd ( f. handle () , SFM_READ , &sf_info, false ) ) != NULL )
212210 {
213211 f_cnt_t frames = sf_info.frames ;
214212 int rate = sf_info.samplerate ;
@@ -218,6 +216,7 @@ void SampleBuffer::update( bool _keep_settings )
218216 }
219217 sf_close ( snd_file );
220218 }
219+ f.close ();
221220 }
222221
223222 if ( !fileLoadError )
@@ -228,28 +227,26 @@ void SampleBuffer::update( bool _keep_settings )
228227 // decoder first if filename extension matches "ogg"
229228 if ( m_frames == 0 && fileInfo.suffix () == " ogg" )
230229 {
231- m_frames = decodeSampleOGGVorbis ( f , buf, channels, samplerate );
230+ m_frames = decodeSampleOGGVorbis ( file , buf, channels, samplerate );
232231 }
233232#endif
234233 if ( m_frames == 0 )
235234 {
236- m_frames = decodeSampleSF ( f , fbuf, channels,
235+ m_frames = decodeSampleSF ( file , fbuf, channels,
237236 samplerate );
238237 }
239238#ifdef LMMS_HAVE_OGGVORBIS
240239 if ( m_frames == 0 )
241240 {
242- m_frames = decodeSampleOGGVorbis ( f , buf, channels,
241+ m_frames = decodeSampleOGGVorbis ( file , buf, channels,
243242 samplerate );
244243 }
245244#endif
246245 if ( m_frames == 0 )
247246 {
248- m_frames = decodeSampleDS ( f , buf, channels,
247+ m_frames = decodeSampleDS ( file , buf, channels,
249248 samplerate );
250249 }
251-
252- delete[] f;
253250 }
254251
255252 if ( m_frames == 0 || fileLoadError ) // if still no frames, bail
@@ -405,7 +402,7 @@ void SampleBuffer::normalizeSampleRate( const sample_rate_t _src_sr,
405402
406403
407404
408- f_cnt_t SampleBuffer::decodeSampleSF ( const char * _f,
405+ f_cnt_t SampleBuffer::decodeSampleSF (QString _f,
409406 sample_t * & _buf,
410407 ch_cnt_t & _channels,
411408 sample_rate_t & _samplerate )
@@ -416,7 +413,11 @@ f_cnt_t SampleBuffer::decodeSampleSF( const char * _f,
416413 f_cnt_t frames = 0 ;
417414 bool sf_rr = false ;
418415
419- if ( ( snd_file = sf_open ( _f, SFM_READ , &sf_info ) ) != NULL )
416+
417+ // Use QFile to handle unicode file names on Windows
418+ QFile f (_f);
419+ f.open (QIODevice::ReadOnly);
420+ if ( ( snd_file = sf_open_fd ( f.handle (), SFM_READ , &sf_info, false ) ) != NULL )
420421 {
421422 frames = sf_info.frames ;
422423
@@ -442,6 +443,8 @@ f_cnt_t SampleBuffer::decodeSampleSF( const char * _f,
442443 " sample %s: %s" , _f, sf_strerror ( NULL ) );
443444#endif
444445 }
446+ f.close ();
447+
445448 // write down either directly or convert i->f depending on file type
446449
447450 if ( frames > 0 && _buf != NULL )
@@ -507,7 +510,7 @@ long qfileTellCallback( void * _udata )
507510
508511
509512
510- f_cnt_t SampleBuffer::decodeSampleOGGVorbis ( const char * _f,
513+ f_cnt_t SampleBuffer::decodeSampleOGGVorbis ( QString _f,
511514 int_sample_t * & _buf,
512515 ch_cnt_t & _channels,
513516 sample_rate_t & _samplerate )
@@ -603,7 +606,7 @@ f_cnt_t SampleBuffer::decodeSampleOGGVorbis( const char * _f,
603606
604607
605608
606- f_cnt_t SampleBuffer::decodeSampleDS ( const char * _f,
609+ f_cnt_t SampleBuffer::decodeSampleDS ( QString _f,
607610 int_sample_t * & _buf,
608611 ch_cnt_t & _channels,
609612 sample_rate_t & _samplerate )
0 commit comments