Tech Off Thread

6 posts

Forum Read Only

This forum has been made read only by the site admins. No new threads or comments can be added.

hey look, an accurate metronome ticker on WP7

Back to Forum: Tech Off
  • User profile image
    dentaku

    I'm posting this just in case it helps someone some day.

    As some of you (or at least two 9ers Wink ) know my cousin and I wanted to see what it was like to make a WP7 app while he was on his Christmas break. http://channel9.msdn.com/Forums/TechOff/Inconsistent-metronome-in-WP7-app

    After having problems with the metronome being unstable W3bbo pointed us in the direction of making the metronome run in a different thread so it didn't stop for no reason but because it was still just using a simple timer the metronome didn't keep time teribly well.

    Because I'm not a programmer but I deal with pro audio software all the time I thought about how I would do it. While looking at the code we already had, I Right-Clicked on SoundEffect and found that it IS possible to make a sound loop AND modify the start and end loop point of a sound.

            //   loopLength:
            //     Loop length in samples.
            public SoundEffect(byte[] buffer, int offset, int count, int sampleRate, AudioChannels channels, int loopStart, int loopLength);
    

    Now that I knew this information I figured it would be posisble to make a perfect metronome by simply creating a .wav file with lots of silence at the end then modifying loopLength to make the metronome tick faster or slower. Relying on the playback of a 44100Hz 16bit sample makes for amazingly accurate timing compared to using the system timer.

    Here's the code if anyone's interested.
    http://www.box.net/shared/5xn4umhgbg

  • User profile image
    dentaku

    By the way. Could someone test this out on a real phone? I'd love to see if it performs well on actual hardware.

  • User profile image
    Tokter

    Seems to work:

    http://www.youtube.com/watch?v=Jub6xU1ge78

    I'm having problems dragging the slider sometimes, but that might be just me.

  • User profile image
    dentaku

    @Tokter:Ha! It works Smiley

    I'm going to have to figure out how to make the slider "thumb" less picky but it's great to see it runnig on real hardware.

    The next step is to work on the interface anyway.

  • User profile image
    itsnotabug

    interesting hack. since you know the sample length, real time length and sample rate of the empty dummy clip, you can use that for calibration... but how are you using it? is there an event fired when the dummy sample loops?

  • User profile image
    dentaku

    Oh, yeah, I guess I didn't explain it terribly well Smiley

    The metronome is a looping .WAV file with a sound at the start but it also has 4 seconds of silence after the initial tick sound. This way you just move the end loop point of the sample and it ticks faster or slower.

    Imagine grabbing the right loop marker on this sample (that's the actual metronome sample we used) and moving it to the left. The loop will be shorter so the metronome will tick faster.Generic Forum Image

    In the code, the vertical slider modifies int loopLength to create he same effect.

    Like you I did think about maybe looping a silent dummy clip and using it for accurate timing for other applications.

    , itsnotabug wrote

    interesting hack. since you know the sample length, real time length and sample rate of the empty dummy clip, you can use that for calibration... but how are you using it? is there an event fired when the dummy sample loops?

     

Conversation locked

This conversation has been locked by the site admins. No new comments can be made.