Bool poly_done; I64 start_buf_num; U0 (*fp_task_end_cb)(); U0 (*fp_old_fill_buf)(SND_OUT_CONTAINER *buf,I64 buf_num)=NULL; U0 PolyFillBuf(SND_OUT_CONTAINER *buf,I64 buf_num) { //Gets called by HD Audio task -- $LK,"HDAudioTask","MN:HDAudioTask"$(). //Note: the buffer is in uncached memory //so you might want to avoid multiple //accesses due to slow speed. (If you were //to add a bunch of waveforms together, you //might want to do it in a cached buffer //and copy it once.) I64 j,m,r; F64 t,d; if (poly_done) return; t=ToF64((buf_num-start_buf_num)*(SND_BUF_LEN/SND_OCHANNELS))/SND_SAMPLE_RATE; j=0; while (j4.0) { if (0.908.0) { if (0.7012.0) { if (0.3016.0) m+=0.3*MAX_I32*Caw(t,1.0/6)*Sin(440.0*(2*ã)*t); } } } //Samples are 24-bit, placed in upper 24 bits of an I32. m*=snd_vol; buf[j++]=ToI64(m*d)&0xFFFFFF00; //Left buf[j++]=ToI64(m*(1.0-d))&0xFFFFFF00; //Right t+=1.0/SND_SAMPLE_RATE; } } U0 PolyTaskEndCB() { poly_done=TRUE; fp_snd_fill_buf=fp_old_fill_buf; if (fp_task_end_cb) (*fp_task_end_cb)(); else Exit; } U0 PolyPhonic() { if (snd_dev!=SD_HD_AUDIO) { "Only works for HD Audio.\n"; return; } poly_done=FALSE; fp_task_end_cb=Fs->task_end_cb; Fs->task_end_cb=&PolyTaskEndCB; //Catch or Kill() task start_buf_num=snd_obuf_num; fp_old_fill_buf=fp_snd_fill_buf; fp_snd_fill_buf=&PolyFillBuf; try #if IncludeDepth<2 PressAKey; #else View; #endif catch { //Catch , but pass it on to next higher handler. fp_snd_fill_buf=fp_old_fill_buf; Fs->task_end_cb=fp_task_end_cb; } poly_done=TRUE; fp_snd_fill_buf=fp_old_fill_buf; Fs->task_end_cb=fp_task_end_cb; } //This is so I can use this file stand alone //or as a component of a program. #if IncludeDepth<2 PolyPhonic; #endif