[haiku-bugs] Re: [Haiku] #7863: [BSound] audio garbled, sometimes crashes, on files other than WAV

  • From: "ttcoder" <trac@xxxxxxxxxxxx>
  • Date: Sat, 23 Jul 2011 15:24:15 -0000

#7863: [BSound] audio garbled, sometimes crashes, on files other than WAV
------------------------------+-----------------------
   Reporter:  ttcoder         |      Owner:  axeld
       Type:  bug             |     Status:  new
   Priority:  normal          |  Milestone:  R1
  Component:  Kits/Media Kit  |    Version:  R1/alpha3
 Resolution:                  |   Keywords:
 Blocked By:                  |   Blocking:
Has a Patch:  0               |   Platform:  All
------------------------------+-----------------------

Comment (by ttcoder):

 Details --

 File types:
 - WAV files are perfect, no flaw whatsoever that I can hear.
 - PCM files need a big buffer (though maybe a tad smaller than mp3s)
 - mp3 files need a big buffer.

 Hardware:[[BR]]
 this is with the Auich driver, but it behaved the same when I tested with
 the SB-Live/emuxki plugged-in.

 Software:[[BR]]
 this is Alpha3 (gotta try again on a nightly, though the nightly of 2
 weeks ago was no better than R1A3).

 Crash:[[BR]]
 The crash I got a couple times after a few seconds of playback:
 in
 [http://dev.haiku-
 os.org/browser/haiku/trunk/src/kits/media/SoundPlayer.cpp#L695
 _SoundPlayBufferFunc]/
 [http://dev.haiku-os.org/browser/haiku/trunk/src/kits/media/Sound.cpp#L182
 GetDataAt]/
 [http://dev.haiku-
 os.org/browser/haiku/trunk/src/kits/media/TrackReader.cpp#L206 ReadFrames]
 {{{
 ...
 Thread 2975 caused an exception: Segment violation
 ...
 (gdb) bt
 #0  0xffff012c in ?? ()
 #1  0x00000000 in ?? ()
 #2  0x00000400 in ?? ()
 #3  0x00385849 in BPrivate::BTrackReader::ReadFrames ()
    from /boot/system/lib/libmedia.so
 #4  0x00376775 in BSound::GetDataAt () from /boot/system/lib/libmedia.so
 #5  0x00378745 in BSoundPlayer::_SoundPlayBufferFunc ()
    from /boot/system/lib/libmedia.so
 #6  0x00379568 in BSoundPlayer::PlayBuffer () from
 /boot/system/lib/libmedia.so
 #7  0x00389a31 in BPrivate::SoundPlayNode::FillNextBuffer ()
    from /boot/system/lib/libmedia.so
 #8  0x003894f8 in BPrivate::SoundPlayNode::SendNewBuffer ()
    from /boot/system/lib/libmedia.so
 #9  0x003893b5 in BPrivate::SoundPlayNode::HandleEvent ()
    from /boot/system/lib/libmedia.so
 #10 0x0035cbf5 in BMediaEventLooper::DispatchEvent ()
    from /boot/system/lib/libmedia.so
 #11 0x0035c894 in BMediaEventLooper::ControlLoop ()
    from /boot/system/lib/libmedia.so
 #12 0x0035cc7f in BMediaEventLooper::_ControlThreadStart ()
    from /boot/system/lib/libmedia.so
 #13 0x008ad7e6 in thread_entry () from /boot/system/lib/libroot.so
 #14 0x78247fec in ?? ()
 (gdb)
 }}}

 Stdout:[[BR]]
 I've also noticed that the MediaKit "audio decode" warnings sent to stdout
 report some different offsets.

 To wit:
 {{{
 /tmp/> MediaPlayer
 open playlist item: Linkin Park - In The End.mp3
 ...
 _InitFromTrack(): keyframes: 1, frame count: 9545356
 running without video node
 BMediaEventLooper: SchedulingLatency is 750
 BMediaRoster::Connect connection established!
 ...
 ########### audio decode error, fChunkBufferSize 913, fChunkBufferOffset 0
 AudioProducer::_FillNextBuffer() - supplier error -> silence
 BMediaRoster::ReleaseNode, trying to release reference counting disabled
 timesource, node 2, port 3752069, team 1596
 }}}

 Whereas TT results in this output:

 {{{
 /tmp/> ./TuneTracker   # playing obviously the same mp3 as above, by the
 way
 ...
 ########### audio decode error, fChunkBufferSize 2338, fChunkBufferOffset
 0
 ########### audio decode error, fChunkBufferSize 2338, fChunkBufferOffset
 0
 ########### audio decode error, fChunkBufferSize 2338, fChunkBufferOffset
 0
 SoundPlayNode::SendNewBuffer, event scheduled much too late, lateness is
 8290
 SoundPlayNode::SendNewBuffer, event scheduled much too late, lateness is
 8288
 SoundPlayNode::SendNewBuffer, event scheduled much too late, lateness is
 8354
 BMediaRoster::ReleaseNode, trying to release reference counting disabled
 timesource, node 2, port 3752069, team 1575
 PluginManager: Error, unloading PlugIn ffmpeg with usecount 2
 }}}

 So it looks like the MediaKit's underlying MP3 decoder "spreads thin" for
 me, making the audio sound more bass and 'chopped'.


 Code:[[BR]]
 Here's the code I use (which does work for WAV files, but not others):
 {{{
                         media_node audio_out = GetOrMakeMixerFor(...);

                         BSound * sound = new BSound( &mp3_entry_ref
 );//passing 'preload=true' makes no difference..

                         media_format fmt;
                         *((media_raw_audio_format *)&fmt.u.raw_audio) =
 sound->Format();
 // necessary under Haiku, but not in BeOS! And audio still not 100% ok:
 fmt.u.raw_audio.buffer_size = 65536;//32768;//16384;//8192;

 printf("---> frame_rate=%f channel_count=%ld format=%lu byte_order=%lu
 buffer_size=%ld\n", fmt.u.raw_audio.frame_rate,
 fmt.u.raw_audio.channel_count, fmt.u.raw_audio.format,
 fmt.u.raw_audio.byte_order, fmt.u.raw_audio.buffer_size);

                         auditionSoundPlayer = new BSoundPlayer(
                                         audio_out,
                                         &fmt.u.raw_audio,
                                         "TT_audition" );
                         auditionSoundPlayer->SetVolume( 1.0 );
                         auditionSoundPlayer->Start();
                         auditionSoundPlayer->StartPlaying( sound );
                         sound->ReleaseRef();
 }}}


 Similar tickets:
 Found #7285 but my ticket is about garbled sound, whereas 7285 is about
 latency. There are some troubling similarities though.

 I've also tried the sample code over at #4825 but it seems that this
 (closed) ticket should be re-opened: the sample code listed on that ticket
 results in some EXTREMELY loud garbled sound, and sometimes crashes --
 i.e. that other code behaves even worse than mine.

-- 
Ticket URL: <http://dev.haiku-os.org/ticket/7863#comment:1>
Haiku <http://dev.haiku-os.org>
Haiku - the operating system.

Other related posts: