Re: [Audacity-devel] No MIDI output on Linux, then freeze
A free multi-track audio editor and recorder
Brought to you by:
aosiniao
From: Steve t. F. <ste...@gm...> - 2017-08-09 14:50:45
|
I've done some digging, and the problem lies with the timestamp on MIDI messages. They are in the past, so ALSA never sends them, then when ALSA's buffer is full it blocks => freeze. We assume that Midi time is one second ahead of real time, but the time stamp returned by MidiTime() is wildly different from real time as returned by Pt_Time For example: Midi time = 1502280219856 Pt_Time = -958334844 (yes that's negative) The problem is that the (double) value calculated in AudioIO::MidiTime() overflows in the casting, and not in a portable way. (PmTimestamp) ((unsigned long) <very_big_float> ) is not equal to (PmTimestamp) <very_big_float> On my Linux box, if I cast to int32_t or PmTimestamp, then the time stamps are reasonable, When casting to unsigned long first, the time stamps are not. In AudioIO::MidiTime(), this works for me: return (PmTimestamp) (1000 * (AudioTime() + 1.0005 - mAudioFramesPerBuffer / mRate + PaUtil_GetTime() - mAudioCallbackOutputTime)); So why did MIDI playback work for me a few weeks ago, and then suddenly stop? On Wednesday, 26 July 2017 at 18:44:29.952, Epoch time rolled over from 31 LSBs = 1, to 31 LSB = 0. Steve On 6 August 2017 at 02:39, Roger Dannenberg <rb...@cs...> wrote: > I added a new test to PortMidi to send lots of messages. I've been > sending1000 timed messages per second for extended durations, e.g. 3 > minutes, and timidity produces some "interesting" output, apparently > dropping a lot of messages which are back-to-back NoteOn/NoteOff > messages, but it never hangs or shows any noticeable hiccups or delays. > > Steve, would you like to compile this and try it on your system? I'm > trying to commit the new stuff to sourceforge, but having some > connection problems, so contact me about the status if you want the code. > > -Roger > > > On 8/4/17 7:48 PM, Steve the Fiddle wrote: >> Check a few posts back in this thread - I've already replied, but the >> thread may have got out of order. >> >> Steve >> >> On 4 August 2017 at 21:31, Paul Licameli <pau...@gm...> wrote: >>> >>> On Wed, Aug 2, 2017 at 1:36 PM, Paul Licameli <pau...@gm...> >>> wrote: >>>> >>>> >>>> On Wed, Aug 2, 2017 at 12:50 PM, Steve the Fiddle >>>> <ste...@gm...> wrote: >>>>> On 2 August 2017 at 17:43, Paul Licameli <pau...@gm...> wrote: >>>>>> >>>>>> On Wed, Aug 2, 2017 at 12:14 PM, Steve the Fiddle >>>>>> <ste...@gm...> >>>>>> wrote: >>>>>>> Testing with Paul's midi branch at 8a8a51e >>>>>>> I still get the freeze condition, no MIDI playback, and no error >>>>>>> messages. >>>>>> >>>>>> Are you sure you rebuilt portmidi and linked to that rebuilt library? >>>>>> Part >>>>>> of the fix is adding error checks to portmidi. >>>>> Possibly not. I'll test again. >>>>> >>>>> Steve >>>> >>>> >>>> I found another thing: >>>> http://www.alsa-project.org/alsa-doc/alsa-lib/group___sequencer.html#ga95462dc59c0319e186cda713ecfb4ed3 >>>> What happens if we pass SND_SEQ_NONBLOCK as the fourth argument of >>>> snd_seq_open ? This documentation suggests that this might solve the >>>> freezing problem at least. You could try that simple change in >>>> pmlinuxalsa.c. Perhaps too, the third argument could be >>>> SND_SEQ_OPEN_OUTPUT. >>>> >>>> Somewhere, there was a failure to detect an error condition related to >>>> starting the queues, and stop the show early. My modified pmlinuxalsa.c >>>> added some checking in alsa_use_queue. Single-step it if you can. That >>>> part should happen in the main thread. >>>> >>>> If you really have the change but still have the freezes, then it could be >>>> that alsa itself is failing to report its errors to the level of portmidi. >>>> Maybe you can step into the snd_seq functions to get more insights about >>>> that. >>>> >>>> A silly question: Have you yet done the "when in doubt, reboot" since >>>> this problem first arose? >>>> >>>> If not, then that's a clue. I wonder if there is some sort of system-wide >>>> resource leak, perhaps because you ran Audacity, and killed it, before it >>>> properly terminated alsa? Can we detect that condition and correct it, with >>>> something else in the alsa API? >>>> >>>> PRL >>>> >>> Steve, have you tried any of these ideas? I eagerly await a report. >>> >>> This is one of two outstanding problems that I still consider show-stopping. >>> It is not good that a new banner feature may cause the program to lock up >>> sometimes. >>> >>> PRL >>> >>> >>>> >>>>> >>>>>> PRL >>>>>> >>>>>> >>>>>>> >>>>>>> Steve >>>>>>> >>>>>>> On 2 August 2017 at 16:17, Roger Dannenberg <rb...@cs...> wrote: >>>>>>>> That's great info. From this, my interpretation is: We're writing a >>>>>>>> midi >>>>>>>> message; Pm_Write called alsa_write() or alsa_write_short(); I think >>>>>>>> this >>>>>>>> puts data into the alsa library output buffer but doesn't actually >>>>>>>> send >>>>>>>> it; >>>>>>>> alsa_write_flush() is called to move data from the library queue to >>>>>>>> the >>>>>>>> kernel side of ALSA; to do that, alsa_write_flush() calls >>>>>>>> snd_seq_drain_output(), and snd_seq_drain_output() never returns. I >>>>>>>> don't >>>>>>>> understand ALSA MIDI well, and when I implemented PortMIDI, I >>>>>>>> couldn't >>>>>>>> figure it out, but after several tries, I got help from one of the >>>>>>>> ALSA >>>>>>>> developers who supplied some of the code fragments. E.g. I couldn't >>>>>>>> explain >>>>>>>> what snd_seq_drain_output() does in detail or why it might hang. The >>>>>>>> documentation describes the API calls, but there's very little about >>>>>>>> what >>>>>>>> they actually do or how to correctly use them other than some >>>>>>>> examples. >>>>>>>> Do >>>>>>>> we have any current contacts in the ALSA team? -Roger >>>>>>>> >>>>>>>> >>>>>>>> On 8/2/17 10:27 AM, Steve the Fiddle wrote: >>>>>>>> >>>>>>>> Attached is a backtrace showing all threads after interrupting the >>>>>>>> freeze (thanks Roger). >>>>>>>> This is from unpatched Audacity. >>>>>>>> >>>>>>>> Steve >>>>>>>> >>>>>>>> On 2 August 2017 at 15:20, Paul Licameli <pau...@gm...> >>>>>>>> wrote: >>>>>>>> >>>>>>>> Here is another piece, not the last, of my solution. I change >>>>>>>> pmlinuxalsa.c >>>>>>>> to detect and report errors when starting the queue, and also avoid >>>>>>>> a >>>>>>>> memory >>>>>>>> leak when there is an error. Roger may want to review this. >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> https://github.com/Paul-Licameli/audacity/commit/b2741064c7efd68df46b04831cd470bb7a86ec8e >>>>>>>> >>>>>>>> >>>>>>>> PRL >>>>>>>> >>>>>>>> >>>>>>>> On Wed, Aug 2, 2017 at 10:02 AM, Paul Licameli >>>>>>>> <pau...@gm...> >>>>>>>> wrote: >>>>>>>> >>>>>>>> >>>>>>>> On Wed, Aug 2, 2017 at 9:26 AM, Roger Dannenberg <rb...@cs...> >>>>>>>> wrote: >>>>>>>> >>>>>>>> This is a good idea to get information about what's going on, but in >>>>>>>> PortMidi, if you set Latency to zero, it means all timestamps should >>>>>>>> be >>>>>>>> ignored and all output should be delivered as soon as possible (in >>>>>>>> order >>>>>>>> of >>>>>>>> output of course). If Latency is non-zero, all timestamps are >>>>>>>> incremented by >>>>>>>> Latency and delivered to the underlying API (ALSA in Linux) for >>>>>>>> timed >>>>>>>> delivery (but also in order of output, so you can't use this to >>>>>>>> schedule >>>>>>>> or >>>>>>>> sort messages by timestamps, and if the timestamp is greater than >>>>>>>> real >>>>>>>> time, >>>>>>>> the message is delivered immediately). Since Audacity audio output >>>>>>>> can >>>>>>>> run >>>>>>>> pretty far ahead of real time, the audio time and MIDI time are >>>>>>>> synchronized, and latency is used to synchronize MIDI to audio. So >>>>>>>> if >>>>>>>> latency=0 "works", it will not be synchronized as well. >>>>>>>> >>>>>>>> I *did* see some very large numbers for timestamps or latency and >>>>>>>> some >>>>>>>> minus signs in some of the debug logs, and I was wondering if there >>>>>>>> was >>>>>>>> a >>>>>>>> problem there, but since the output works up to a point, I figured >>>>>>>> the >>>>>>>> problem is elsewhere. >>>>>>>> >>>>>>>> Also, output with latency=0, no timestamps, can use completely >>>>>>>> different >>>>>>>> output methods, but I think that's only true on Windows. >>>>>>>> >>>>>>>> -Roger >>>>>>>> >>>>>>>> Roger, I had no intention of making this a permanent fix, but I >>>>>>>> examined >>>>>>>> pmlinuxalsa.c and concluded that there are error messages being >>>>>>>> ignored >>>>>>>> at >>>>>>>> startup, only when there is a latency and the queue is initialized. >>>>>>>> >>>>>>>> I am working on fixes: failure of portmidi to report errors, also >>>>>>>> failure >>>>>>>> of Audacity to test for them. >>>>>>>> >>>>>>>> PRL >>>>>>>> >>>>>>>> >>>>>>>> On 8/2/17 9:03 AM, Paul Licameli wrote: >>>>>>>> >>>>>>>> Steve, here is a guess: make this change to line 2111 of >>>>>>>> AudioIO.cpp: >>>>>>>> >>>>>>>> mMidiLatency = 0; // arbitrary, but small >>>>>>>> >>>>>>>> Either you will get playback without problems, or you will get a >>>>>>>> prompt >>>>>>>> failure when you attempt to start. >>>>>>>> >>>>>>>> I have growing confidence that we can at least avoid the hanging >>>>>>>> problem. >>>>>>>> I will write more soon. >>>>>>>> >>>>>>>> PRL >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> ------------------------------------------------------------------------------ >>>>>>>> Check out the vibrant tech community on one of the world's most >>>>>>>> engaging tech sites, Slashdot.org! http://sdm.link/slashdot >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> _______________________________________________ >>>>>>>> audacity-devel mailing list >>>>>>>> aud...@li... >>>>>>>> https://lists.sourceforge.net/lists/listinfo/audacity-devel >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> ------------------------------------------------------------------------------ >>>>>>>> Check out the vibrant tech community on one of the world's most >>>>>>>> engaging tech sites, Slashdot.org! http://sdm.link/slashdot >>>>>>>> _______________________________________________ >>>>>>>> audacity-devel mailing list >>>>>>>> aud...@li... >>>>>>>> https://lists.sourceforge.net/lists/listinfo/audacity-devel >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> ------------------------------------------------------------------------------ >>>>>>>> Check out the vibrant tech community on one of the world's most >>>>>>>> engaging tech sites, Slashdot.org! http://sdm.link/slashdot >>>>>>>> _______________________________________________ >>>>>>>> audacity-devel mailing list >>>>>>>> aud...@li... >>>>>>>> https://lists.sourceforge.net/lists/listinfo/audacity-devel >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> ------------------------------------------------------------------------------ >>>>>>>> Check out the vibrant tech community on one of the world's most >>>>>>>> engaging tech sites, Slashdot.org! http://sdm.link/slashdot >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> _______________________________________________ >>>>>>>> audacity-devel mailing list >>>>>>>> aud...@li... >>>>>>>> https://lists.sourceforge.net/lists/listinfo/audacity-devel >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> ------------------------------------------------------------------------------ >>>>>>>> Check out the vibrant tech community on one of the world's most >>>>>>>> engaging tech sites, Slashdot.org! http://sdm.link/slashdot >>>>>>>> _______________________________________________ >>>>>>>> audacity-devel mailing list >>>>>>>> aud...@li... >>>>>>>> https://lists.sourceforge.net/lists/listinfo/audacity-devel >>>>>>>> >>>>>>> >>>>>>> >>>>>>> ------------------------------------------------------------------------------ >>>>>>> Check out the vibrant tech community on one of the world's most >>>>>>> engaging tech sites, Slashdot.org! http://sdm.link/slashdot >>>>>>> _______________________________________________ >>>>>>> audacity-devel mailing list >>>>>>> aud...@li... >>>>>>> https://lists.sourceforge.net/lists/listinfo/audacity-devel >>>>>> >>>>>> >>>>>> >>>>>> ------------------------------------------------------------------------------ >>>>>> Check out the vibrant tech community on one of the world's most >>>>>> engaging tech sites, Slashdot.org! http://sdm.link/slashdot >>>>>> _______________________________________________ >>>>>> audacity-devel mailing list >>>>>> aud...@li... >>>>>> https://lists.sourceforge.net/lists/listinfo/audacity-devel >>>>>> >>>>> >>>>> ------------------------------------------------------------------------------ >>>>> Check out the vibrant tech community on one of the world's most >>>>> engaging tech sites, Slashdot.org! http://sdm.link/slashdot >>>>> _______________________________________________ >>>>> audacity-devel mailing list >>>>> aud...@li... >>>>> https://lists.sourceforge.net/lists/listinfo/audacity-devel >>>> >>> >>> ------------------------------------------------------------------------------ >>> Check out the vibrant tech community on one of the world's most >>> engaging tech sites, Slashdot.org! http://sdm.link/slashdot >>> _______________________________________________ >>> audacity-devel mailing list >>> aud...@li... >>> https://lists.sourceforge.net/lists/listinfo/audacity-devel >>> >> ------------------------------------------------------------------------------ >> Check out the vibrant tech community on one of the world's most >> engaging tech sites, Slashdot.org! http://sdm.link/slashdot >> _______________________________________________ >> audacity-devel mailing list >> aud...@li... >> https://lists.sourceforge.net/lists/listinfo/audacity-devel > > |