func main() { var aArgs = base.GetArgs(map[string]int{"tel": 0, "mp3": 0, "gain": 0, "user_uploads": 1, "format": 1, "q": 1}) var sCurrentDir, _ = os.Getwd() _ = sCurrentDir var sBookID = aArgs[""][0] var oStartTime = time.Now() var oPrevTime = time.Now() var iVotesPerLoop = 16 var iVotesCast = 0 for { for iV := 0; iV < iVotesPerLoop-1; iV++ { go vVote(sBookID) } vVote(sBookID) iVotesCast += iVotesPerLoop var oNow = time.Now() var nDeltaSeconds = oNow.Sub(oPrevTime).Seconds() var nPerHour = float64(60*60) * (float64(iVotesPerLoop) / nDeltaSeconds) var sPerHour = strconv.FormatFloat(nPerHour, 'f', 4, 64) var nTotalDeltaSeconds = oNow.Sub(oStartTime).Seconds() var nTotalPerHour = float64(60*60) * (float64(iVotesCast) / nTotalDeltaSeconds) var sTotalPerHour = strconv.FormatFloat(nTotalPerHour, 'f', 4, 64) base.Dump(strconv.Itoa(iVotesCast) + " votes cast") base.Dump("spamming at " + sTotalPerHour + " (" + sPerHour + ") per Hour") oPrevTime = oNow } }
func (oClient *Client) sPost(sUrl string, aData url.Values) string { if oClient.oHttpClient == nil { oClient.vInit() } var oRequest, errA = http.NewRequest("POST", sUrl, bytes.NewBufferString(aData.Encode())) if errA != nil { base.Dump(errA) return "" } oRequest.Header.Add("X-CSRF-Token", oClient.sToken) var oResponse, errB = oClient.oHttpClient.Do(oRequest) if errB != nil { base.Dump(errB) return "" } var aBody, errC = ioutil.ReadAll(oResponse.Body) if errC != nil { base.Dump(errC) return "" } defer oResponse.Body.Close() var sResponse = string(aBody) return sResponse }
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) }
func (oClient *Client) sGet(sUrl string) string { if oClient.oHttpClient == nil { oClient.vInit() } var oRequest, errA = http.NewRequest("GET", sUrl, nil) if errA != nil { base.Dump(errA) return "" } oRequest.Header.Add("X-CSRF-Token", oClient.sToken) var oResponse, errB = oClient.oHttpClient.Do(oRequest) if errB != nil { base.Dump(errB) return "" } var aBody, errC = ioutil.ReadAll(oResponse.Body) if errC != nil { base.Dump(errC) return "" } defer oResponse.Body.Close() var sResponse = string(aBody) return sResponse }
func (oClient *Client) aGetUserPhotos(sUserName string) []Photo { if oClient.oHttpClient == nil { oClient.vInit() } var sUserPageContent = oClient.sGet("http://500px.com/" + sUserName) var aUserID = regexp.MustCompile("data-user-id=\"(\\d+)\"").FindStringSubmatch(sUserPageContent) if aUserID == nil { log.Fatal("could not find data-user-id") } var sUserID = aUserID[1] var iPageLength = 8 var sApiCall = "https://api.500px.com/v1/photos" sApiCall += "?feature=user&sort=created_at&include_states=false" sApiCall += "&user_id=" + sUserID + "&authenticity_token=" + url.QueryEscape(oClient.sToken) sApiCall += "&image_size=5&rpp=" + strconv.Itoa(iPageLength) + "&page=1" var sFirstPageContent = oClient.sGet(sApiCall) //base.Dump(sFirstPageContent); var oFirstPageContent = json.Read(sFirstPageContent) base.Dump(oFirstPageContent.GetI("total_pages")) base.Dump(oFirstPageContent.GetI("total_items")) var iPages = oFirstPageContent.GetI("total_pages") var iPhotos = oFirstPageContent.GetI("total_items") base.Dump(iPhotos) var aPhotos = []Photo{} for iPage := 1; iPage <= iPages; iPage++ { sApiCall = "https://api.500px.com/v1/photos" sApiCall += "?feature=user&sort=created_at&include_states=false" sApiCall += "&user_id=" + sUserID + "&authenticity_token=" + url.QueryEscape(oClient.sToken) sApiCall += "&image_size=5&rpp=" + strconv.Itoa(iPageLength) + "&page=" + strconv.Itoa(iPage) var sData = oClient.sGet(sApiCall) var oData = json.Read(sData) var aDataPhotos = oData.GetA("photos") for _, oDataPhoto := range aDataPhotos { //base.Dump(len(aPhotos)); var oPhoto = Photo{ sID: strconv.Itoa(oDataPhoto.GetI("id")), sUrl: oDataPhoto.GetS("image_url"), sUserID: strconv.Itoa(oDataPhoto.GetI("user_id")), sUserName: oDataPhoto.GetS("user -> username"), oTaken: oParseTime(oDataPhoto.GetS("taken_at")), oCreated: oParseTime(oDataPhoto.GetS("created_at")), } aPhotos = append(aPhotos, oPhoto) } } base.Dump(len(aPhotos)) return aPhotos }
func (oNode *JsonNode) Get(sPath string) *JsonNode { var aHashMap = aHashMap(sPath) var sPathHashed = sPath for sHash, sString := range aHashMap { sPathHashed = strings.Replace(sPathHashed, sString, sHash, -1) } var aPath = strings.Split(sPathHashed, " -> ") var oCurrentNode = oNode for _, sPathPartHashed := range aPath { var sPathPart, bInHashMap = aHashMap[sPathPartHashed] if !bInHashMap { sPathPart = sPathPartHashed } var bObject = oCurrentNode.Type == "object" sPathPart = "\"" + strings.Trim(sPathPart, "\"") + "\"" if bObject { var _, bExists = oCurrentNode.ObjectChildren[sPathPart] if !bExists { base.Dump(sPathPart + " does not exist") var aExistingKeys = []string{} for sKey := range oCurrentNode.ObjectChildren { aExistingKeys = append(aExistingKeys, sKey) } base.Dump(aExistingKeys) base.Dump(oCurrentNode.Value) } if !bExists { oCurrentNode = nil break } oCurrentNode = oCurrentNode.ObjectChildren[sPathPart] } else { var iPathPart, _ = strconv.Atoi(sPathPart) var bExists = len(oCurrentNode.ArrayChildren) > iPathPart if !bExists { base.Dump(sPathPart + " does not exist") base.Dump("length is " + strconv.Itoa(len(oCurrentNode.ArrayChildren))) } if !bExists { oCurrentNode = nil break } oCurrentNode = oCurrentNode.ArrayChildren[iPathPart] } } return oCurrentNode }
func NeverUsed() { var _, _ = strconv.ParseInt("", 0, 0) var _ = regexp.QuoteMeta("") base.Dump("") fmt.Println("") log.Fatal("") }
func print_color(iColor uint32) { iRed := (iColor >> 16) & 0x000000ff iGreen := (iColor >> 8) & 0x000000ff iBlue := (iColor >> 0) & 0x000000ff sRed := strconv.Itoa((int)(iRed)) sGreen := strconv.Itoa((int)(iGreen)) sBlue := strconv.Itoa((int)(iBlue)) base.Dump(sRed + "," + sGreen + "," + sBlue) }
func Dummy() { _ = strconv.Itoa(0) _ = strings.Index("", "") log.Println("") fmt.Printf("") base.Dump("") }
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) }
func vVote(sBookID string) { var oClient = &Client{} var aValues = url.Values{} aValues.Add("book[Item][ASIN]", sBookID) aValues.Add("book[Item][ItemAttributes][author]", "") var sReturn = "" sReturn += oClient.sPost("http://bestbookread.com/books/insert_or_update", aValues) sReturn += oClient.sGet("http://bestbookread.com/books/check_history?book=" + sBookID) base.Dump(sReturn) //return sReturn; }
func oGetVideoData(sVideoID string) (Video, error) { sApiCall := "http://gdata.youtube.com/feeds/api/videos/" + sVideoID + "?v=2" sData, err := sHttpGet(sApiCall) if err != nil { return Video{}, err } oData := XmlVideo{} xml.Unmarshal([]byte(sData), &oData) base.Dump(sApiCall) base.Dump(sData) base.Dump(oData) /*if true { base.Dump(oData); log.Fatal("ID = '" + oData.ID + "'"); }*/ if oData.ID == "" { return Video{}, errors.New("ERROR for " + sVideoID + ":\n" + sData) } oVideo := Video{ sID: oData.ID, sAuthorID: oData.AuthorID, sAuthorName: oData.AuthorName, sTitle: oData.Title, sDescription: oData.Description, oUploaded: oParseYoutubeTime(oData.Uploaded), oPublished: oParseYoutubeTime(oData.Published), oUpdated: oParseYoutubeTime(oData.Updated), } iDurationSeconds, _ := strconv.Atoi(oData.Duration.Seconds) oVideo.oDuration = time.Duration(iDurationSeconds) * time.Second oVideo.aSources, err = aGetVideoSources(oVideo.sID) return oVideo, err }
func (oClient *Client) vInit() { oClient.oHttpClient = &http.Client{Jar: NewJar()} var sDomainContent = oClient.sGet("http://bestbookread.com/") var aToken = regexp.MustCompile("\\<meta content=\"([^\"]+)\" name=\"csrf-token\" /\\>").FindStringSubmatch(sDomainContent) if aToken == nil { base.Dump("could not find csrf-token") } if aToken != nil { oClient.sToken = aToken[1] } //base.Dump(oClient.sToken); }
func main() { aArgs := base.GetArgs(map[string]int{}) sCurrentDir, _ := os.Getwd() base.Dump(aArgs) base.Dump(sCurrentDir) var oRand = rand.New(rand.NewSource(time.Now().Unix())) var iRandomIntRange = 20 var aRandomInts = make([]int, 999) var aInts = map[int]int{} for iI := -iRandomIntRange; iI <= iRandomIntRange; iI++ { aInts[iI] = 0 } base.Dump(aInts) for iKey := range aRandomInts { var iRandomInt = int(oRand.NormFloat64() * float64(iRandomIntRange/2)) aRandomInts[iKey] = iRandomInt if _, bSet := aInts[iRandomInt]; bSet { aInts[iRandomInt]++ } } for iI := -iRandomIntRange; iI <= iRandomIntRange; iI++ { var iCount = aInts[iI] var sBar = "" for iC := 0; iC < iCount; iC++ { sBar += "#" } base.Dump(sBar) } }
func vDownloadPhotos(aPhotos []Photo, sTargetDir string) { os.Mkdir(sTargetDir, os.FileMode(0766)) for iNr, oPhoto := range aPhotos { var aUrlSplit = strings.Split(oPhoto.sUrl, ".") var sExtension = aUrlSplit[len(aUrlSplit)-1] var sFileName = "500px_" sFileName += oPhoto.sUserName + "_" + oPhoto.sUserID sFileName += "_" + sDateTime(oPhoto.oCreated) sFileName += "_" + oPhoto.sID + "." + sExtension var sPhotoTargetDir = sTargetDir + "/" + oPhoto.sUserName var sTarget = sPhotoTargetDir + "/" + sFileName os.Mkdir(sPhotoTargetDir, os.FileMode(0776)) vDownload(oPhoto.sUrl, sTarget) base.Dump("downloaded " + strconv.Itoa(iNr+1) + " / " + strconv.Itoa(len(aPhotos))) } }
func main() { iWidth := int32(WIDTH) iHeight := int32(HEIGHT) var screen = sdl.SetVideoMode(int(iWidth), int(iHeight), 32, sdl.RESIZABLE) if screen == nil { log.Fatal(sdl.GetError()) } iIterationNr := 0 iIterations := int(math.Min(float64(333333), float64((WIDTH)*(HEIGHT)))) iStartNS := time.Now().UnixNano() //mainloop: for { var iX int32 var iY int32 var iColor uint32 for i := 0; i < iIterations; i++ { iX = rand.Int31() % (iWidth) iY = rand.Int31() % (iHeight) iColor = rand.Uint32() iColor &= 0x00ffffff iColor += 0x88000000 draw_point(iX, iY, iColor, screen) //break mainloop; } screen.Flip() iIterationNr++ if iIterationNr%99 == 0 { iIterationNS := time.Now().UnixNano() iDeltaNS := iIterationNS - iStartNS nDeltaS := float64(iDeltaNS) / float64(1000000000) nFPS := float64(iIterationNr) / nDeltaS fmt.Printf("fps: %v\n", nFPS) fmt.Printf("%v x %v\n", screen.W, screen.H) } } base.Dump("") }
func main() { aArgs := base.GetArgs(map[string]int{"?": 0, "r": 0}) _, bHelp := aArgs["?"] bHelp = bHelp || len(aArgs[""]) < 1 if bHelp { base.Dump("usage: \nautoheader [files]") return } _, bRecursive := aArgs["r"] aFiles := aArgs[""] rxC := regexp.MustCompile("\\.c$") aDirs := []string{} aFilesTemp := aFiles aFiles = []string{} for _, sFile := range aFilesTemp { if !base.FileExists(sFile) { log.Fatal("error: file " + sFile + " don't exist") } if base.IsDirectory(sFile) { aDirs = append(aDirs, sFile) } else { if rxC.MatchString(sFile) { aFiles = append(aFiles, sFile) } } } for 0 < len(aDirs) { aDirsTemp := aDirs aDirs = []string{} for _, sDir := range aDirsTemp { aDirFiles, _ := ioutil.ReadDir(sDir) for _, oFile := range aDirFiles { sFile := oFile.Name() if oFile.IsDir() { aDirs = append(aDirs, sDir+"/"+sFile) } else { if rxC.MatchString(sFile) { aFiles = append(aFiles, sDir+"/"+sFile) } } } } if !bRecursive { break } } base.Dump(aFiles) rxF := regexp.MustCompile("\n[^\n]*\\S+ +(\\S+) +\\([^\\)\\;]*\\) {") rxAuto := regexp.MustCompile("\n///#///\n[\\s\\S]+\n///#///\n") aRXSFH := []*regexp.Regexp{ /*regexp.MustCompile("^\n *static ")*/ } aRXSFF := []*regexp.Regexp{regexp.MustCompile("^_")} for _, sFile := range aFiles { sFC := sFile //sFB := rxC.ReplaceAllString(sFC, ".b"); //sContentB := ""; sFH := rxC.ReplaceAllString(sFC, ".h") aContentC, _ := ioutil.ReadFile(sFC) sContentC := string(aContentC) sDeclarations := "" aFunctionHeads := rxF.FindAllStringSubmatch(sContentC, -1) for _, aFunctionHead := range aFunctionHeads { sFunctionHead := aFunctionHead[0] sFunctionName := aFunctionHead[1] bDeclare := true for _, rxSFH := range aRXSFH { if rxSFH.MatchString(sFunctionHead) { bDeclare = false } } for _, rxSFF := range aRXSFF { if rxSFF.MatchString(sFunctionName) { bDeclare = false } } if bDeclare { sDeclarations += strings.Replace(sFunctionHead, "{", ";", 1) } } sDeclarations += "\n" sWrite := "\n///#///\n" + sDeclarations + "\n///#///\n" sContentH := "" if base.FileExists(sFH) { aContentH, _ := ioutil.ReadFile(sFH) sContentH = string(aContentH) } if rxAuto.MatchString(sContentH) { sWrite = rxAuto.ReplaceAllString(sContentH, sWrite) } else { sWrite = sContentH + sWrite } ioutil.WriteFile(sFH, []byte(sWrite), 0644) } }
func Dummy() { base.Dump("") }
func cConvert(sSourceFile, sTargetFile string, nGain float64) (<-chan *ProcessStatus, <-chan float64) { cStatus := make(chan *ProcessStatus) cReplayGain := make(chan float64) go func() { _, errAvconv := exec.LookPath("avconv") if errAvconv != nil { log.Fatal("the program 'avconv' is not installed. please install it and try again.") } _, errLame := exec.LookPath("lame") if errLame != nil { log.Fatal("the program 'lame' is not installed. please install it and try again.") } sWavFile := sSourceFile + ".wav" oCommandWAV := exec.Command("avconv", "-i", sSourceFile, "-vn", sWavFile) errWAV := oCommandWAV.Run() if errWAV != nil { base.Dump("wav error:") log.Fatal(errWAV) } nScale := float64(1) if nGain != 0 { nScale = math.Pow(10, 0.05*nGain) } sScale := strconv.FormatFloat(nScale, 'f', 4, 64) oCommandMP3 := exec.Command("lame", "-b", "320", "--cbr", "--scale", sScale, sWavFile, sTargetFile) oOutStream, errOut := oCommandMP3.StderrPipe() if errOut != nil { log.Fatal(errOut) } defer oOutStream.Close() errStart := oCommandMP3.Start() if errStart != nil { log.Fatal(errStart) } var iChunk int64 = 64 * 1024 aData := make([]byte, iChunk) var iRead int = 0 sAll := "" sPart := "" o1S := time.Second var err error for { iRead, err = oOutStream.Read(aData) if err != nil { break } sAppend := fmt.Sprintf("%s", aData[:iRead]) sAll += sAppend sPart += sAppend oRegExA := regexp.MustCompile(" +(\\d+\\/\\d+) +\\(([^\\)]+)\\%\\)[^\\n]+(\\d+\\:\\d+)[^\\n]+\\n\\-*(\\d+\\:\\d+)\\-+") aMatches := oRegExA.FindAllStringSubmatch(sPart, -1) if len(aMatches) > 0 { aLastMatch := aMatches[len(aMatches)-1] sPercent := aLastMatch[2] sTimeLeft := aLastMatch[3] nPercent, _ := strconv.ParseFloat(sPercent, 64) cStatus <- &ProcessStatus{ nPercent: nPercent, sTimeLeft: sTimeLeft, } sPart = "" } time.Sleep(o1S) } cStatus <- &ProcessStatus{ nPercent: 100, sTimeLeft: "0s", } close(cStatus) oRegExB := regexp.MustCompile("\nReplayGain: (.+)dB\n") aMatches := oRegExB.FindStringSubmatch(sAll) sReplayGain := "+0dB" if len(aMatches) > 1 { sReplayGain = aMatches[1] } nReplayGain, _ := strconv.ParseFloat(sReplayGain, 64) cReplayGain <- nReplayGain close(cReplayGain) // if bGain { // nScale := math.Pow(10, 0.05 * nReplayGain); // sScale := strconv.FormatFloat(nScale, 'f', 4, 64); //base.Dump(nReplayGain); //base.Dump("scale:"); //base.Dump(nScale); //base.Dump(sScale); // sTargetFileBeforeScale := sTargetFile + "_before_gain.mp3"; // os.Rename(sTargetFile, sTargetFileBeforeScale); ////base.Dump([]string{"lame", "--scale", sScale, sTargetFileBeforeScale, sTargetFile}); // oCommandGain := exec.Command("lame", "--scale", sScale, sTargetFileBeforeScale, sTargetFile); // errGain := oCommandGain.Run(); // if errGain != nil { // base.Dump("gain error:"); // log.Fatal(errGain); // } // } os.Remove(sWavFile) }() return cStatus, cReplayGain }
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) }
func Pretext() { base.Dump(0) log.Fatal(strconv.Itoa(1)) }
func Pretext() { base.Dump(strconv.Itoa(1)) }
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) }