def title	"KRChip"
def version	"1.0.0"
def description	"Kobo Redux Chip Sound Theme"
def author	"David Olofson"
def copyright	"Copyright 2016 David Olofson"
def license	"GPL"
def a2sversion	"1.9.1"


  //////////////////////////////////
 // Master section
//////////////////////////////////

export import "master.a2s"


  //////////////////////////////////
 // Game sound effects
//////////////////////////////////

export import "sfx.a2s"


  //////////////////////////////////
 // UI sound effects
//////////////////////////////////

export import "uisfx.a2s"


  //////////////////////////////////
 // Music
//////////////////////////////////

TitleSong()
{
	struct {
		wtosc o1;	wtosc o1b
		wtosc o2;	wtosc o2b
		env o3e;	wtosc o3
		wire o3e.out o3.a
	}
	o1.w pulse30; o1b.w pulse40
	o2.w saw; o2b.w saw
	o3.w noise

	!base (rand 6n quant 1n)

	//Intro
	o1.p (base - 36n1); o1b.p (o1.p + 0n2); set
	o1.a .15; o1b.a .15
	d 1000

	o2.p (base - 12n); o2b.p (o2.p + 8n05); set
	o2.a .2; o2b.a .2; ramp o2.a 4000; ramp o2b.a 4000
	d 2000

	-o2b.p 1n; ramp o2b.p 1000
	d 3000

	o2.a 0; o2b.a 0
	@o3.p 3; o3e.mode o3e.IEXP3
	d 2000

	for {
		// Calculate harmony
		o1.p (base - 36n1); o1b.p (o1.p + 0n2)
		o2.p (base + 3n + (rand 7n quant 4n) - 12n)
		o2b.p (o2.p + 7n05)
		set

		// 1
		@o3.p (rand .5)
		@o3e.target .6; o3e.target 0; ramp o3e.target 4000
		o1.a .3; o1b.a .3
		o2.a .2; o2b.a .2
		d 2000

		// 2
		@o3.p (1 + rand .5)
		@o3e.target .5; o3e.target 0; ramp o3e.target 4000
		o1.a .1; o1b.a .1
		o2.a .1; o2b.a .1
		d 2000

		// 3
		@o3.p (2 + rand .5)
		@o3e.target .3; o3e.target 0; ramp o3e.target 4000
		o1.a .2; o1b.a .2
		o2.a 0; o2b.a 0
		d 2000

		// 4
		@o3.p (3 + rand .5)
		@o3e.target .25; o3e.target 0; ramp o3e.target 4000
		base (rand 6n quant 1n)
		!nb (base - 36n1)
		200 {
			+o1.p (nb - o1.p * .02); o1b.p (o1.p + 0n2)
			d 10
		}
	}
}

export S_TITLESONG()
{
	struct {
		inline 0 1
		fbdelay 1 2
		panmix 2 >
	}
	fbdelay 900;	fbgain .3
	ldelay 976;	lgain .2
	rdelay 1133;	rgain .2
	vol .5
	set
	1:TitleSong
	end
.stop	vol 0;	d 1000
	kill 1
	1() {
		force stop
	}
}


IngameSong()
{
	struct {
		wtosc o1
		wtosc o2
		wtosc o3
	}

	o1.w noise; o2.w noise; o3.w noise
	o1.p 0; o2.p 1; o3.p 3; set

	for {
		o1.p (rand 1 - .5); o2.p (rand 2); o3.p (rand 2 + 2)
		o1.a (rand .4); o2.a (rand .2); o3.a (rand .1)
		d 3000
	}
}

export S_INGAMESONG1()
{
	struct {
		inline 0 2
		fbdelay 2 2
		panmix 2 >
	}
	fbdelay 1500; fbgain .5
	ldelay 1333; lgain .5
	rdelay 1444; rgain .5
	vol .1
	set
	1:IngameSong
	end
.stop	vol 0;	d 1000
	kill 1
	1() {
		force stop
	}
}
export def S_INGAMESONG2 S_INGAMESONG1
export def S_INGAMESONG3 S_INGAMESONG1
export def S_INGAMESONG4 S_INGAMESONG1
export def S_INGAMESONG5 S_INGAMESONG1
