Ticket #396 (closed defect: fixed)

Opened 2 years ago

Last modified 2 years ago

Inaccurate beep generation algorithm causes lags on netbooks

Reported by: aleksey_s Owned by: aleksey_s
Priority: minor Milestone: 2009.1
Component: Core Version: development
Keywords: needsCodeReview Cc:
Operating system: Blocked by:
Blocking:

Description

Tried on intel atom 1.6 ghz.

Change History

comment:1 Changed 2 years ago by aleksey_s

  • Keywords needsCodeReview added
  • Owner set to aleksey_s
  • Status changed from new to accepted

I was really surprised by time measurements i made after receiving this report.
Proposed implementation see in bzr branch:  http://bzr.nvaccess.org/nvda/tonesRewrite

comment:2 follow-up: ↓ 3 Changed 2 years ago by jteh

To clarify, does this actually fix the problem on said Netbooks or do you suspect that it fixes the problem?

We've considered moving the tone generation stuff into another thread. This would allow for smoother movement between tones when many tones occur in close succession.

Btw, for your interest, I suspect the reason the Python code is so slow is that it keeps appending to a string. Strings are immutable, which means that the whole string is probably regenerated each time we add a byte. If we were using Python 3, we'd use a bytes array, which is mutable and therefore probably much faster when appending a single byte at a time. It may be faster to use a list rather than a string in Python 2 and then join it at the end of the loop.

comment:3 in reply to: ↑ 2 Changed 2 years ago by aleksey_s

Replying to jteh:

To clarify, does this actually fix the problem on said Netbooks or do you suspect that it fixes the problem?

Yes, tested on my girlfriend's Aspire One.

We've considered moving the tone generation stuff into another thread. This would allow for smoother movement between tones when many tones occur in close succession.

Do you mean new thread for each beep or one thread for all? Anyway, current implementation can generate as many beeps at a time asw you want without any lag. :) And as far as i know we already are playing audio in another thread.

Btw, for your interest, I suspect the reason the Python code is so slow is that it keeps appending to a string. Strings are immutable, which means that the whole string is probably regenerated each time we add a byte. If we were using Python 3, we'd use a bytes array, which is mutable and therefore probably much faster when appending a single byte at a time. It may be faster to use a list rather than a string in Python 2 and then join it at the end of the loop.

I suspect native code will be faster here anyway. Of course i am not about accuration for accuration, here i saw really lags and made time measurements. Well, since, we aren't on python 3 i believe a couple linesof c++ code will do the job.

comment:4 Changed 2 years ago by aleksey_s

Any chances this will be included in main?

comment:5 Changed 2 years ago by jteh

  • Milestone set to 2009.1

Mick, tested this just now and it works fine for me. No l10n impact. Are you happy to include in 2009.1 given the performance improvement on netbooks?

comment:6 Changed 2 years ago by mdcurran

I am certainly happy for this to go in to main.
While I was reviewing I did commit a small optimization to the generateBeep function, which I had been meaning to do in tones.py for a while anyway. That is to calculate some of the sine frequency stuff outside the for loop, as the only real variable there is the position with in the sine wave.

I do have another question about coding, which is more probably a lack of understanding on my part:
Why is it that for all your unsigned int constants you don't actually declare them as int? e.g.
const unsigned sampleRate=44100;

Is there a rule in c++ that states these are automatically int?

However, the code works and is understandable, so I'm happy if it goes in to main.

comment:7 Changed 2 years ago by jteh

  • Status changed from accepted to closed
  • Resolution set to fixed

Merged in r3305. Thanks for your work.

Note: See TracTickets for help on using tickets.