BDrum::BDrum() { long defaultdata[] = {0, 0x1000, 0x3000}; Fs = 44100.0; ring.SetT(0.3*Fs); Fbegin=ring.CalcFc(100.0/Fs); Fend=ring.CalcFc(10.0/Fs); Fc = 0; ReadRow(defaultdata); }
bool FDataTableImporterJSON::ReadTable() { if (JSONData.IsEmpty()) { ImportProblems.Add(TEXT("Input data is empty.")); return false; } // Check we have a RowStruct specified if (!DataTable->RowStruct) { ImportProblems.Add(TEXT("No RowStruct specified.")); return false; } TArray< TSharedPtr<FJsonValue> > ParsedTableRows; { const TSharedRef< TJsonReader<TCHAR> > JsonReader = TJsonReaderFactory<TCHAR>::Create(JSONData); if (!FJsonSerializer::Deserialize(JsonReader, ParsedTableRows) || ParsedTableRows.Num() == 0) { ImportProblems.Add(FString::Printf(TEXT("Failed to parse the JSON data. Error: %s"), *JsonReader->GetErrorMessage())); return false; } } // Empty existing data DataTable->EmptyTable(); // Iterate over rows for (int32 RowIdx = 0; RowIdx < ParsedTableRows.Num(); ++RowIdx) { const TSharedPtr<FJsonValue>& ParsedTableRowValue = ParsedTableRows[RowIdx]; TSharedPtr<FJsonObject> ParsedTableRowObject = ParsedTableRowValue->AsObject(); if (!ParsedTableRowObject.IsValid()) { ImportProblems.Add(FString::Printf(TEXT("Row '%d' is not a valid JSON object."), RowIdx)); continue; } ReadRow(ParsedTableRowObject.ToSharedRef(), RowIdx); } DataTable->Modify(true); return true; }
TB303::TB303() { long defaultdata[] = {-1,0,0,0,0,0,0,0}; vco_inc = 0.0; vco_k = 0; vcf_cutoff = 0; vcf_envmod = 0; vcf_reso = 0; vcf_envdecay = 0; vcf_envpos = ENVINC; vcf_a = vcf_b = vcf_d1 = vcf_d2 = 0; vcf_c0 = 0; vcf_e0 = 0; vcf_e1 = 0; vca_mode = 2; vca_a = 0; vca_attack = 1.0 - 0.94406088; vca_decay = 0.99897516; vca_a0 = 0.5; ReadRow(defaultdata); }
// Execute a compiled command and gather the result bool CCommand::Execute(const PDatabase& DB) { n_assert(DB.isvalid()); //!!!only for error msg! n_assert(IsValid()); if (VT.isvalid()) VT->SetModifiedTracking(false); bool Done = false; while (!Done) { switch (sqlite3_step(SQLiteStmt)) { case SQLITE_DONE: Done = true; break; case SQLITE_BUSY: n_sleep(0.0001); break; case SQLITE_ROW: if (VT.isvalid()) ReadRow(); break; case SQLITE_ERROR: SetError(sqlite3_errmsg(DB->GetSQLiteHandle())); FAIL; case SQLITE_MISUSE: { n_error("CCommand::Execute(): sqlite3_step() returned SQLITE_MISUSE!"); FAIL; } default: { n_error("CCommand::Execute(): unknown error code returned from sqlite3_step()"); FAIL; } } } // Reset the command, this clears the bound values n_assert(sqlite3_reset(SQLiteStmt) == SQLITE_OK); if (VT.isvalid()) VT->SetModifiedTracking(true); OK; }
static void ReadATKRaster(FILE * const file, int * const rwidth, int * const rheight, unsigned char ** const destaddrP) { int row, rowlen; /* count rows; byte length of row */ int version; char keyword[6]; int discardid; int objectid; /* id read for the incoming pixel image */ long tc; /* temp */ int width, height; /* dimensions of image */ if (fscanf(file, "\\begindata{raster,%d", &discardid) != 1 || getc(file) != '}' || getc(file) != '\n') pm_error ("input file not Andrew raster object"); fscanf(file, " %d ", &version); if (version < 2) pm_error ("version too old to parse"); { unsigned int options; long xscale, yscale; long xoffset, yoffset, subwidth, subheight; /* ignore all these features: */ fscanf(file, " %u %ld %ld %ld %ld %ld %ld", &options, &xscale, &yscale, &xoffset, &yoffset, &subwidth, &subheight); } /* scan to end of line in case this is actually something beyond V2 */ while (((tc=getc(file)) != '\n') && (tc != '\\') && (tc != EOF)) {} /* read the keyword */ fscanf(file, " %5s", keyword); if (!STREQ(keyword, "bits")) pm_error ("keyword is not 'bits'!"); fscanf(file, " %d %d %d ", &objectid, &width, &height); if (width < 1 || height < 1 || width > 1000000 || height > 1000000) pm_error ("bad width or height"); *rwidth = width; *rheight = height; rowlen = (width + 7) / 8; MALLOCARRAY(*destaddrP, height * rowlen); if (destaddrP == NULL) pm_error("Unable to allocate %u bytes for the input image.", height * rowlen); for (row = 0; row < height; row++) { long c; c = ReadRow(file, *destaddrP + (row * rowlen), rowlen); if (c != '|') { if (c == EOF) pm_error ("premature EOF"); else pm_error ("bad format"); break; } } while (! feof(file) && getc(file) != '\\') {}; /* scan for \enddata */ if (fscanf(file, "enddata{raster,%d", &discardid) != 1 || getc(file) != '}' || getc(file) != '\n') pm_error ("missing end-of-object marker"); }
int ReadILBM (struct IFFHandle * iff, struct Window * window, ULONG Width, ULONG Height, UWORD Depth, BOOL Compression, BOOL masking) { struct RastPort * rp = window->RPort; BYTE * planes[MAX_PLANES]; int t,x,bit,byte,row,pen = 0,lastpen; printf ("ReadILBM iff=%p win=%p Size=%ldx%ld Depth=%d %s%s\n", iff, window, Width, Height, Depth, Compression ? "C":"", masking ? "M":"" ); planes[0] = AllocMem (Width*Depth + ((masking) ? Width : 0), MEMF_ANY); if (!planes[0]) return FALSE; for (t=1; t<Depth; t++) planes[t] = planes[t-1] + Width; if (masking) planes[t] = planes[t-1] + Width; for ( ; t<MAX_PLANES; t++) planes[t] = NULL; for (row=0; row<Height; row++) { if (!ReadRow (iff, planes, Width, Depth, Compression, masking)) { FreeMem (planes[0], Width*Depth + ((masking) ? Width : 0)); return FALSE; } /* printf ("row %d, %08lx\n", row, *(ULONG*)planes[0]); */ lastpen = -1; Move (rp, 0, row); for (x=0; x<Width; x++) { bit = 0x80 >> (x & 7); byte = x / 8; for (pen=t=0; t<Depth; t++) if (planes[t][byte] & bit) pen |= 1L << t; if (lastpen == -1) lastpen = pen; /* SetAPen (rp, pen); WritePixel (rp, x, row); */ if (lastpen != pen) { SetAPen (rp, lastpen); Draw (rp, x+1, row); lastpen = pen; } } SetAPen (rp, pen); Draw (rp, Width, row); } return TRUE; }
/* ReadBigram: load a bigram from given file */ static void ReadMatBigram(LModel *lm,char *fn) { Vector vec; char buf[132]; int P,p,j; float sum,x; LabId id; MatBiLM *matbi; if (trace&T_TIO) printf("\nMB "),fflush(stdout); if(InitSource(fn,&source,LangModFilter)<SUCCESS) HError(8110,"ReadMatBigram: Can't open file %s", fn); vec = CreateVector(&gcheap,MAX_LMID); ReadLMWord(buf);SkipWhiteSpace(&source); id=GetLabId(buf,TRUE); P = ReadRow(vec); if (P<=0 || P >MAX_LMID) HError(8151,"ReadMatBigram: First row invalid (%d entries)",P); matbi=CreateMatBigram(lm,P); matbi->wdlist[1] = id; for (p=1;p<=P;p++) matbi->bigMat[1][p]=vec[p]; id->aux=(Ptr) 1; Dispose(&gcheap,vec); for (sum=0.0, j=1; j<=P; j++) { x = matbi->bigMat[1][j]; if (x<0) HError(8151,"ReadMatBigram: In bigram, entry %d for %s is -ve (%e)", j,buf,x); sum += x; matbi->bigMat[1][j]=((x<MINLARG)?LZERO:log(x)); } if (sum < 0.99 || sum > 1.01) HError(-8151,"ReadMatBigram: Row %d of bigram %s adds up to %f",1,fn,sum); for (p=2; ReadLMWord(buf); p++) { if (trace&T_TIO) { if ((p%25)==0) printf(". "),fflush(stdout); if ((p%800)==0) printf("\n "),fflush(stdout); } if (p>P) HError(8150,"ReadMatBigram: More rows than columns in bigram %s",fn); id=GetLabId(buf,TRUE); if ((int)id->aux != 0) HError(8150,"ReadMatBigram: Duplicated name %s in bigram %s",buf,fn); id->aux = (Ptr) p; matbi->wdlist[p] = id; SkipWhiteSpace(&source); if (ReadRow(matbi->bigMat[p])!=P) HError(8150,"ReadMatBigram: Wrong number of items in row %d",p); for (sum=0.0, j=1; j<=P; j++) { x = matbi->bigMat[p][j]; if (x<0) HError(8151,"ReadMatBigram: In bigram, entry %d for %s is -ve (%e)", j,buf,x); sum += x; matbi->bigMat[p][j]=((x<MINLARG)?LZERO:log(x)); } if (sum < 0.99 || sum > 1.01) HError(-8151,"ReadMatBigram: Row %d of bigram %s adds up to %f",p,fn,sum); } if (P>p) HError(8150,"ReadMatBigram: More columns than rows in bigram %s",fn); if (trace&T_TIO) printf("\n"),fflush(stdout); CloseSource(&source); }