12-29-2020, 03:25 PM (This post was last modified: 12-30-2020, 02:25 AM by solid.)
When the "new" tone generator is called many times it is switched off while the program continues measuring (see post https://phyphox.org/forums/showthread.ph...07#pid2207). I do not think it is something new, it was observed with previous versions of phyphox. The number of points before the switching off depends of the frequency value.
This was probably the most annoying bug to test I have ever seen as I had to actually run the tone generator for about 20 minutes to hear when it fails and I had to do so every time I tried something. But the solution is simple and to me somewhat satisfyingly "low level".
Ths short version: The problem occurs on Android and maybe 32bit iPhones (i.e. the iPhone 5s of those supporting phyphox). It is independent of how often you set the frequency, but happens after an exact number of periods - even on the built in tone generator experiment.
In detail, the problem was that there was an integer overflow while calculating the index for the sine lookup table. Instead of calculating the sine function for each sample (which would mean 48000 sines per second - and that is not a quick and simple calculation) phyphox generates a table of 4096 pre-calculated sine values (thanks to sine's symmetry we could do with a fourth of this, but the implementation is easier this way). When generating the tone we then need to calculate the index of these values, which simply means that instead of calculating a phase from 0 to 2pi, we calculate an integer phase from 0 to 4095. And since it is cyclic, we just calculate an absurdly large number and map it to the 0 to 4095 range with the modulo function. And this absurdly large number hit the maximum of a signed 32bit integer of 2^31-1.
In terms of the tone generator, this means that limit is reached after (2^31-1)/48000 periods. So, if you try the default frequency of the included tone generator at 440 Hz, the tone will stop after 1192 seconds (almost 20 minutes). If you set it to 100 Hz it works for over an hour and if you set it to 8738Hz it breaks after exactly one minute.
The good news is that this is an easy fix included in the next update (probably another beta). The bad news is that this will be a while since it is a rather niche problem and the first change since we published the last beta version just before Christmas. Unfortunately, there is not much you can do about it except for trying to work around the problem by finishing the measurement with fewer total periods (I know, a very strange and hard to control limitation) or pausing the measurement, saving the current state and re-opening the state to continue from there. You might also be able to use two or more tone generators as the phase is tracked for each generator individually (using a different tone generator for different frequency range while keeping the others at a frequency of zero), but this is quite certainly not worth the hassle.
01-04-2021, 04:40 PM (This post was last modified: 01-04-2021, 09:13 PM by solid.)
Thank you, Sebastian.
I supposed something like this. But there is another problem with the tone generator of probably different origin. When I clean the data the generator does not restart and I have to quit the program to make it working again.
01-07-2021, 04:28 PM (This post was last modified: 01-07-2021, 04:30 PM by Sebastian Staacks.)
Sorry, forgot to enable the subscription to this thread...
Do you mean after it turned off after a long run? That is to be expected. The phase is not stored in the data buffers of the experiment but in the instance of the experiment class that is created when the experiment is loaded, so it is not reset when you clear the buffer.
Edit:
BTW: Seems like my estimate for a fix was way to pessimistic. I will release a new beta as soon as you confirm that this is not an additional bug
I have verified once more..
- You just start measurements and you do not like something, so you press "trash" to clear buffers without pressing "pause".
- Clean up puts the program to pause, but if you press "run" nothing happens.
- To restart the measurements you have to press "pause" and then "run" again. Going out of the program is not necessary.