Hi
I am trying to use the clock module as a timer to build a metronome. To test things out I set the timer to 1000s ms and each time the event occurs I play a sound (the sound mp3 file is about 100ms long)
What I find is that when I compared to my computer's seconds clock, there is a lag in time. In other words, the AI2's clock timer seems to get out of phase with the computer's clock after about 50s.
I modified an old (unpublished) extension that I almost forgot.
Run this app (timer with a metronome sound) against a chronometer. It shouldn't lose a single millisecond (even if it's been running for hours).
I want to play a sound every 250ms. I have a timer that fires every 250ms. I verified that it was counting 4 every 1second so the timer is firing correctly. Now I want to play a sound every 250 ms so I get 4 beats every second. It is the same sound and is in .wav format. I have uploaded the source file to the sound component and set the source file at the start.
The problem is the interval between sounds is not uniform. It stutters. If I set the timer so that it plays a sound every 1second, it seems to sound correct.
The sound file is only 50ms long. There is seems to be some internal delay that is causing non-unformity when I play at intervals less than 1000msec. The shorter the duration, the worse it is.
I have set the minimum interval to be 10ms.
The Clock component is not accurate and the Sound component takes some time to trigger.
What exactly is the purpose? What should be achieved?
How long should the 250ms beats be played?
What could probably be done would be to create a 1 sec track with four 250ms sounds and loop it using the TaifunPlayer extension (audio format: OGG).
Post a test aia (including the sound).
Anke: Thanks for merging. I thought of starting a new thread since it concerned specifically sound generation but yes, it is related to the metronome hobby project I am working on.
I have the timer working correctly but the sound appears to be non-uniform when bpm is set to 120 i.e. 2 beats per second.
I have a fast counter at 100ms marking time and the audio file is 50ms
I have attached the aia file. I could not upload the audio file which is .wav format but you can substitute any sound you want.
Thanks a lot for your help. Looks like you modified my code to make it work. Can you please attach the aia file so I could download and try it out.
Also what is a TaifunPlayer? Where do I get it and its documentation?
Also how do I convert my .wav file to a .ogg file?
Thanks for your help.
If I understand you right, for each metronome bpm setting, I need to source the corresponding ogg file and use Taifun player to loop which will operate independently of the timer interrupt? And the sounds in each ogg file should be spaced just right so that timing is correct?
This assumes that I have a prepopulated list of metronome settings and corresponding ogg files.
If I want any arbitrary integer value between 60 and 120, I have to generate and store 61 different ogg files?
I am not as familiar with timer interrupts and the player so I am learning by building a metronome which I can use for my music practice. Sure, I can download one among many out there but it is more satisfying to use one that I built (with help from the community, of course
As I said before, the point is to create a metronome. You can google what a metronome is. If you want to keep a certain rhythm, a metronome can help achieve it and you can pretty much input any integer value (upto a reason) for beats per minute. There are also many free metronome apps on Google app store that take an integer value and work pretty well. The actual BPM depends on the music written indicated by the tempo.
I was testing it with a few values of BPM to see how the timer and the player works. While looping with a discrete set of ogg files is a good idea if you have a few values (and is a useful tool to have in my toolbox), for arbitrary integer inputs within a range this method would not be practical.
Based on all the discussion so far, looks like AppInventor has certain limitations which makes the creation of a general purpose metronome metronome not possible.
Contrary to appearances, the built-in clock can be accurate. You just have to approach it differently. Try this project witchout extensions and check its accuracy. metronom.aia (6.5 KB)
and it works as long as the timer interval is high enough. But for many problems this is a possible solution to bypass the inaccuracy (which, however, is inherent in the system).