/
BPPlayer_min.js
38 lines (36 loc) · 12.1 KB
/
BPPlayer_min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/*
JavaScript Flod 1.0
2011/11/30
Christian Corti
Neoart Costa Rica
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
This work is licensed under the Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License.
To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/ or send a letter to
Creative Commons, 171 Second Street, Suite 300, San Francisco, California, 94105, USA.
*/
(function(){function k(i){return Object.create(null,{index:{value:i,writable:!0},next:{value:null,writable:!0},channel:{value:null,writable:!0},enabled:{value:0,writable:!0},restart:{value:0,writable:!0},note:{value:0,writable:!0},period:{value:0,writable:!0},sample:{value:0,writable:!0},samplePtr:{value:0,writable:!0},sampleLen:{value:0,writable:!0},synth:{value:0,writable:!0},synthPtr:{value:0,writable:!0},arpeggio:{value:0,writable:!0},autoArpeggio:{value:0,writable:!0},autoSlide:{value:0,writable:!0},
vibrato:{value:0,writable:!0},volume:{value:0,writable:!0},volumeDef:{value:0,writable:!0},adsrControl:{value:0,writable:!0},adsrPtr:{value:0,writable:!0},adsrCtr:{value:0,writable:!0},lfoControl:{value:0,writable:!0},lfoPtr:{value:0,writable:!0},lfoCtr:{value:0,writable:!0},egControl:{value:0,writable:!0},egPtr:{value:0,writable:!0},egCtr:{value:0,writable:!0},egValue:{value:0,writable:!0},fxControl:{value:0,writable:!0},fxCtr:{value:0,writable:!0},modControl:{value:0,writable:!0},modPtr:{value:0,
writable:!0},modCtr:{value:0,writable:!0},initialize:{value:function(){this.channel=null;this.enabled=0;this.samplePtr=this.sample=this.period=this.note=this.restart=0;this.sampleLen=2;this.synth=0;this.synthPtr=-1;this.modCtr=this.modPtr=this.modControl=this.fxCtr=this.fxControl=this.egValue=this.egCtr=this.egPtr=this.egControl=this.lfoCtr=this.lfoPtr=this.lfoControl=this.adsrCtr=this.adsrPtr=this.adsrControl=this.volumeDef=this.volume=this.vibrato=this.autoSlide=this.autoArpeggio=this.arpeggio=
0}}})}window.neoart.createBPPlayer=function(i){i=createAmigaPlayer(i);Object.defineProperties(i,{id:{value:"BPPlayer"},tracks:{value:[],writable:!0},patterns:{value:[],writable:!0},samples:{value:[],writable:!0},length:{value:0,writable:!0},buffer:{value:[],writable:!0},voices:{value:[],writable:!0},trackPos:{value:0,writable:!0},patternPos:{value:0,writable:!0},nextPos:{value:0,writable:!0},jumpFlag:{value:0,writable:!0},repeatCtr:{value:0,writable:!0},arpeggioCtr:{value:0,writable:!0},vibratoPos:{value:0,
writable:!0},initialize:{value:function(){var c=0,e=this.voices[0];this.core_initialize();this.timer=6;this.tick=1;this.repeatCtr=this.jumpFlag=this.nextPos=this.patternPos=this.trackPos=0;this.arpeggioCtr=1;for(this.vibratoPos=0;128>c;++c)this.buffer[c]=0;for(;e;)e.initialize(),e.channel=this.mixer.channels[e.index],e.samplePtr=this.mixer.loopPtr,e=e.next}},reset:{value:function(){for(var c,e,b,d=this.voices[0];d;){if(!(0>d.synthPtr)){b=d.index<<5;e=d.synthPtr+32;for(c=d.synthPtr;c<e;++c)this.mixer.memory[c]=
this.buffer[b++]}d=d.next}}},loader:{value:function(c){var e=0,b,d=0,g,f;this.title=c.readString(26);b=c.readString(4);if("BPSM"==b)this.version=m;else{b=b.substr(0,3);if("V.2"==b)this.version=n;else if("V.3"==b)this.version=j;else return;c.position=29;f=c.readUnsignedByte()}for(this.length=c.readUnsignedShort();16>++e;){b=this.createSample();if(255==c.readUnsignedByte())b.synth=1,b.table=c.readUnsignedByte(),b.pointer=b.table<<6,b.length=c.readUnsignedShort()<<1,b.adsrControl=c.readUnsignedByte(),
b.adsrTable=c.readUnsignedByte()<<6,b.adsrLen=c.readUnsignedShort(),b.adsrSpeed=c.readUnsignedByte(),b.lfoControl=c.readUnsignedByte(),b.lfoTable=c.readUnsignedByte()<<6,b.lfoDepth=c.readUnsignedByte(),b.lfoLen=c.readUnsignedShort(),this.version<j?(c.readByte(),b.lfoDelay=c.readUnsignedByte(),b.lfoSpeed=c.readUnsignedByte(),b.egControl=c.readUnsignedByte(),b.egTable=c.readUnsignedByte()<<6,c.readByte(),b.egLen=c.readUnsignedShort(),c.readByte(),b.egDelay=c.readUnsignedByte(),b.egSpeed=c.readUnsignedByte(),
b.fxSpeed=1,b.modSpeed=1,b.volume=c.readUnsignedByte(),c.position+=6):(b.lfoDelay=c.readUnsignedByte(),b.lfoSpeed=c.readUnsignedByte(),b.egControl=c.readUnsignedByte(),b.egTable=c.readUnsignedByte()<<6,b.egLen=c.readUnsignedShort(),b.egDelay=c.readUnsignedByte(),b.egSpeed=c.readUnsignedByte(),b.fxControl=c.readUnsignedByte(),b.fxSpeed=c.readUnsignedByte(),b.fxDelay=c.readUnsignedByte(),b.modControl=c.readUnsignedByte(),b.modTable=c.readUnsignedByte()<<6,b.modSpeed=c.readUnsignedByte(),b.modDelay=
c.readUnsignedByte(),b.volume=c.readUnsignedByte(),b.modLen=c.readUnsignedShort());else if(c.position--,b.synth=0,b.name=c.readString(24),b.length=c.readUnsignedShort()<<1,b.length){if(b.loop=c.readUnsignedShort(),b.repeat=c.readUnsignedShort()<<1,b.volume=c.readUnsignedShort(),b.loop+b.repeat>=b.length)b.repeat=b.length-b.loop}else b.pointer--,b.repeat=2,c.position+=6;this.samples[e]=b}b=this.length<<2;this.tracks=[];this.tracks.length=b;for(e=0;e<b;++e){g=this.createStep();g.pattern=c.readUnsignedShort();
g.soundTranspose=c.readByte();g.transpose=c.readByte();if(g.pattern>d)d=g.pattern;this.tracks[e]=g}b=d<<4;this.patterns=[];this.patterns.length=b;for(e=0;e<b;++e)d=this.mixer.createRow(),d.note=c.readByte(),d.sample=c.readUnsignedByte(),d.effect=d.sample&15,d.sample=(d.sample&240)>>4,d.param=c.readByte(),this.patterns[e]=d;this.mixer.store(c,f<<6);for(e=0;16>++e;)if(b=this.samples[e],!(b.synth||0==b.length))b.pointer=this.mixer.store(c,b.length),b.loopPtr=b.pointer+b.loop}},process:{value:function(){var c,
e,b,d,g,f=this.mixer.memory,h,a=this.voices[0];this.arpeggioCtr=--this.arpeggioCtr&3;for(this.vibratoPos=++this.vibratoPos&7;a;){c=a.channel;a.period+=a.autoSlide;c.period=a.vibrato?a.period+(o[this.vibratoPos]/a.vibrato>>0):a.period;c.pointer=a.samplePtr;c.length=a.sampleLen;if(a.arpeggio||a.autoArpeggio)d=a.note,0==this.arpeggioCtr?d+=((a.arpeggio&240)>>4)+((a.autoArpeggio&240)>>4):1==this.arpeggioCtr&&(d+=(a.arpeggio&15)+(a.autoArpeggio&15)),c.period=a.period=l[d+35],a.restart=0;if(a.synth){d=
this.samples[a.sample];if(a.adsrControl&&0==--a.adsrCtr&&(a.adsrCtr=d.adsrSpeed,e=128+f[d.adsrTable+a.adsrPtr]>>2,c.volume=e*a.volume>>6,++a.adsrPtr==d.adsrLen&&(a.adsrPtr=0,1==a.adsrControl)))a.adsrControl=0;if(a.lfoControl&&0==--a.lfoCtr&&(a.lfoCtr=d.lfoSpeed,e=f[d.lfoTable+a.lfoPtr],d.lfoDepth&&(e=e/d.lfoDepth>>0),c.period=a.period+e,++a.lfoPtr==d.lfoLen&&(a.lfoPtr=0,1==a.lfoControl)))a.lfoControl=0;if(!(0>a.synthPtr)){if(a.egControl&&0==--a.egCtr){a.egCtr=d.egSpeed;e=a.egValue;a.egValue=128+f[d.egTable+
a.egPtr]>>3;if(a.egValue!=e)if(h=(a.index<<5)+e,b=a.synthPtr+e,a.egValue<e){e-=a.egValue;for(g=b-e;b>g;)f[--b]=this.buffer[--h]}else{e=a.egValue-e;for(g=b+e;b<g;)f[b++]=~this.buffer[h++]+1}if(++a.egPtr==d.egLen&&(a.egPtr=0,1==a.egControl))a.egControl=0}switch(a.fxControl){case 1:if(0==--a.fxCtr){a.fxCtr=d.fxSpeed;b=a.synthPtr;g=a.synthPtr+32;for(e=0<b?f[b-1]:0;b<g;)e=e+f[b+1]>>1,f[b++]=e}break;case 2:h=(a.index<<5)+31;g=a.synthPtr+32;e=d.fxSpeed;for(b=a.synthPtr;b<g;++b)this.buffer[h]<f[b]?f[b]-=
e:this.buffer[h]>f[b]&&(f[b]+=e),h--;break;case 3:case 5:h=a.index<<5;g=a.synthPtr+32;e=d.fxSpeed;for(b=a.synthPtr;b<g;++b)this.buffer[h]<f[b]?f[b]-=e:this.buffer[h]>f[b]&&(f[b]+=e),h++;break;case 4:h=a.synthPtr+64;g=a.synthPtr+32;e=d.fxSpeed;for(b=a.synthPtr;b<g;++b)f[h]<f[b]?f[b]-=e:f[h]>f[b]&&(f[b]+=e),h++;break;case 6:if(0==--a.fxCtr){a.fxControl=0;a.fxCtr=1;h=a.synthPtr+64;g=a.synthPtr+32;for(b=a.synthPtr;b<g;++b)f[b]=f[h++]}}if(a.modControl&&0==--a.modCtr&&(a.modCtr=d.modSpeed,f[a.synthPtr+
32]=f[d.modTable+a.modPtr],++a.modPtr==d.modLen&&(a.modPtr=0,1==a.modControl)))a.modControl=0}}a=a.next}if(0==--this.tick){this.tick=this.timer;for(a=this.voices[0];a;){c=a.channel;a.enabled=0;g=this.tracks[(this.trackPos<<2)+a.index];h=this.patterns[this.patternPos+(g.pattern-1<<4)];d=h.note;b=h.effect;e=h.param;if(d){a.autoArpeggio=a.autoSlide=a.vibrato=0;if(10!=b||0==(e&240))d+=g.transpose;a.note=d;a.period=l[d+35];a.restart=13>b?a.volumeDef=1:0;d=h.sample;if(0==d)d=a.sample;if(10!=b||0==(e&15))d+=
g.soundTranspose;if(13>b&&(!a.synth||a.sample!=d))a.sample=d,a.enabled=1}switch(b){case 0:a.arpeggio=e;break;case 1:a.volume=e;a.volumeDef=0;if(this.version<j||!a.synth)c.volume=a.volume;break;case 2:this.tick=this.timer=e;break;case 3:this.mixer.filter.active=e;break;case 4:a.period-=e;a.arpeggio=0;break;case 5:a.period+=e;a.arpeggio=0;break;case 6:this.version==j?a.vibrato=e:repeatCtr=e;break;case 7:if(this.version==j)this.nextPos=e,this.jumpFlag=1;else if(0==this.repeatCtr)this.trackPos=e;break;
case 8:a.autoSlide=e;break;case 9:a.autoArpeggio=e;if(this.version==j&&(a.adsrPtr=0,0==a.adsrControl))a.adsrControl=1;break;case 11:a.fxControl=e;break;case 13:a.autoArpeggio=e;a.fxControl^=1;a.adsrPtr=0;if(0==a.adsrControl)a.adsrControl=1;break;case 14:a.autoArpeggio=e;a.adsrPtr=0;if(0==a.adsrControl)a.adsrControl=1;break;case 15:a.autoArpeggio=e}a=a.next}if(this.jumpFlag)this.trackPos=this.nextPos,this.patternPos=this.jumpFlag=0;else if(16==++this.patternPos&&(this.patternPos=0,++this.trackPos==
this.length))this.trackPos=0,this.mixer.complete=1;for(a=this.voices[0];a;){c=a.channel;if(a.enabled)c.enabled=a.enabled=0;if(0!=a.restart&&-1<a.synthPtr){h=a.index<<5;g=a.synthPtr+32;for(b=a.synthPtr;b<g;++b)f[b]=this.buffer[h++];a.synthPtr=-1}a=a.next}for(a=this.voices[0];a;){if(0!=a.restart){c=a.channel;c.period=a.period;a.restart=0;d=this.samples[a.sample];if(d.synth){a.synth=1;a.egValue=0;a.adsrPtr=a.lfoPtr=a.egPtr=a.modPtr=0;a.adsrCtr=1;a.lfoCtr=d.lfoDelay+1;a.egCtr=d.egDelay+1;a.fxCtr=d.fxDelay+
1;a.modCtr=d.modDelay+1;a.adsrControl=d.adsrControl;a.lfoControl=d.lfoControl;a.egControl=d.egControl;a.fxControl=d.fxControl;a.modControl=d.modControl;c.pointer=a.samplePtr=d.pointer;c.length=a.sampleLen=d.length;if(a.adsrControl){e=128+f[d.adsrTable]>>2;if(a.volumeDef)a.volume=d.volume,a.volumeDef=0;c.volume=e*a.volume>>6}else c.volume=a.volumeDef?d.volume:a.volume;if(a.egControl||a.fxControl||a.modControl){a.synthPtr=d.pointer;b=a.index<<5;g=a.synthPtr+32;for(h=a.synthPtr;h<g;++h)this.buffer[b++]=
f[h]}}else a.synth=a.lfoControl=0,0>d.pointer?(a.samplePtr=this.mixer.loopPtr,a.sampleLen=2):(c.pointer=d.pointer,c.volume=a.volumeDef?d.volume:a.volume,2!=d.repeat?(a.samplePtr=d.loopPtr,c.length=a.sampleLen=d.repeat):(a.samplePtr=this.mixer.loopPtr,a.sampleLen=2,c.length=d.length));c.enabled=a.enabled=1}a=a.next}}}},createSample:{value:function(){var c=this.mixer.createSample();Object.defineProperties(c,{synth:{value:0,writable:!0},table:{value:0,writable:!0},adsrControl:{value:0,writable:!0},adsrTable:{value:0,
writable:!0},adsrLen:{value:0,writable:!0},adsrSpeed:{value:0,writable:!0},lfoControl:{value:0,writable:!0},lfoTable:{value:0,writable:!0},lfoDepth:{value:0,writable:!0},lfoLen:{value:0,writable:!0},lfoDelay:{value:0,writable:!0},lfoSpeed:{value:0,writable:!0},egControl:{value:0,writable:!0},egTable:{value:0,writable:!0},egLen:{value:0,writable:!0},egDelay:{value:0,writable:!0},egSpeed:{value:0,writable:!0},fxControl:{value:0,writable:!0},fxDelay:{value:0,writable:!0},fxSpeed:{value:0,writable:!0},
modControl:{value:0,writable:!0},modTable:{value:0,writable:!0},modLen:{value:0,writable:!0},modDelay:{value:0,writable:!0},modSpeed:{value:0,writable:!0}});return c}},createStep:{value:function(){return Object.create(null,{pattern:{value:0,writable:!0},soundTranspose:{value:0,writable:!0},transpose:{value:0,writable:!0}})}}});i.buffer=new Int32Array(128);i.voices[0]=k(0);i.voices[0].next=i.voices[1]=k(1);i.voices[1].next=i.voices[2]=k(2);i.voices[2].next=i.voices[3]=k(3);return Object.seal(i)};var m=
1,n=2,j=3,l=[6848,6464,6080,5760,5440,5120,4832,4576,4320,4064,3840,3616,3424,3232,3040,2880,2720,2560,2416,2288,2160,2032,1920,1808,1712,1616,1520,1440,1360,1280,1208,1144,1080,1016,960,904,856,808,760,720,680,640,604,572,540,508,480,452,428,404,380,360,340,320,302,286,270,254,240,226,214,202,190,180,170,160,151,143,135,127,120,113,107,101,95,90,85,80,76,72,68,64,60,57],o=[0,64,128,64,0,-64,-128,-64]})();