Notice: Welcome to TinyChan, an account has automatically been created and assigned to you, you don't have to register or log in to use the board, but don't clear your cookies unless you have set a memorable name and password. Alternatively, you can restore your ID. The use of this site requires cookies to be enabled; please cease browsing this site if you don't consent.

TinyChan

New reply in topic: Bytebeat/Floatbeat/Funcbeat

You are not recognized as the original poster of this topic.

:

You are required to fill in a captcha for your first 5 posts. Sorry, but this is required to stop people from posting while drunk. Please be responsible and don't drink and post!
If you receive this often, consider not clearing your cookies.

Please familiarise yourself with the rules and markup syntax before posting.


Replying to Calculating the sample rate.…

This apparently only works fine with Dollchan's bytebeat player, but Greggman's is fucking buggy as shit.
Type: Funcbeat
let ticks=0,start=0,
    seconds=3, //until calculation
    sampleRate,
    oscT=0; //the time for oscillator
const TAU=Math.PI*2;
function main(t){
  let freq=440;
  oscT=(oscT+(freq/sampleRate))%1;
  return(t%2<1?Math.sin(oscT*TAU):Math.sin(t*freq*TAU))*.5;
}
return time=>{
  if(time<.1){ //Reset on playback.
    ticks=0;sampleRate=undefined;
  }
  if(sampleRate!==undefined)
    return main(time); //Play main function if there's a sample rate.
  if(ticks===0)
    start=time; //Set start at current time.
  ticks++;
  if(time-start>=seconds) //Check if specified duration has elapsed.
    sampleRate=Math.max(ticks/Math.max(1e-4,time-start),1); //Divide ticks by elapsed duration to get the sample rate.
  return(Math.random()-.5)*.1; //Play noise if there's no calculated sample rate.
};