This is the bug/patch tracker for Rockbox. Click here for more information.
Quick links: Bugs · Patches · Rockbox frontpage
FS#6109 - Recording misses lots of samples (1-2 seconds!)
Attached to Project:
Rockbox
Opened by Peter D'Hoye (petur) - Tuesday, 03 October 2006, 11:08 GMT+2
Last edited by Peter D'Hoye (petur) - Monday, 04 December 2006, 10:12 GMT+2
Opened by Peter D'Hoye (petur) - Tuesday, 03 October 2006, 11:08 GMT+2
Last edited by Peter D'Hoye (petur) - Monday, 04 December 2006, 10:12 GMT+2
|
Detailscurrent CVS recording code is not stable. Missing samples (1-2 seconds) around the time of diskwrite, but not always. Maybe a timing issue/glitch?
example of 80 minutes recording: missing samples at: 10:23 (delta 10:23 = 4 x buffer time) 15:35 (delta 5:12 = 2 x buffer time) 36:25 (delta 20:50 = 8 x buffer time) 52:01 (delta 15:36 = 6 x buffer time) 72:49 (delta 20:48 = 8 x buffer time) |
This task depends upon
Closed by Michael Sevakis (MikeS)
Friday, 16 February 2007, 11:43 GMT+2
Reason for closing: Fixed
Additional comments about closing: ostensibly, presumably and likley probably
Friday, 16 February 2007, 11:43 GMT+2
Reason for closing: Fixed
Additional comments about closing: ostensibly, presumably and likley probably
Just encountered it again with a build based on CVS 2006-12-02 :(
Maybe my disk is fragmented too much causing saving to take more time here?
sample of the glitch: http://users.telenet.be/petur/glitch.wav (listen very good at 0:13 and following seconds)
In total, I've had 3 glitches in 1:44 hour. The file had 2 fragments. Another (shorter) recording has no audible glitches on first hearing but 29 fragments. Go figure...
I did some very important voice recording recently through line-in on the H120 and had no glitches in files > 1hr (MP3, mono, 160kbps). I know it's not as many trips around the ring buffer as a WAV will make but spinup and high watermark are still time based on encoded data, so hmmm. I'm not currently aware of any other person that's had a glitch problem. If you have any buffer overflows you'll get the warning flashing and it was tested (inadvertently) when recording was being added to iPods and H10 and it worked (caught a pcm buffer overflow when a line of code was removed accidentally). The buffer checks are part of a normal build.
I was running in via optical S/PDIF. However, out of three sets that I've recorded I had no issues with the first, only the last two. I did change the level meters from linear to logrithmic between the first and secods sets and changed the min/max values for them. That's the only change, which seems unlikely to cause such an issue. That also caused the level meters to show up as a solid bar, which eventually began functioning normally after awhile.
Did you get any warning flash on the screen on top of the time display? If you were using a build since PCMREC_PARANOID was added then you likely should have (see 3 msgs above). Your description is again what I would expect if something kept the drive from writing and the buffer fills up _and_ doing concert recording too...hmmm. At home on my H120 I've had no luck at duplicating any of this for recordings of any length or format. I know I'm sounding repetitive but have no other plausible theory or pointer in another direction. If you used a recent build and got no warning then I'll have to consider other possibilities.
jhMikeS, can't we just nudge the watermark levels a bit more to the safe side? I'd rather not wipe my disk everytime I go taping just to be sure it'll be glitchless. Remember, I've never had these issues before the new encoder framework, and my disk didn't fill up much more since that. So I still blame badly chosen bufferlimits.
Change Line 833: 5ull*HZ part could be 8ull*HZ to have a 10s minimum watermark. Usually the compensated watermark for me is around 7.5 seconds (5 + 2.5). The minimum drive compensation is 2s and max 10s. The thresholds are tighter on x5 with only 16MB ram (and 88.2kHz !!) and I don't know about others atm. I don't want to induce a perpetual flushing state on lower mem players.
I want to know if a warning 00000002 came up because that would comfirm my theory. I put that in there so tapers could report back and I'd know exactly what occurred. I'm quite sure it can't be pcm overflow (warning 000000001) since that would cause a skip forward to a section of the latest pcm data received and then back on track and then probably a repeat of that section later if another overflow didn't occurr. Afaik all is jump forward in time by chunk-multiple sizes hence dumping data since no room is left.
Are these players using (larger?) replacement drives? I'm Curious.
Here's the relevant information about the setup: My drive was practically empty (maybe 2 Gb of music on it), not fragmented at all. I was recording from SPDIF optical in to WAV format at 16bit/44.1kHz. The iRiver is barely used and completely stock, no RTC chip mods, no large capacity drives or batteries. It's never been opened to expose the guts (even though I really want to).
I will mention that it was having some other funny issues at the time. It had locked up about an hour before, causing me to have to reset it with a paper clip. Then it was having some really strange issues with the peak meter (appearing as solid full bars for five minutes, etc). I have since wiped rockbox and done a clean install from the Jan 29 build. No more issues.
My only other idea about what could cause this involves loosing the input signal. Could this possibly be an issue with the recorder temporarily loosing the optical SPDIF signal? That could happen if it were shaken enough (possibly by loud sound?) Was everyone else using a digital source when the issues happened?
I'll be experimenting a lot in the near future. I'll be recording another show in two weeks, so I'll try recording from line, radio, etc and using different codecs. I'd really hate to have this happen with WavePack, where I'd loose potentially more than with just samples missing in a WAVE file. Is there anything else I can do to try and help solve this? I've been looking a lot at the code, but am not familiar with it enough yet to discover much, and I'd love to know that it has been resolved before I loose chunks of another show.
Yes, S/PDIF errors could also cause the same thing. It will just drop the data that the CPU said was bad and not advance the pcm buffer so sure that's another possiblity. Peter was using a H300 series so no S/PDIF in his case. I don't put a warning for S/PDIF errors since they're common when a source device just begins playback and such and benign in those cases as well.
Dropped data either at the raw pcm end or even after encoding won't hurt a WavPack file at all (or any other format). The header for each WavPack chunk isn't finalized until writing it, each is independent of the others and the RIFF metadata will be based upon what has actually been written to disk just before closing the file. If writing to disk failed recording would have set an error.
The issues you were having could be connected to it as well. I can't see the peakmeters acting that way unless something is really goofed like settings not being reset when they should or a full reinstall not being done when it should have been.
That's the thing, every other problem Peter reported I was able to narrow down and fix rather quickly but this one doesn't seem to have a cause from a mistake that I can spot in the recording code itself. Could be buffer limits but why no trouble for me or others recording under calmer conditions? Loud sound/movement affecting the hd? Perhaps things require more time under those conditions and that's all. The older pcm record didn't have to share CPU time with the codec thread.
Unfortunately your description of what was going on doesn't help me narrow things to a single cause in your case at all.
At this point I really can't claim that it's a bug since I can't reproduce it. Like you said, even if there is a bug it could be related to something completely different. I had played with a LOT of setting prior to that recording session, and during my tests I tried to turn everything unnecessary off to keep things clean. I should do a lot more poking through the code to see what is going on.
As for the buffer limits, they do seem to be a little tight, not allowing a lot of room for error. Would it be hard to loosen that up a little? I guess from now on I'll just do a clean install from a tested build with everything turned off before I record something important, but it all leaves me a little unsettled.
What threads run in parallel with the recorder? Is it just the codec being used or are there others?
The buffer limits can be changed very easily and I may clean up the way they're defined so they can be different for different mem sizes if needed and I'll test out boosting upon losing progress to the codec thread rather than at 1s left in the buffer.
Recording involves chiefly: 1) codec thread encoding/copying audio data 2) main thread running gui/lcd updates/peakmeters/AGC 3) pcmrec thread (mostly sleeping till a disk flush happens but checking status every 200ms) 4) DMA transfer of pcm data (interrupt every ~46ms for 2048 samples @44.1k).
The limit for a typical HD spininup on an iRiver should now be about the same margin as before (11s-12s). I can't atm test the WavPack at 88kHz on x5 to test the priority boosting - it's guaranteed to be needed there. Will also up priority if 1 second of ground is lost rather than 1s left. I added more yielding to that to try and allow other things to run but would like to tune it. Did some misc. stuff.
Not sure if I should commit yet without testing the WavPack thing on x5.
Also, I have an idea to add a buffer screen similar to the one for the audio thread. Maybe a graphical representation would help visualization and tuning. Would have to be accessible somehow via the recording screen rather than the debug menu so that entering/leaving it doesn't interrupt recording.
I like your ideas about the buffer screen. How about using the A/B button while recording to get there? I don't think it is used otherwise. If you'd like help testing the changes before you commit them I would volunteer my unit. I should probably retest recording again with the settings that I had set previously to make absolutely sure that I can't reproduce this. Maybe I can narrow it down to a particular setting that is causing this
Eureka, I did have a breakthrough simulating a burdened flush and I didn't get an overflow in the codec buffer but rather the PCM buffer (even though the flush did complete properly and I might add, somewhat quickly). Indeed if the write pointer overshoots you will lose all 11 seconds of data in the pcm buffer and have a skip forward since the overshoot makes it logically empty. The priority boosting is not letting the codec thread run enough if a flush stays boosted for a long time. I cannot not rule out sound vibration as the reason the drive writes may slow down since they pass the shaking test.
The results of this checking were exactly of the sort that has been experienced. I found an additional skip in Peter's recording that was NOT on a chunk boundary and that can't happen if the codec buffer overflows.
The older non-codec recording would not be susceptible to this problem so quickly since only one thread was involved and the output buffer and the pcm buffer were the same buffer and it was all available memory. More generous buffer limits in the codec buffer probably won't be as helpful as hoped since the pcm buffer seems the one inclined to overflow. In short: 1) Increase the PCM buffer size 2) Better coordinate the two threads during priority boost (which is a mandatory aspect of this but maybe not on all players).
This is the best result I've had the most promising lead by far...though a bit couterintuitive.
You could try blasting music at it at concert levels while recording...or maybe even louder that that to try and enhance the effect.
Yes, it would probably help. What would also help is for you to give me the exact sample index from sample 0 of your recording that each clip starts at. This tells me something since with wav and aiff encoder chunks are the same size as pcm chunks so always correspond 1:1. Milliseconds aren't close enough. I don't know if your audio software allows working at the sample level with sample indexes though. Peter just send me his whole recording in mono flac so I could look.
If it would be better, I can just revert it all back to a codec-less system but I think that's probably overkill and it probably really only needs some tweaking to resolve.
EDIT: Delete invalid patches.
BTW: Those patches above contain test code that cuts memory in half. :P I made extra care to remove all that stuff in this one. I just got a bit distracted and forgot about it. Sorry.
By the way, thanks so much for all the time and effort you have put into this, and don't think that it isn't appreciated, because it certainly is.
Also, I'm looking into the peakmeter issue and have thoughts about how to handle the settings to make any issue with db/% moot.
I will probably commit the changes (along with some simplifications and misc tweaks) since it does make the code more robust against writing problems (10x +) but I know for sure I can max it out with a few more small ones.
Anyway, I recorded another concert this last weekend (stealth-taping through mic-in instead of SPDIF), and had no issues at all. The recording came out great. No matter what I do I cannot reproduce any sort of errors. At this point I would say why not just commit the changes? I can think of nothing else that I can do to help out any more and it sounds like you have made some good improvements. Lets just call it done and I'll continue watching for your error messages to pop up while recording and we can just reopen this if it ever happens again. What do you think?
There's no difference at all in the execuction of code when using S/PDIF after initial configuration.
I'm waiting for word from Petur since he was the original reporter before closing anything but he'll probably take it upon himself if he's reasonably satisfied and open it again if anything comes up.
commit the changes and close the report. I get the feeling you found the possible issue I had so I'm ok with closing the issue.
If I ever have more troubles I can still reopen or submit a new report ;)
Or better, debug myself.
Sorry for letting you on your own on this but I had no time to learn the changed code & debug it...
Had some personal crap going on so I was ready to tear anyone's head off the other day. Sorry for the outburst (and the graphic language). :)
Incidentally the newer wavpack lib seems to suck. Bad compression ratios. Used to be ~870kbits, now I'm negative compression pretty often. :\\