static int print_budget(void) { struct tm *stime; int monthly_budget, daily_budget, spent, budget_today, remaining, next_day; int ret; if((ret = read_db(&monthly_budget, &spent)) != EXIT_SUCCESS) return ret; stime = local_time(); daily_budget = monthly_budget / days_this_month(); budget_today = monthly_budget * stime->tm_mday / days_this_month(); remaining = budget_today - spent; if(remaining >= 0) { printf("%02d.%02d.%04d; %d;\n", stime->tm_mday, stime->tm_mon + 1, stime->tm_year + 1900, remaining); } else if(spent < monthly_budget) { next_day = days_this_month() - (monthly_budget - spent) / daily_budget; if(spent % daily_budget == 0) next_day++; printf("%02d.%02d.%4d;\n", next_day, stime->tm_mon + 1, stime->tm_year + 1900); } else { if(stime->tm_mon++ > 11) { stime->tm_mon = 0; stime->tm_year++; } printf("01.%02d.%4d;\n", stime->tm_mon + 1, stime->tm_year + 1900); } return EXIT_SUCCESS; }
mixed cmd(string timezone) { string *parts, year, time, tz; int offset, x, hour, min, sec; if(!timezone || !valid_timezone(timezone)){ timezone = this_player()->GetProperty("timezone"); } if(!timezone || !valid_timezone(timezone)) timezone = local_time()[9]; offset = TIME_D->GetOffset(timezone); offset += EXTRA_TIME_OFFSET; if(query_os_type() != "windows" ) x = offset * 3600; else x = 0; time = ctime( time() + x ); x = sizeof(parts = explode(time, " ")); year = parts[x - 1]; sscanf(parts[x - 2], "%d:%d:%d", hour, min, sec); message("info", sprintf("Time: %d:%s%d %s\nDate: %s, %s", (hour>12 ? (hour-12) : (hour == 0 ? 12 : hour)), (min < 10 ? "0" : ""), min, ((hour>11 && hour) ? "pm" : "am"), implode(parts[0..(x-3)], " "), year), this_player() ); return 1; }
// /// Adjust for local time zone and Daylight Savings Time. // ClockTy TTime::LocalSecs() const { TTime local_time( Sec - _timezone ); if (local_time.IsDST()) local_time.Sec += SECONDS_IN_HOUR; return local_time.Sec; }
void op_sleep() { /* Stack: |=============================|=============================| | BEFORE | AFTER | |=============================|=============================| top | Interval or time of day | | |=============================|=============================| */ DESCRIPTOR * descr; long int time_now; long int wake_time; time_now = local_time(); descr = e_stack - 1; k_get_value(descr); /* 0460 */ if (descr->type == STRING) (void)k_str_to_num(descr); if (descr->type == STRING) { if (!iconv_time_conversion()) /* Converted to internal format time of day */ { GetInt(descr); wake_time = time_now - (time_now % 86400) + descr->data.value; /* 0460 */ if (wake_time < time_now) wake_time += 86400; /* Tomorrow */ } } else /* Sleep specified number of seconds */ { GetInt(descr); wake_time = time_now + descr->data.value; } k_dismiss(); while(local_time() < wake_time) { if (my_uptr->events) process_events(); if (k_exit_cause & K_INTERRUPT) break; Sleep(1000); if ((process.break_inhibits == 0) && break_pending) break; } return; }
void device_execute_interface::pulse_input_line_and_vector(int irqline, int vector, const attotime &duration) { assert(duration > attotime::zero); set_input_line_and_vector(irqline, ASSERT_LINE, vector); attotime target_time = local_time() + duration; m_scheduler->timer_set(target_time - m_scheduler->time(), timer_expired_delegate(FUNC(device_execute_interface::irq_pulse_clear), this), irqline); }
void op_date() { /* The windows time uses 00:00:00 on 1/1/70 as its datum. We must adjust this so that 31/12/67 is day zero. */ InitDescr(e_stack, INTEGER); (e_stack++)->data.value = ((local_time() + date_adjustment) / 86400L) + 732; }
void op_pause() { /* Stack: |=============================|=============================| | BEFORE | AFTER | |=============================|=============================| top | Timeout (seconds) | | |=============================|=============================| */ DESCRIPTOR * descr; long int timeout; descr = e_stack - 1; GetInt(descr); timeout = descr->data.value; timeout = (timeout > 0)?(local_time() + timeout):0; k_dismiss(); while(!(my_uptr->flags & USR_WAKE)) { if (my_uptr->events) process_events(); if (k_exit_cause & K_INTERRUPT) break; if ((process.break_inhibits == 0) && break_pending) break; sleep(1); if ((timeout) && (local_time() >= timeout)) { process.status = ER_TIMEOUT; goto exit_op_pause; } } process.status = 0; my_uptr->flags &= ~USR_WAKE; exit_op_pause: return; }
static int days_this_month(void) { struct tm *stime; int ret; int daysinmonth[12] = { 31, 0, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; stime = local_time(); ret = daysinmonth[stime->tm_mon]; if(stime->tm_mon == 1) { ret = days_in_febuary(stime->tm_year + 1900); } return ret; }
static int print_budget_verbose(int summary) { struct tm *stime; int monthly_budget, daily_budget, spent, budget_today, remaining, next_day; int ret; if((ret = read_db(&monthly_budget, &spent)) != EXIT_SUCCESS) return ret; stime = local_time(); daily_budget = monthly_budget / days_this_month(); budget_today = monthly_budget * stime->tm_mday / days_this_month(); remaining = budget_today - spent; if(summary) { printf("--------------------------------------\n"); printf(" JUNK FOOD SUMMARY:\n"); printf("--------------------------------------\n"); printf(" Today is %02d.%02d.%4d.\n", stime->tm_mday, stime->tm_mon + 1, stime->tm_year + 1900); printf(" Your monthly budget is: %d.%02d " CURRENCY "\n", BREAKUP(monthly_budget)); printf(" You spent: %d.%02d " CURRENCY "\n", BREAKUP(spent)); printf(" Budget until today: %d.%02d " CURRENCY "\n", BREAKUP(budget_today)); printf("--------------------------------------\n\n"); } printf("You can spend "); if(remaining >= 0) { printf("%d.%02d " CURRENCY "\n\n", BREAKUP(remaining)); } else if(spent < monthly_budget) { next_day = days_this_month() - (monthly_budget - spent) / daily_budget; if(spent % daily_budget == 0) next_day++; printf("again on %02d.%02d.%4d\n\n", next_day, stime->tm_mon + 1, stime->tm_year + 1900); } else { printf("again next month.\n\n"); } return EXIT_SUCCESS; }
void op_timedate() { char s[20+1]; long int timenow; short int hour; short int min; short int sec; STRING_CHUNK * p; long int n; short int i; timenow = local_time() + date_adjustment; /* Form time of day values */ n = timenow % 86400L; hour = (short int)(n / 3600); n = n % 3600; min = (short int)(n / 60); sec = (short int)(n % 60); /* Build result string */ sprintf(s, "%02d:%02d:%02d %s", (int)hour, (int)min, (int)sec, day_to_ddmmmyyyy((timenow / 86400L) + 732)); UpperCaseString(s); InitDescr(e_stack, STRING); p = e_stack->data.str.saddr = s_alloc(20L, &i); p->string_len = 20; p->bytes = 20; p->ref_ct = 1; memcpy(p->data, s, 20); e_stack++; }
int main(int argc, char *argv[]) { int i, g, p, r; int param1; float fpmops; float mflops; int isok1 = 0; int isok2 = 0; int count1 = 0; float errors[2][10]; int erdata[5][10]; float newdata = 0.999999f; float one; for (i=1; i<9; i=i+2) { if (argc > i) { switch (toupper(argv[i][0])) { case 'K': param1 = 0; if (argc > i+1) { sscanf(argv[i+1],"%d", ¶m1); if (param1 > 0) words = param1 * 1000; } break; case 'S': param1 = 0; if (argc > i+1) { sscanf(argv[i+1],"%d", ¶m1); if (param1 > 0) section = param1; if (section > 3) section = 3; } break; case 'L': param1 = 0; if (argc > i+1) { sscanf(argv[i+1],"%d", ¶m1); if (param1 > 0) testlog = param1; if (testlog > 99) testlog = 0; } break; case 'M': param1 = 0; if (argc > i+1) { sscanf(argv[i+1],"%d", ¶m1); if (param1 > 0) passes = param1; passes = passes * 4; } break; } } } sprintf (testcpu, "test%d", testlog); sprintf (logfile, "log%d.txt", testlog); local_time(); outfile = fopen(logfile,"a+"); if (outfile == NULL) { printf (" Cannot open results file \n\n"); printf(" Press Enter\n"); g = getchar(); exit (0); } if (section == 1) { opwd = 2; } if (section == 2) { opwd = 8; } if (section == 3) { opwd = 32; } getDetails(); printf(" %s %s\n", heading, timeday); if (testlog < 2) { for (i=0; i<10; i++) { printf("%s\n", configdata[i]); } } printf("\n"); fprintf (outfile, "\n"); fprintf (outfile, "##############################################\n\n"); for (i=1; i<10; i++) { fprintf(outfile, "%s \n", configdata[i]); } fprintf (outfile, "\n"); fprintf (outfile, "##############################################\n\n"); fprintf(outfile, " %s %s\n", heading, timeday); fprintf(outfile, " %s\n\n", compiler); fprintf(outfile, " Using %d KBytes, %d Operations Per Word, For Approximately %d Minutes\n", 4*words/1000, opwd, passes*loopsecs/60); printf(" Reporting approximately every %d seconds, repeated %d times\n", loopsecs, passes); fprintf(outfile, "\n Pass 4 Byte Ops/ Repeat Seconds MFLOPS First All\n"); fprintf(outfile, " Words Word Passes Results Same\n\n"); printf( "\n System 4 Byte Ops/ Repeat Seconds MFLOPS First All\n"); printf( " Pass Words Word Passes Results Same\n\n"); fflush(outfile); isok1 = 0; size_x = words * sizeof(float); for (p=0; p<passes; p++) { // Allocate arrays for host CPU x_cpu = (float *)_mm_malloc(size_x, 16); if (x_cpu == NULL) { printf(" ERROR WILL EXIT\n"); printf(" Press Enter\n"); g = getchar(); exit(1); } // Data for array for (i=0; i<words; i++) { x_cpu[i] = newdata; } if (p == 0) { start_time(); do { runTests(); end_time(); repeat2 = repeat2 + 1; } while (secs < (float)loopsecs); one = x_cpu[0]; if (one == newdata) { isok2 = 1; isok1 = 1; } } else { start_time(); for (r=0; r<repeat2; r++) { runTests(); } end_time(); } fpmops = (float)words * (float)opwd; mflops = (float)repeats * repeat2 * fpmops / 1000000.0f / (float)secs; // Print results fprintf(outfile, "%7d %9d %5d %8d %10.2f %8.0f ", p+1, words, opwd, repeats * repeat2, secs, mflops); printf("%3d%5d%9d %5d %8d %10.2f %8.0f ", testlog, p+1,words, opwd, repeats * repeat2, secs, mflops); isok1 = 0; for (i=0; i<words; i++) { if (one != x_cpu[i]) { isok1 = 1; if (count1 < 10) { errors[0][count1] = x_cpu[i]; errors[1][count1] = one; erdata[0][count1] = i; erdata[1][count1] = words; erdata[2][count1] = opwd; erdata[3][count1] = repeats * repeat2; count1 = count1 + 1; } } } if (isok1 == 0) { fprintf(outfile, " %13.9f Yes\n", x_cpu[0]); printf(" %13.9f Yes\n", x_cpu[0]); } else { fprintf(outfile, " See later No\n"); printf(" See log No\n"); } fflush(outfile); // Cleanup _mm_free(x_cpu); } local_time(); fprintf(outfile, "\n End at %s\n", timeday); printf("\n End at %s\n", timeday); fprintf(outfile, "\n"); printf("\n"); fprintf(outfile,"\n"); if (isok2 > 0) { fprintf(outfile," ERROR - At least one first result of 0.999999 - no calculations?\n\n"); printf(" ERROR - At least one first result of 0.999999 - no calculations?\n\n"); } if (count1 > 0) { fprintf(outfile," First Unexpected Results\n"); for (i=0; i<count1; i++) { fprintf(outfile,"%7s %9d %5d %8d word %9d was %10.6f not %10.6f\n", testcpu, erdata[1][i], erdata[2][i], erdata[3][i], erdata[0][i], errors[0][i], errors[1][i]); } fprintf(outfile,"\n"); } fclose (outfile); // printf(" Press Enter\n"); // g = getchar(); return 0; }
void set_date(long int new_date) { date_adjustment = (new_date - ((local_time() / 86400L) + 732)) * 86400; }
void op_time() { InitDescr(e_stack, INTEGER); (e_stack++)->data.value = local_time() % 86400L; }
INT32 _appendValue( CHAR delChar, bson_iterator *pIt, CHAR **ppBuffer, INT32 *pCSVSize, BOOLEAN includeBinary, BOOLEAN includeRegex ) { INT32 rc = SDB_OK ; bson_type type = bson_iterator_type( pIt ) ; INT32 tempSize = 0 ; INT32 base64Size = 0 ; INT32 binType = 0 ; CHAR temp[128] = { 0 } ; const CHAR *pTemp = NULL ; CHAR *pBase64 = NULL ; bson_timestamp_t ts; time_t timer ; struct tm psr; if ( type == BSON_DOUBLE || type == BSON_BOOL || type == BSON_NULL || type == BSON_INT || type == BSON_LONG ) { rc = _appendNonString( delChar, pIt, ppBuffer, pCSVSize ) ; if ( rc ) { goto error ; } } else { rc = _appendString( delChar, &delChar, 1, ppBuffer, pCSVSize ) ; if ( rc ) { goto error ; } if ( type == BSON_TIMESTAMP ) { ts = bson_iterator_timestamp( pIt ) ; timer = (time_t)ts.t; local_time( &timer, &psr ) ; tempSize = ossSnprintf ( temp, 64, "%04d-%02d-%02d-%02d.%02d.%02d.%06d", psr.tm_year + 1900, psr.tm_mon + 1, psr.tm_mday, psr.tm_hour, psr.tm_min, psr.tm_sec, ts.i ) ; rc = _appendString( delChar, temp, tempSize, ppBuffer, pCSVSize ) ; if ( rc ) { goto error ; } } else if ( type == BSON_DATE ) { timer = bson_iterator_date( pIt ) / 1000 ; local_time( &timer, &psr ) ; tempSize = ossSnprintf ( temp, 64, "%04d-%02d-%02d", psr.tm_year + 1900, psr.tm_mon + 1, psr.tm_mday ) ; rc = _appendString( delChar, temp, tempSize, ppBuffer, pCSVSize ) ; if ( rc ) { goto error ; } } else if ( type == BSON_UNDEFINED ) { rc = _appendString( delChar, CSV_STR_UNDEFINED, CSV_STR_UNDEFINED_SIZE, ppBuffer, pCSVSize ) ; if ( rc ) { goto error ; } } else if ( type == BSON_MINKEY ) { rc = _appendString( delChar, CSV_STR_MINKEY, CSV_STR_MINKEY_SIZE, ppBuffer, pCSVSize ) ; if ( rc ) { goto error ; } } else if ( type == BSON_MAXKEY ) { rc = _appendString( delChar, CSV_STR_MAXKEY, CSV_STR_MAXKEY_SIZE, ppBuffer, pCSVSize ) ; if ( rc ) { goto error ; } } else if ( type == BSON_CODE ) { pTemp = bson_iterator_code( pIt ) ; rc = _appendString( delChar, pTemp, ossStrlen( pTemp ), ppBuffer, pCSVSize ) ; if ( rc ) { goto error ; } } else if ( type == BSON_STRING || type == BSON_SYMBOL ) { pTemp = bson_iterator_string( pIt ) ; rc = _appendString( delChar, pTemp, ossStrlen( pTemp ), ppBuffer, pCSVSize ) ; if ( rc ) { goto error ; } } else if ( type == BSON_BINDATA ) { if( TRUE == includeBinary ) { rc = _appendString( delChar, CSV_STR_LEFTBRACKET, 1, ppBuffer, pCSVSize ) ; if ( rc ) { goto error ; } binType = (INT32)bson_iterator_bin_type( pIt ) ; tempSize = ossSnprintf ( temp, 64, "%d", binType ) ; rc = _appendString( delChar, &temp, tempSize, ppBuffer, pCSVSize ) ; if ( rc ) { goto error ; } rc = _appendString( delChar, CSV_STR_RIGHTBRACKET, 1, ppBuffer, pCSVSize ) ; if ( rc ) { goto error ; } } pTemp = bson_iterator_bin_data( pIt ) ; tempSize = bson_iterator_bin_len ( pIt ) ; base64Size = getEnBase64Size ( tempSize ) ; pBase64 = (CHAR *)SDB_OSS_MALLOC( base64Size ) ; if( NULL == pBase64 ) { rc = SDB_OOM ; goto error ; } ossMemset( pBase64, 0, base64Size ) ; if ( !base64Encode( pTemp, tempSize, pBase64, base64Size ) ) { rc = SDB_OOM ; goto error ; } rc = _appendString( delChar, pBase64, base64Size - 1, ppBuffer, pCSVSize ) ; if ( rc ) { goto error ; } } else if ( type == BSON_REGEX ) { if( TRUE == includeRegex ) { rc = _appendString( delChar, CSV_STR_BACKSLASH, 1, ppBuffer, pCSVSize ) ; if ( rc ) { goto error ; } } pTemp = bson_iterator_regex( pIt ) ; rc = _appendString( delChar, pTemp, ossStrlen( pTemp ), ppBuffer, pCSVSize ) ; if ( rc ) { goto error ; } if( TRUE == includeRegex ) { rc = _appendString( delChar, CSV_STR_BACKSLASH, 1, ppBuffer, pCSVSize ) ; if ( rc ) { goto error ; } pTemp = bson_iterator_regex_opts( pIt ) ; rc = _appendString( delChar, pTemp, ossStrlen( pTemp ), ppBuffer, pCSVSize ) ; if ( rc ) { goto error ; } } } else if ( type == BSON_OID ) { bson_oid_to_string( bson_iterator_oid( pIt ), temp ) ; rc = _appendString( delChar, temp, 24, ppBuffer, pCSVSize ) ; if ( rc ) { goto error ; } } else { rc = _appendObj( delChar, pIt, ppBuffer, pCSVSize ) ; if ( rc ) { goto error ; } } rc = _appendString( delChar, &delChar, 1, ppBuffer, pCSVSize ) ; if ( rc ) { goto error ; } } done: SAFE_OSS_FREE( pBase64 ) ; return rc ; error: goto done ; }
void main() { long thisThread; double TimeUsed; double totScore; double mwips; double totMwips; double total[4][10]; double timeTot[4]; int answers[4][10]; int g, i, j, t; int threads; int passThreads[4]; int count = 10; int duration = 5; char errorMsg[100]; n1 = 12*x100; n2 = 14*x100; n3 = 345*x100; n4 = 210*x100; n5 = 32*x100; n6 = 899*x100; n7 = 616*x100; n8 = 93*x100; passThreads[0] = 1; passThreads[1] = 2; passThreads[2] = 4; passThreads[3] = 8; FILE *outfile; outfile = fopen("MP-WHETS.txt","a+"); if (outfile == NULL) { printf ("Cannot open results file \n\n"); printf(" Press Enter\n"); g = getchar(); exit (0); } printf("\n"); getDetails(); local_time(); printf(" ##########################################\n"); fprintf (outfile, " #####################################################\n"); printf ("\nFrom File /proc/cpuinfo\n"); printf("%s\n", configdata[0]); printf ("\nFrom File /proc/version\n"); printf("%s\n", configdata[1]); printf("\n MP-Whetstone Benchmark %s %s\n", version, timeday); printf(" Using 1, 2, 4 and 8 Threads\n\n"); printf(" MFLOPS MFLOPS If Fixpt Cos MFLOPS Equal Exp MWIPS\n"); printf(" 1 2 MOPS MOPS MOPS 3 MOPS MOPS\n\n"); fprintf(outfile, "\n MP-Whetstone Benchmark %s %s\n", version, timeday); fprintf(outfile, " Using 1, 2, 4 and 8 Threads\n\n"); fprintf(outfile, " MWIPS MFLOPS MFLOPS MFLOPS Cos Exp Fixpt If Equal\n"); fprintf(outfile, " 1 2 3 MOPS MOPS MOPS MOPS MOPS\n\n"); do { TimeUsed=0; thisThread = 0; start_time(); for (test=1; test<9; test++) { pthread_create(&tid[thisThread], attrt, whetstones, (void *)thisThread); pthread_join(tid[thisThread], NULL); } TimeUsed = secs; count = count - 1; if (TimeUsed > 0.2) count = 0; else repeatPasses = repeatPasses * 5; } while (count > 0); if (TimeUsed > 0) repeatPasses = (int)((SPDP)(duration * repeatPasses) / TimeUsed); if (repeatPasses < 1) repeatPasses = 1; for(t=0; t<4; t++) { threads = passThreads[t]; printf("%2dT ", threads); fprintf(outfile, "%2dT ", threads); fflush(stdout); fflush(outfile); timeTot[t] = 0; TimeUsed = 0; for (test=1; test<9; test++) { totScore = 0; start_time(); for (thisThread=1; thisThread<threads+1; thisThread++) { pthread_create(&tid[thisThread], attrt, whetstones, (void *)thisThread); } for (thisThread=1; thisThread<threads+1; thisThread++) { pthread_join(tid[thisThread], NULL); } end_time(); TimeUsed = TimeUsed + secs; for (i=1; i<threads+1; i++) { totScore = totScore + score[i][test]; } printf("%7.1f", totScore); fflush(stdout); } timeTot[t] = TimeUsed; for (i=1; i<threads+1; i++) { score[i][9] = 0.0; } totMwips = 0; for (i=1; i<threads+1; i++) { mwips=(double)(repeatPasses) * (double)(x100) / (10 * timec[i][9]); score[i][9] = mwips; totMwips = totMwips + mwips; } printf("%7.1f\n", totMwips); fflush(stdout); results[t][9] = 0.0; for (j=1; j<10; j++) { total[t][j] = 0.0; for (i=1; i<threads+1; i++) { total[t][j] = total[t][j] + score[i][j]; } } sprintf(errorMsg, " All calculations produced consistent numeric results"); for (j=1; j<10; j++) { for (i=1; i<threads+1; i++) { if (results[i][j] != results[1][j]) { sprintf(errorMsg, " Numeric results incorrect"); } } } fprintf(outfile, "%7.1f%7.1f%7.1f%7.1f%6.1f%6.1f%7.1f%7.1f%7.1f\n", total[t][9], total[t][1], total[t][2], total[t][6], total[t][5], total[t][8], total[t][4], total[t][3], total[t][7]); fflush(stdout); fflush(outfile); } printf("\n Overall Seconds %6.2f 1T, %6.2f 2T, %6.2f 4T, %6.2f 8T\n\n%s\n\n", timeTot[0], timeTot[1], timeTot[2], timeTot[3], errorMsg); fprintf(outfile, "\n Overall Seconds %6.2f 1T, %6.2f 2T, %6.2f 4T, %6.2f 8T\n\n%s\n\n", timeTot[0], timeTot[1], timeTot[2], timeTot[3], errorMsg); fflush(stdout); fflush(outfile); fprintf (outfile, "\nSYSTEM INFORMATION\n\nFrom File /proc/cpuinfo\n"); fprintf (outfile, "%s \n", configdata[0]); fprintf (outfile, "\nFrom File /proc/version\n"); fprintf (outfile, "%s \n", configdata[1]); fprintf (outfile, "\n"); fflush(outfile); char moredata[1024]; printf("Type additional information to include in MP-MFLOPS.txt - Press Enter\n"); if (fgets (moredata, sizeof(moredata), stdin) != NULL) fprintf (outfile, "Additional information - %s\n", moredata); fflush(stdout); fflush(outfile); fclose(outfile); return; }
/****************************************************************************** **函数名称: plog_write **功 能: 将日志信息写入缓存 **输入参数: ** fp: 文件指针 ** level: 日志级别 ** dump: 内存地址 ** dumplen: 需打印的地址长度 ** msg: 日志内容 **输出参数: NONE **返 回: 0:success !0:failed **实现描述: **注意事项: **作 者: # Qifeng.zou # 2014.09.11 # ******************************************************************************/ static int plog_write(plog_cycle_t *log, int level, const void *dump, int dumplen, const char *errmsg, const struct timeb *ctm) { struct tm loctm; local_time(&ctm->time, &loctm); /* 获取当前系统时间 */ switch (level) { case LOG_LEVEL_FATAL: { /* @进程号|YYYYMMDD|HH:MM:SS.MM|级别提示 日志内容 */ fprintf(log->fp, "@%d|%04d%02d%02d|%02d:%02d:%02d.%03d|FATAL %s\n", log->pid, loctm.tm_year+1900, loctm.tm_mon+1, loctm.tm_mday, loctm.tm_hour, loctm.tm_min, loctm.tm_sec, ctm->millitm, errmsg); break; } case LOG_LEVEL_ERROR: { /* @进程号|YYYYMMDD|HH:MM:SS.MM|级别提示 日志内容 */ fprintf(log->fp, "@%d|%04d%02d%02d|%02d:%02d:%02d.%03d|ERROR %s\n", log->pid, loctm.tm_year+1900, loctm.tm_mon+1, loctm.tm_mday, loctm.tm_hour, loctm.tm_min, loctm.tm_sec, ctm->millitm, errmsg); break; } case LOG_LEVEL_WARN: { /* @进程号|YYYYMMDD|HH:MM:SS.MM|级别提示 日志内容 */ fprintf(log->fp, "@%d|%04d%02d%02d|%02d:%02d:%02d.%03d|WARN %s\n", log->pid, loctm.tm_year+1900, loctm.tm_mon+1, loctm.tm_mday, loctm.tm_hour, loctm.tm_min, loctm.tm_sec, ctm->millitm, errmsg); break; } case LOG_LEVEL_INFO: { /* @进程号|YYYYMMDD|HH:MM:SS.MM|级别提示 日志内容 */ fprintf(log->fp, "@%d|%04d%02d%02d|%02d:%02d:%02d.%03d|INFO %s\n", log->pid, loctm.tm_year+1900, loctm.tm_mon+1, loctm.tm_mday, loctm.tm_hour, loctm.tm_min, loctm.tm_sec, ctm->millitm, errmsg); break; } case LOG_LEVEL_DEBUG: { /* @进程号|YYYYMMDD|HH:MM:SS.MM|级别提示 日志内容 */ fprintf(log->fp, "@%d|%04d%02d%02d|%02d:%02d:%02d.%03d|DEBUG %s\n", log->pid, loctm.tm_year+1900, loctm.tm_mon+1, loctm.tm_mday, loctm.tm_hour, loctm.tm_min, loctm.tm_sec, ctm->millitm, errmsg); break; } case LOG_LEVEL_TRACE: { /* @进程号|YYYYMMDD|HH:MM:SS.MM|级别提示 日志内容 */ fprintf(log->fp, "@%d|%04d%02d%02d|%02d:%02d:%02d.%03d|TRACE %s\n", log->pid, loctm.tm_year+1900, loctm.tm_mon+1, loctm.tm_mday, loctm.tm_hour, loctm.tm_min, loctm.tm_sec, ctm->millitm, errmsg); break; } default: { /* @进程号|YYYYMMDD|HH:MM:SS.MM|级别提示 日志内容 */ fprintf(log->fp, "@%d|%04d%02d%02d|%02d:%02d:%02d.%03d|OTHER %s\n", log->pid, loctm.tm_year+1900, loctm.tm_mon+1, loctm.tm_mday, loctm.tm_hour, loctm.tm_min, loctm.tm_sec, ctm->millitm, errmsg); break; } } /* 打印DUMP数据 */ if ((NULL != dump) && (dumplen > 0)) { plog_print_dump(log, dump, dumplen); } return 0; }
int main(int argc, char **argv) { if (argc < 3) { printf( "Resample\n" "========\n" "Sample rate conversion utility\n" "This utility is a part of AC3Filter project (http://ac3filter.net)\n" "Copyright (c) 2008-2011 by Alexander Vigovsky\n" "\n" "Usage:\n" " > resample input.wav output.wav [-r[ate]:n] [-q[uality]:n] [-a[ttenuation]:n] [-d[ither]]\n" "\n" "Options:\n" " input.wav - file to convert\n" " output.wav - file to write the result to\n" " rate - new sample rate (deafult: 48000)\n" " quality - passband width (default: 0.99)\n" " attenuation - stopband attenuation in dB (default: 100)\n" " dither - dither the result\n" "\n" "Example:\n" " > resample input.wav output.wav -r:44100 -q:0.999 -a:150\n" " Passband width in this example is 0.999. This means that only uppper 22Hz\n" " of the destination bandwidth (22028Hz - 22050Hz) will be distorted.\n" " Note, that attenuation is large here. Such attenuation is only sensible for\n" " at least 24bit files.\n"); return 0; } const char *input_filename = argv[1]; const char *output_filename = argv[2]; int sample_rate = 48000; double q = 0.99; double a = 100; bool do_dither = false; for (int iarg = 3; iarg < argc; iarg++) { // -r[ate] if (is_arg(argv[iarg], "r", argt_num) || is_arg(argv[iarg], "rate", argt_num)) { sample_rate = (int)arg_num(argv[iarg]); continue; } // -q[uality] if (is_arg(argv[iarg], "q", argt_num) || is_arg(argv[iarg], "quality", argt_num)) { q = arg_num(argv[iarg]); continue; } // -a[ttenuation] if (is_arg(argv[iarg], "a", argt_num) || is_arg(argv[iarg], "attenuation", argt_num)) { a = arg_num(argv[iarg]); continue; } // -d[ither] if (is_arg(argv[iarg], "d", argt_bool) || is_arg(argv[iarg], "dither", argt_bool)) { do_dither = arg_bool(argv[iarg]); continue; } printf("Error: unknown option: %s\n", argv[iarg]); return 1; } if (sample_rate == 0) { printf("Error: incorrect sample rate\n"); return -1; } WAVSource src(input_filename, block_size); if (!src.is_open()) { printf("Error: cannot open file: %s\n", input_filename); return -1; } WAVSink sink(output_filename); if (!sink.is_open()) { printf("Error: cannot open file: %s\n", output_filename); return -1; } Speakers spk = src.get_output(); Converter iconv(block_size); Converter oconv(block_size); Resample resample; AGC agc(1024); Dither dither; iconv.set_format(FORMAT_LINEAR); oconv.set_format(src.get_output().format); if (!resample.set(sample_rate, a, q)) { printf("Error: cannot do sample rate conversion with given parameters\n", output_filename); return -1; } FilterChain chain; chain.add_back(&iconv, "Input converter"); chain.add_back(&resample, "Resample"); if (do_dither && !spk.is_floating_point()) { chain.add_back(&dither, "Dither"); dither.level = 0.5 / spk.level; } chain.add_back(&agc, "AGC"); chain.add_back(&oconv, "Output converter"); Chunk chunk; printf("Conversion %i -> %i\n", src.get_output().sample_rate, sample_rate); printf("0%%\r"); vtime_t t = local_time() + 0.1; while (!src.is_empty()) { src.get_chunk(&chunk); if (!chain.process_to(&chunk, &sink)) { char buf[1024]; chain.chain_text(buf, array_size(buf)); printf("Processing error. Chain dump: %s\n", buf); return -1; } if (local_time() > t) { t += 0.1; double pos = double(src.pos()) * 100 / src.size(); printf("%i%%\r", (int)pos); } } printf("100%%\n"); return 0; }
int main(int argc, char **argv) { if (argc < 3) { printf( "Gain\n" "====\n" "Simple gain tool to amplify or attenuate an audio file.\n" "This utility is a part of AC3Filter project (http://ac3filter.net)\n" "Copyright (c) 2008-2009 by Alexander Vigovsky\n" "\n" "Usage:\n" " > gain input.wav output.wav [-g[ain]:n]\n" "\n" "Options:\n" " input.wav - file to process\n" " output.wav - file to write the result to\n" " -gain - gain to apply\n" "\n" "Example:\n" " > gain a.wav b.wav -gain:-10\n" " Attenuate by 10dB\n" ); return 0; } const char *input_filename = argv[1]; const char *output_filename = argv[2]; double gain = 1.0; ///////////////////////////////////////////////////////////////////////////// // Parse arguments for (int iarg = 3; iarg < argc; iarg++) { // -gain if (is_arg(argv[iarg], "gain", argt_num)) { gain = db2value(arg_num(argv[iarg])); continue; } printf("Error: unknown option: %s\n", argv[iarg]); return -1; } ///////////////////////////////////////////////////////////////////////////// // Open files WAVSource src(input_filename, block_size); if (!src.is_open()) { printf("Error: cannot open file: %s\n", input_filename); return -1; } WAVSink sink(output_filename); if (!sink.is_open()) { printf("Error: cannot open file: %s\n", output_filename); return -1; } Speakers spk = src.get_output(); ///////////////////////////////////////////////////////////////////////////// // Build the chain Converter iconv(block_size); Converter oconv(block_size); iconv.set_format(FORMAT_LINEAR); oconv.set_format(src.get_output().format); Gain gain_filter; AGC agc(1024); gain_filter.gain = gain; FilterChain chain; chain.add_back(&iconv, "Input converter"); chain.add_back(&gain_filter, "Gain"); chain.add_back(&agc, "AGC"); chain.add_back(&oconv, "Output converter"); if (!chain.set_input(spk)) { printf("Error: cannot start processing\n"); return -1; } ///////////////////////////////////////////////////////////////////////////// // Do the job Chunk chunk; printf("0%%\r"); vtime_t t = local_time() + 0.1; while (!src.is_empty()) { src.get_chunk(&chunk); if (!chain.process_to(&chunk, &sink)) { char buf[1024]; chain.chain_text(buf, array_size(buf)); printf("Processing error. Chain dump: %s\n", buf); return -1; } if (local_time() > t) { t += 0.1; double pos = double(src.pos()) * 100 / src.size(); printf("%i%%\r", (int)pos); } } printf("100%%\n"); return 0; }