Saturday, November 5, 2011

an idea reconstruction

At some point, having already functional code is good and even perfect,
however try to understand precisely big idea implemented:
    synchronized void updateAudio(int tstates, int value) {
        tstates = tstates - audiotstates;
        audiotstates += tstates;
        float time = tstates;

        synchronized (beeper) {
            if (time + timeRem > spf) {
                level += ((spf - timeRem) / spf) * value;
                time -= spf - timeRem;
                lastLevel = (lastLevel + level) >>> 1;
                beeper[bufp++] = lastLevel;
            } else {
                timeRem += time;
                level += (time / spf) * value;
                return;
            }

            while (time > spf) {
                lastLevel = (lastLevel + value) >>> 1;
                beeper[bufp++] = lastLevel;
                time -= spf;
            }
        }

        // calculamos el nivel de sonido de la parte residual de la muestra
        // para el prуximo cambio de estado
        level = (int) (value * (time / spf));
        timeRem = time;
    }

 Now, can you write the own implementation?

2 comments:

  1. You've got a real device why poking with emulator?

    ReplyDelete
  2. real device needs some improvements :)

    on emulators, this implementation IMHO is cleanest and simplest...

    tiny and algorithmically interesting...

    ideas from and into what modulations?

    ReplyDelete