示例#1
0
func main() {

	aArgs := base.GetArgs(map[string]int{})
	sCurrentDir, _ := os.Getwd()

	base.Dump(aArgs)
	base.Dump(sCurrentDir)

	oStream := audio.NewStream()

	var iSampleRate = 44100

	var oRand = rand.New(rand.NewSource(time.Now().Unix()))

	var cSamplesWritten = oStream.Start(iSampleRate, time.Duration(100)*time.Millisecond)
	defer oStream.Stop()

	var oStartTime = time.Now()

	//var iCooldownSamples = iSampleRate * 44 / 100;
	//var oCooldownDuration = (1000 * time.Duration(iCooldownSamples) / time.Duration(iSampleRate)) * time.Millisecond;
	var iNextPlayStart = 0
	base.Dump(time.Now())
	for {
		var iSamplesWritten = <-cSamplesWritten
		if iSamplesWritten > iNextPlayStart-5*iSampleRate {
			var aSound = SoundA(iSampleRate, time.Duration(2)*time.Second/time.Duration(4), 16, 32)
			for iKey := range aSound {
				var nWavePart = float64(iKey) / float64(len(aSound))
				var nVolume = 0.75 + 0.25*float32(math.Sin(math.Pi*nWavePart))
				aSound[iKey] = nVolume * aSound[iKey]
			}
			for iS := 0; iS < len(aSound); iS++ {
			}
			if true || oRand.Intn(32) > 0 {
				oStream.Play(iNextPlayStart, &aSound)
			}
			iNextPlayStart += len(aSound)
		}
		var oTimePassed = time.Now().Sub(oStartTime)
		if oTimePassed > time.Duration(1)*time.Hour {
			break
		}
		//time.Sleep(time.Duration(50) * time.Millisecond);
	}
	base.Dump(time.Now())

	/*oStream.Play(0, aSound);
	  oStream.Play(0, aSound);*/

	/*for {
	        //aSound = []float32{-1, -1, -1, -1, 1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1};
	//base.Dump("play");
	        //oStream.PlayNow(aSound);
	        time.Sleep(time.Duration(500) * time.Millisecond);
	    }*/

	time.Sleep(time.Second)

}
示例#2
0
func main() {

	aArgs := base.GetArgs(map[string]int{})
	sCurrentDir, _ := os.Getwd()

	base.Dump(aArgs)
	base.Dump(sCurrentDir)

	oStream := audio.NewStream()

	var iSampleRate = 44100

	var iMinWaveSamples = iSampleRate / 32
	var iMaxWaveSamples = iSampleRate / 16

	var nWavePart = float64(0)
	aSound := make([]float32, 64*iSampleRate)
	rand.Seed(time.Now().Unix())
	var iSoundAt = 0
	for iSoundAt < len(aSound) {
		var iWaveSamples = iMinWaveSamples + rand.Intn(iMaxWaveSamples-iMinWaveSamples)
		if iWaveSamples > len(aSound)-iSoundAt {
			iWaveSamples = len(aSound) - iSoundAt
		}
		for iWS := 0; iWS < iWaveSamples; iWS++ {
			nWavePart = float64(iWS) / float64(iWaveSamples)
			aSound[iSoundAt+iWS] = float32(0.8) * float32(math.Sin(math.Pi*nWavePart))
			if nWavePart < 0.5 {
				aSound[iSoundAt+iWS] = 1
			} else {
				aSound[iSoundAt+iWS] = -1
			}
		}
		iSoundAt += iWaveSamples
	}
	//base.Dump(aSound);
	oStream.Play(0, aSound)

	oStream.Start(iSampleRate)

	time.Sleep(time.Duration(100000) * time.Second)

}
示例#3
0
func main() {

	aArgs := base.GetArgs(map[string]int{"v": 1, "mode": 1})
	sCurrentDir, _ := os.Getwd()

	base.Dump(aArgs)
	base.Dump(sCurrentDir)

	var nVolume float32 = 1.0
	if len(aArgs["v"]) > 0 {
		var nVolume64, _ = strconv.ParseFloat(aArgs["v"][0], 32)
		nVolume = float32(nVolume64)
	}
	base.Dump("nVolume = " + strconv.FormatFloat(float64(nVolume), 'f', 4, 32))

	oStream := audio.NewStream()
	oStream.SetVolume(nVolume)

	var iSampleRate = 44100

	//if _, bSet := aArgs["mode"]; !bSet {
	//	aArgs["mode"] = []string{"a"};
	//}
	//var sMode = aArgs["mode"];

	var cSamplesWritten = oStream.Start(iSampleRate, time.Duration(100)*time.Millisecond)
	defer oStream.Stop()

	var sDuration = "1h"
	if len(aArgs[""]) > 0 {
		sDuration = aArgs[""][0]
	}
	var oDuration, errParse = time.ParseDuration(sDuration)
	if errParse != nil {
		oDuration = time.Duration(60) * time.Minute
	}
	base.Dump(oDuration)

	fSound := func(iSampleRate int) []float32 {
		return SoundA(iSampleRate, time.Duration(2)*time.Second, 16, 32)
	}
	if len(aArgs["mode"]) > 0 && aArgs["mode"][0] == "b" {
		fSound = func(iSampleRate int) []float32 {
			return SoundB(iSampleRate /*, time.Duration(2) * time.Second*/, 16, 32)
		}
	}

	var iNextPlayStart = 0
	var oStartTime = time.Now()
	var oLastLoggedTime = time.Time{}
	var iTotalSamples = int(float64(iSampleRate) * oDuration.Seconds())
	var iSamplesPushed = 0

	for {
		var iSamplesWritten = <-cSamplesWritten
		if iSamplesWritten > iNextPlayStart-5*iSampleRate {
			var oNow = time.Now()
			if oNow.Sub(oLastLoggedTime) > (time.Duration(1) * time.Minute) {
				base.Dump(time.Now())
				oLastLoggedTime = oNow
			}
			var aSound = fSound(iSampleRate)
			for iKey := range aSound {
				var nWavePart = float64(iKey) / float64(len(aSound))
				var nVolume = 0.75 + 0.25*float32(math.Sin(math.Pi*nWavePart))
				aSound[iKey] = nVolume * aSound[iKey]
			}
			var iSamplesLeft = iTotalSamples - iSamplesPushed
			if iSamplesLeft < 0 {
				break
			}
			if iSamplesLeft < len(aSound) {
				for iS := iSamplesLeft; iS < len(aSound); iS++ {
					aSound[iS] = 0
				}
			}
			oStream.Play(iNextPlayStart, &aSound)
			iSamplesPushed += len(aSound)
			iNextPlayStart += len(aSound)
		}
		var oTimePassed = time.Now().Sub(oStartTime)
		if oTimePassed > oDuration {
			break
		}
		time.Sleep(time.Duration(50) * time.Millisecond)
	}

	time.Sleep(time.Second)

}
示例#4
0
func main() {

	aArgs := base.GetArgs(map[string]int{})
	sCurrentDir, _ := os.Getwd()

	base.Dump(aArgs)
	base.Dump(sCurrentDir)

	oStream := audio.NewStream()

	var iSampleRate = 44100

	var oRand = rand.New(rand.NewSource(time.Now().Unix()))

	var cSamplesWritten = oStream.Start(iSampleRate, time.Duration(100)*time.Millisecond)
	defer oStream.Stop()

	var oStartTime = time.Now()

	//var iCooldownSamples = iSampleRate * 44 / 100;
	//var oCooldownDuration = (1000 * time.Duration(iCooldownSamples) / time.Duration(iSampleRate)) * time.Millisecond;
	var sDuration = "1h"
	if len(aArgs[""]) > 0 {
		sDuration = aArgs[""][0]
	}
	var oDuration, errParse = time.ParseDuration(sDuration)
	if errParse != nil {
		oDuration = time.Duration(60) * time.Minute
	}
	base.Dump(oDuration)

	var oImage = image.NewImage(20000, 200)
	oImage.FillRect(0, 0, oImage.Width(), oImage.Height(), image.NewColor(255, 255, 255, 255))
	oImage.DrawPoint(10, 10, image.NewColor(255, 0, 0, 255))

	var iNextPlayStart = 0
	for {
		var iSamplesWritten = <-cSamplesWritten
		if iSamplesWritten > iNextPlayStart-5*iSampleRate {
			base.Dump(time.Now())
			var aSound = SoundA(iSampleRate, time.Duration(2)*time.Second/time.Duration(8), 16, 32)
			for iKey := range aSound {
				var nWavePart = float64(iKey) / float64(len(aSound))
				var nVolume = 0.75 + 0.25*float32(math.Sin(math.Pi*nWavePart))
				//nVolume = float32(1.0);
				aSound[iKey] = nVolume * aSound[iKey]
			}
			// for iS := 0; iS < len(aSound); iS ++ {}
			if true || oRand.Intn(32) > 0 {
				oStream.Play(iNextPlayStart, &aSound)
				drawSound(oImage, &aSound, iNextPlayStart, 8)
			}
			iNextPlayStart += len(aSound)
		}
		var oTimePassed = time.Now().Sub(oStartTime)
		if oTimePassed > oDuration {
			break
		}
		time.Sleep(time.Duration(50) * time.Millisecond)
	}

	/*oStream.Play(0, aSound);
	  oStream.Play(0, aSound);*/

	/*for {
	        //aSound = []float32{-1, -1, -1, -1, 1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1};
	//base.Dump("play");
	        //oStream.PlayNow(aSound);
	        time.Sleep(time.Duration(500) * time.Millisecond);
	    }*/

	time.Sleep(time.Second)

}