static PyObject * flea_get_auto_setting(PyObject *self, PyObject *args) { int handle = -1; fleaCamera* cam = NULL; const char* prop_name; fleaProperty prop; if (!PyArg_ParseTuple(args, "is", &handle, &prop_name)) return NULL; if (handle >= 0 && handle < NUM_CAMERA_HANDLES && cameras[handle]) { cam = cameras[handle]; if (strcmp(prop_name, "exposure") == 0) { prop = get_exposure(cam); } else if (strcmp(prop_name, "shutter") == 0) { prop = get_shutter(cam); } else if (strcmp(prop_name, "gain") == 0) { prop = get_gain(cam); } else { return NULL; } } else { PyErr_SetString(FleaError, "Invalid Handle"); return NULL; } return Py_BuildValue("iif", prop.autoMode, prop.on, prop.value); }
int TBusTrack::process(nframes_t nframes) { if (m_isMuted || (get_gain() == 0.0f) ) { return 0; } process_pre_sends(nframes); m_pluginChain->process_pre_fader(m_processBus, nframes); m_fader->process(m_processBus, nframes); float panFactor; if ( (m_processBus->get_channel_count() >= 1) && (m_pan > 0) ) { panFactor = 1 - m_pan; Mixer::apply_gain_to_buffer(m_processBus->get_buffer(0, nframes), nframes, panFactor); } if ( (m_processBus->get_channel_count() >= 2) && (m_pan < 0) ) { panFactor = 1 + m_pan; Mixer::apply_gain_to_buffer(m_processBus->get_buffer(1, nframes), nframes, panFactor); } // gain automation curve only understands audio_sample_t** atm // so wrap the process buffers into a audio_sample_t** audio_sample_t* mixdown[m_processBus->get_channel_count()]; for(int chan=0; chan<m_processBus->get_channel_count(); chan++) { mixdown[chan] = m_processBus->get_buffer(chan, nframes); } TimeRef location = m_session->get_transport_location(); TimeRef endlocation = location + TimeRef(nframes, audiodevice().get_sample_rate()); m_fader->process_gain(mixdown, location, endlocation, nframes, m_processBus->get_channel_count()); m_pluginChain->process_post_fader(m_processBus, nframes); m_processBus->process_monitoring(m_vumonitors); process_post_sends(nframes); m_processBus->silence_buffers(nframes); return 1; }
static void hdspmmixer_get(t_hdspmmixer *x, t_symbol *s, int argc, t_atom *argv) { int idx, src, dst,val; if (argc < 3 || A_FLOAT != argv->a_type || A_FLOAT != (argv+1)->a_type || A_FLOAT != (argv+2)->a_type ) { error("hdspmmixer: set <float cardnr> <float source> <float destination>\n"); /* return -EINVAL;*/ } idx = atom_getint(argv); src = atom_getint(argv+1); dst = atom_getint(argv+2); val = get_gain(idx,src,dst); if(val < 0) outlet_float(x->x_error,(float) val); else outlet_float(x->x_obj.ob_outlet,(float) val); /* post("gain: %i",get_gain(idx,src,dst));*/ }
// entry point void mexFunction(int nlhs,mxArray *plhs[], int nrhs,const mxArray *prhs[]) { char* str; str = mxArrayToString(prhs[0]); if ( 0 == strcmp(str,"train") ) { train(nlhs,plhs, nrhs,prhs); } else if ( 0 == strcmp(str,"get") ) { get(nlhs,plhs, nrhs,prhs); } else if ( 0 == strcmp(str,"get_cc") ) { get_cc(nlhs,plhs, nrhs,prhs); } else if ( 0 == strcmp(str,"get_sc") ) { get_sc(nlhs,plhs, nrhs,prhs); } else if ( 0 == strcmp(str,"get_is_leaf") ) { get_is_leaf(nlhs,plhs, nrhs,prhs); } else if ( 0 == strcmp(str,"get_gain") ) { get_gain(nlhs,plhs, nrhs,prhs); } else if ( 0 == strcmp(str,"predict") ) { predict(nlhs,plhs, nrhs,prhs); } else if ( 0 == strcmp(str,"delete") ) { del(nlhs,plhs, nrhs,prhs); } else if ( 0 == strcmp(str,"save") ) { save(nlhs,plhs, nrhs,prhs); } else { mexErrMsgTxt("pSampVTLogitBoost_mex::unknown option."); } }
/** Acquire utility main */ int main(int argc, char *argv[]) { g_argv0 = argv[0]; int equal = 0; int shaping = 0; int average = 0;//ERG int calibration = 0;//ERG if ( argc < MINARGS ) { usage(); exit ( EXIT_FAILURE ); } /* Command line options */ static struct option long_options[] = { /* These options set a flag. */ {"average", no_argument, 0, 'a'},//ERG {"calibration", no_argument, 0, 'c'},//ERG {"equalization", no_argument, 0, 'e'}, {"shaping", no_argument, 0, 's'}, {"gain1", required_argument, 0, '1'}, {"gain2", required_argument, 0, '2'}, {"version", no_argument, 0, 'v'}, {"help", no_argument, 0, 'h'}, {0, 0, 0, 0} }; const char *optstring = "aces1:2:vh";//ERG /* getopt_long stores the option index here. */ int option_index = 0; int ch = -1; while ( (ch = getopt_long( argc, argv, optstring, long_options, &option_index )) != -1 ) { switch ( ch ) { case 'a'://ERG average = 1; break; case 'c'://ERG calibration = 1; break; case 'e': equal = 1; break; case 's': shaping = 1; break; /* Gain Channel 1 */ case '1': { int gain1; if (get_gain(&gain1, optarg) != 0) { usage(); return -1; } t_params[GAIN1_PARAM] = gain1; } break; /* Gain Channel 2 */ case '2': { int gain2; if (get_gain(&gain2, optarg) != 0) { usage(); return -1; } t_params[GAIN2_PARAM] = gain2; } break; case 'v': fprintf(stdout, "%s version %s-%s\n", g_argv0, VERSION_STR, REVISION_STR); exit( EXIT_SUCCESS ); break; case 'h': usage(); exit( EXIT_SUCCESS ); break; default: usage(); exit( EXIT_FAILURE ); } } /* Acquisition size */ uint32_t size = 0; if (optind < argc) { size = atoi(argv[optind]); if (size > SIGNAL_LENGTH) { fprintf(stderr, "Invalid SIZE: %s\n", argv[optind]); usage(); exit( EXIT_FAILURE ); } } else { fprintf(stderr, "SIZE parameter missing\n"); usage(); exit( EXIT_FAILURE ); } optind++; /* Optional decimation */ if (optind < argc) { uint32_t dec = atoi(argv[optind]); uint32_t idx; for (idx = 0; idx < DEC_MAX; idx++) { if (dec == g_dec[idx]) { break; } } if (idx != DEC_MAX) { t_params[TIME_RANGE_PARAM] = idx; } else { fprintf(stderr, "Invalid decimation DEC: %s\n", argv[optind]); usage(); return -1; } } /* Filter parameters */ t_params[EQUAL_FILT_PARAM] = equal; t_params[SHAPE_FILT_PARAM] = shaping; /* Initialization of Oscilloscope application */ if(rp_app_init(calibration) < 0) {//ERG fprintf(stderr, "rp_app_init() failed!\n"); return -1; } /* Setting of parameters in Oscilloscope main module */ if(rp_set_params((float *)&t_params, PARAMS_NUM) < 0) { fprintf(stderr, "rp_set_params() failed!\n"); return -1; } { float **s; int sig_num, sig_len; int i; int ret_val; int retries = 150000; s = (float **)malloc(SIGNALS_NUM * sizeof(float *)); for(i = 0; i < SIGNALS_NUM; i++) { s[i] = (float *)malloc(SIGNAL_LENGTH * sizeof(float)); } while(retries >= 0) { if((ret_val = rp_get_signals(&s, &sig_num, &sig_len)) >= 0) { /* Signals acquired in s[][]: * s[0][i] - TODO * s[1][i] - Channel ADC1 raw signal * s[2][i] - Channel ADC2 raw signal */ if (average == 1) { if (calibration == 0) { long long ch1_average = 0; long long ch2_average = 0; for(i = 0; i < MIN(size, sig_len); i++) { ch1_average += (int)s[1][i]; ch2_average += (int)s[2][i]; } ch1_average /= MIN(size, sig_len); ch2_average /= MIN(size, sig_len); printf("%7lld %7lld\n", ch1_average, ch2_average); } else { long double ch1_average = 0.0; long double ch2_average = 0.0; for(i = 0; i < MIN(size, sig_len); i++) { ch1_average += s[1][i]; ch2_average += s[2][i]; } ch1_average /= MIN(size, sig_len); ch2_average /= MIN(size, sig_len); printf("%.4Lf %.4Lf\n", ch1_average, ch2_average); } } else if (calibration == 0) { for(i = 0; i < MIN(size, sig_len); i++) { printf("%7d %7d\n", (int)s[1][i], (int)s[2][i]); } } else { for(i = 0; i < MIN(size, sig_len); i++) { printf("%.4f %.4f\n", s[1][i], s[2][i]); } } break; } if(retries-- == 0) { fprintf(stderr, "Signal scquisition was not triggered!\n"); break; } usleep(1000); } } if(rp_app_exit() < 0) { fprintf(stderr, "rp_app_exit() failed!\n"); return -1; } return 0; }
static int te_calc_ndcg_rel(const EPI *epi, const REL_INFO *rel_info, const RESULTS *results, const TREC_MEAS *tm, TREC_EVAL *eval) { RES_RELS res_rels; double results_gain, results_dcg; double ideal_gain, ideal_dcg; double sum = 0.0; long num_rel_ret = 0; long num_rel = 0; long cur_level, num_at_level; long i; GAINS gains; if (UNDEF == te_form_res_rels(epi, rel_info, results, &res_rels)) return (UNDEF); if (UNDEF == setup_gains(tm, &res_rels, &gains)) return (UNDEF); results_dcg = 0.0; ideal_dcg = 0.0; cur_level = gains.num_gains - 1; ideal_gain = (cur_level >= 0) ? gains.rel_gains[cur_level].gain : 0.0; num_at_level = 0; for (i = 0; i < res_rels.num_ret && ideal_gain > 0.0; i++) { /* Calculate change in results dcg */ results_gain = get_gain(res_rels.results_rel_list[i], &gains); if (results_gain != 0) /* Note: i+2 since doc i has rank i+1 */ results_dcg += results_gain / log2((double) (i + 2)); /* Calculate change in ideal dcg */ num_at_level++; while (cur_level >= 0 && num_at_level > gains.rel_gains[cur_level].num_at_level) { num_at_level = 1; cur_level--; ideal_gain = (cur_level >= 0) ? gains.rel_gains[cur_level].gain : 0.0; } if (ideal_gain > 0.0) { num_rel++; ideal_dcg += ideal_gain / log2((double) (i + 2)); } /* Average will include this point if rel */ if (results_gain > 0) { sum += results_dcg / ideal_dcg; num_rel_ret++; } if (epi->debug_level > 0) printf("ndcg_rel: %ld %ld %3.1f %6.4f %3.1f %6.4f %6.4f\n", i, cur_level, results_gain, results_dcg, ideal_gain, ideal_dcg, sum); } if (i < res_rels.num_ret) { while (i < res_rels.num_ret) { /* Calculate change in results dcg */ results_gain = get_gain(res_rels.results_rel_list[i], &gains); if (results_gain != 0) results_dcg += results_gain / log2((double) (i + 2)); /* Average will include this point if rel */ if (results_gain > 0) { sum += results_dcg / ideal_dcg; num_rel_ret++; } if (epi->debug_level > 0) printf("ndcg_rel: %ld %ld %3.1f %6.4f %3.1f %6.4f %6.4f\n", i, cur_level, results_gain, results_dcg, 0.0, ideal_dcg, sum); i++; } } while (ideal_gain > 0.0) { /* Calculate change in ideal dcg */ num_at_level++; while (cur_level >= 0 && num_at_level > gains.rel_gains[cur_level].num_at_level) { num_at_level = 1; cur_level--; ideal_gain = (cur_level >= 0) ? gains.rel_gains[cur_level].gain : 0.0; } if (ideal_gain > 0.0) { num_rel++; ideal_dcg += ideal_gain / log2((double) (i + 2)); } if (epi->debug_level > 0) printf("ndcg_rel: %ld %ld %3.1f %6.4f %3.1f %6.4f\n", i, cur_level, 0.0, results_dcg, ideal_gain, ideal_dcg); i++; } sum += ((double) (num_rel - num_rel_ret)) * results_dcg / ideal_dcg; if (epi->debug_level > 0) printf("ndcg_rel: %ld %ld %6.4f %6.4f %6.4f\n", i, cur_level, results_dcg, ideal_dcg, sum); if (sum > 0.0) eval->values[tm->eval_index].value = sum / num_rel; Free(gains.rel_gains); return (1); }
/** * Gets the scaling_factor. * * @return scaling_factor double */ double Probe::getGain() const { return get_gain(); }
void camera_server() { size_t count = 0; initialise_termination_handler(); int deviceDescriptor = v4l2_open("/dev/video0", O_RDWR /* required */| O_NONBLOCK, 0); if (deviceDescriptor == -1) { throw std::runtime_error("Unable to open device"); } // disable_output_processing(deviceDescriptor); if (!isStreamingIOSupported(deviceDescriptor)) { throw std::runtime_error("Streaming is not supported"); } setCameraOutputFormat(deviceDescriptor, CAMERA_FRAME_WIDTH, CAMERA_FRAME_HEIGHT, V4L2_PIX_FMT_YUYV); std::cout << "Absolute focus supported: " << isControlSupported(deviceDescriptor,V4L2_CID_FOCUS_ABSOLUTE) << std::endl; std::cout << "Relative focus supported: " << isControlSupported(deviceDescriptor,V4L2_CID_FOCUS_RELATIVE) << std::endl; set_manual_exposure(deviceDescriptor,true); printf("Is manual exposure set = %u\n", is_manual_exposure(deviceDescriptor)); set_absolute_exposure(100,deviceDescriptor); set_exposure_auto_priority(deviceDescriptor,false); printf("Is exposure auto priority set = %u\n", is_exposure_auto_priority(deviceDescriptor)); set_auto_white_balance(deviceDescriptor,false); printf("Is auto white balance set = %u\n", is_auto_white_balance_set(deviceDescriptor)); set_gain(deviceDescriptor,1); printf("Gain set = %u\n", get_gain(deviceDescriptor)); printf("Focus value = %u\n", get_focus_variable(deviceDescriptor)); set_fps(deviceDescriptor,30); start_capturing(deviceDescriptor); unsigned int counter; int announce_socket=socket(AF_INET,SOCK_DGRAM,0); if (announce_socket < 0) { perror("socket"); exit(1); } sockaddr_in announce_address; memset(&announce_address,0,sizeof(announce_address)); announce_address.sin_family=AF_INET; announce_address.sin_addr.s_addr=inet_addr(CAMERA_ANNOUNCE_GROUP); announce_address.sin_port=htons(CAMERA_ANNOUNCE_PORT); while (running != 0) { fd_set fds; int r; FD_ZERO(&fds); FD_SET(deviceDescriptor, &fds); r = select(deviceDescriptor + 1, &fds, NULL, NULL, NULL); if (r > 0) { struct v4l2_buffer buf; memset(&buf, 0, sizeof(buf)); buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; buf.memory = V4L2_MEMORY_USERPTR; if (-1 == xioctl(deviceDescriptor, VIDIOC_DQBUF, &buf)) { switch (errno) { case EAGAIN: continue; case EIO: /* Could ignore EIO, see spec. */ /* fall through */ default: perror("VIDIOC_DQBUF"); exit(1); } } if ((buf.flags | V4L2_BUF_FLAG_ERROR) != 0) { //TODO Investigate the permanent occurence of the V4L2_BUF_FLAG_ERROR // std::cerr << "Frame buffer error" << std::endl; } printf("Index = %u, seconds = %ld us = %ld\n", buf.index,buf.timestamp.tv_sec,buf.timestamp.tv_usec); // printf("Real time: seconds = %ld, us = %ld\n", tp.tv_sec,tp.tv_nsec/1000); int ret; assert(ptrToSequenceMap.count(buf.m.userptr) != 0); size_t sequence_number = ptrToSequenceMap[buf.m.userptr]; ptrToSequenceMap.erase(buf.m.userptr); queueNextFrameBuffer(deviceDescriptor, buf.index, sequence_number, CAMERA_FRAME_WIDTH*CAMERA_FRAME_HEIGHT*2); //TODO Investigate why the video streaming fails if the unmap call below is placed before the queueNextFrameBuffer call above. //Probably this is because in that case the mmap call returns the same virtual address as the munmap call had just used for the deallocation ret = munmap(reinterpret_cast<void*>(buf.m.userptr),buf.length); if (ret == -1) { perror("munmap"); } BufferReference readyBuffer; readyBuffer.index = buf.index; readyBuffer.offset = 0; readyBuffer.size = buf.bytesused; readyBuffer.timestamp_seconds = buf.timestamp.tv_sec; readyBuffer.timestamp_microseconds = buf.timestamp.tv_usec; readyBuffer.width = CAMERA_FRAME_WIDTH; readyBuffer.height = CAMERA_FRAME_HEIGHT; readyBuffer.sequence = sequence_number; std::array<char,1024> ipc_buffer; asn_enc_rval_t encode_result = der_encode_to_buffer(&asn_DEF_BufferReference, &readyBuffer,ipc_buffer.data(),ipc_buffer.size()); ret = sendto(announce_socket,ipc_buffer.data(),encode_result.encoded,0,(struct sockaddr *) &announce_address,sizeof(announce_address)); if (ret < 0) { perror("sendto"); exit(1); } timespec tp; clock_gettime(CLOCK_MONOTONIC,&tp); std::cout << "Grab frame delay = " << get_milliseconds_delta(buf.timestamp,tp) << " ms" << std::endl; count++; counter++; } } v4l2_buf_type type = V4L2_BUF_TYPE_VIDEO_CAPTURE; if (-1 == xioctl(deviceDescriptor, VIDIOC_STREAMOFF, &type)) perror("VIDIOC_STREAMOFF"); if (-1 == close(deviceDescriptor)) perror("close"); close(announce_socket); }
int main(int argc, char** argv) { SETTINGS settings; int option_index = 1, ret, i, bits; #ifdef _WIN32 char CmdDir[MAX_PATH]; char *p; #endif memset(&settings, 0, sizeof(settings)); settings.first_file = 1; settings.radio = 1; settings.clip_prev = 1; settings.outbitwidth = 16; settings.format = WAV_NO_FMT; #ifdef _WIN32 /* Is this good enough? Or do we need to consider multi-byte codepages as * well? */ SetConsoleOutputCP(GetACP()); GetModuleFileName(NULL, CmdDir, MAX_PATH); p = strrchr(CmdDir, '\\') + 1; p[0] = '\0'; #endif while ((ret = getopt_long(argc, argv, ARG_STRING, long_options, &option_index)) != -1) { switch(ret) { case 0: if (!strcmp(long_options[option_index].name, "force")) { settings.force = 1; } else if (!strcmp(long_options[option_index].name, "undo-gain")) { settings.undo = 1; } else { fprintf(stderr, "Internal error parsing command line options\n"); exit(1); } break; case 'h': usage(); exit(0); break; case 'a': settings.audiophile = 1; break; case 'r': settings.radio = 1; break; case 'q': settings.adc = 1; break; case 'p': settings.no_offset = 1; break; case 'c': settings.apply_gain = 0; break; case 'x': settings.scale = 1; break; case 'y': settings.apply_gain = 1; settings.scale = 0; break; case 'w': settings.write_chunk = 1; break; case 's': settings.fast = 1; break; case 'o': settings.std_out = 1; break; #ifdef ENABLE_RECURSIVE case 'z': settings.recursive = 1; break; #endif case 'l': write_to_log = 1; #ifdef _WIN32 strcpy(log_file_name, CmdDir); strcat(log_file_name, LOG_NAME); #else strcpy(log_file_name, LOG_NAME); #endif break; case 'f': write_to_log = 1; strcpy(log_file_name, optarg); break; case 'n': settings.clip_prev = 0; break; case 'd': settings.need_to_process = 1; settings.dithering = 1; if(sscanf(optarg, "%d", &settings.shapingtype) != 1) { fprintf(stderr, "Warning: dither type %s not recognised, using default\n", optarg); break; } if (settings.shapingtype == 0) settings.dithering = 0; else if (settings.shapingtype == 1) settings.shapingtype = 0; else if (settings.shapingtype == 2) settings.shapingtype = 1; else if (settings.shapingtype == 3) settings.shapingtype = 2; else if (settings.shapingtype == 4) settings.shapingtype = 3; break; case 't': settings.limiter = 1; break; case 'g': if(sscanf(optarg, "%lf", &settings.man_gain) != 1) { fprintf(stderr, "Warning: manual gain %s not recognised, ignoring\n", optarg); break; } if(settings.man_gain < -20.0) { fprintf(stderr, "Warning: manual gain %s is out of range, " "applying gain of -20.0dB\n", optarg); settings.man_gain = -20.0; } else if(settings.man_gain > 12.0) { fprintf(stderr, "Warning: manual gain %s is out of range, " "applying gain of +12.0dB\n", optarg); settings.man_gain = 12.0; } break; case 'b': settings.need_to_process = 1; if(sscanf(optarg, "%d", &bits) != 1) { fprintf(stderr, "Warning: output format %s not recognised, using default\n", optarg); break; } if (bits == 1) { settings.outbitwidth = 8; settings.format = WAV_FMT_8BIT; break; } else if (bits == 2) { settings.outbitwidth = 16; settings.format = WAV_FMT_16BIT; break; } else if (bits == 3) { settings.outbitwidth = 24; settings.format = WAV_FMT_24BIT; break; } else if (bits == 4) { settings.outbitwidth = 32; settings.format = WAV_FMT_32BIT; break; } else if (bits == 5) { settings.outbitwidth = 32; settings.format = WAV_FMT_FLOAT; break; } else if (bits == 6) { settings.outbitwidth = 16; settings.format = WAV_FMT_AIFF; break; } else { fprintf(stderr, "Warning: output format %s not recognised, using default\n", optarg); break; } break; #ifdef _WIN32 case 'e': { char *p; int k; char * lpPart[MAX_PATH]={NULL}; settings.cmd = (char *) malloc(1024*8); /* 8Kb is XP's limit */ if (settings.cmd == NULL) { fprintf(stderr, "Failed to allocate memory for cmd...\n"); return 1; } p = settings.cmd; k = GetFullPathName(argv[optind - 1], 1024*8, p, lpPart); k = GetShortPathName(p, p, MAX_PATH); if (k == 0) { p += sprintf (p, "%s", argv[optind - 1]); } else { p += k; } for (k = optind; k < argc; ++k) { p += sprintf(p, " \"%s\"", argv[k]); } argc = optind; break; } #endif } } if (settings.undo == 1) { settings.write_chunk = 0; settings.no_offset = 1; } if (optind >= argc) { fprintf(stderr, _("No files specified.\n")); usage(); return EXIT_SUCCESS; } if (write_to_log) { write_log("Command line:\n\t"); for(i = 0; i < argc; i++) write_log("%s ", argv[i]); write_log("\n"); } if (!strcmp(argv[optind], "-")) { double track_peak, track_gain; double dc_offset; double offset; if (!get_gain("-", &track_peak, &track_gain, &dc_offset, &offset, &settings)) return -1; } else { for (i = optind; i < argc; ++i) { #ifdef ENABLE_RECURSIVE if (process_argument(argv[i], &settings) < 0) { free_list(settings.file_list); return EXIT_FAILURE; } #else if (add_to_list(&settings.file_list, argv[i]) < 0) return EXIT_FAILURE; #endif } /* Process files (perhaps remaining) in list */ ret = process_files(settings.file_list, &settings, "."); free_list(settings.file_list); settings.file_list = NULL; if (settings.cmd) free(settings.cmd); settings.cmd = NULL; } return (ret < 0) ? EXIT_FAILURE : EXIT_SUCCESS; }
/** * \brief Processs the file in file_list. * * Process the files in file_list. If settings->album is set, the files are * considered to belong to one album. * * \param file_list list of files to process. * \param settings settings and global variables. * \return 0 if successful and -1 if an error occured (in which case a * message has been printed). */ int process_files(FILE_LIST* file_list, SETTINGS* settings, const char* dir) { FILE_LIST* file; double factor_clip, audiophile_gain = 0., Gain, scale, dB, album_dc_offset[2] = {0., 0.}; settings->album_peak = NO_PEAK; if (file_list == NULL) return 0; settings->first_file = 1; /* Undo previously applied gain */ if (settings->undo) { for (file = file_list; file; file = file->next_file) { if (file->filename == '\0') continue; if (!write_gains(file->filename, 0, 0, 0, 0, 0, settings)) { fprintf(stderr, " Error processing GAIN for file - %s\n", file->filename); continue; } } } else { /* Analyze the files */ for (file = file_list; file; file = file->next_file) { int dc_l; int dc_r; if (file->filename == '\0') continue; if (!get_gain(file->filename, &file->track_peak, &file->track_gain, file->dc_offset, file->offset, settings)) { file->filename = '\0'; continue; } dc_l = (int)(file->dc_offset[0] * 32768 * -1); dc_r = (int)(file->dc_offset[1] * 32768 * -1); if (dc_l < -1 || dc_l > 1 || dc_r < -1 || dc_r > 1) settings->need_to_process = 1; album_dc_offset[0] += file->offset[0]; album_dc_offset[1] += file->offset[1]; } album_dc_offset[0] /= total_samples; album_dc_offset[1] /= total_samples; if (!settings->no_offset && settings->adc) { int dc_l = (int)(album_dc_offset[0] * 32768 * -1); int dc_r = (int)(album_dc_offset[1] * 32768 * -1); fprintf(stderr, " ********************* Album DC Offset | %4d | %4d | ***************\n", dc_l, dc_r); if(write_to_log) { write_log(" ********************* Album DC Offset | %4d | %4d | ***************\n", dc_l, dc_r); } } fprintf(stderr, "\n"); if(write_to_log) write_log("\n"); if (settings->audiophile) { Gain = GetAlbumGain() + settings->man_gain; scale = pow(10., Gain * 0.05); settings->set_album_gain = 0; if(settings->clip_prev) { factor_clip = (32767./( settings->album_peak + 1)); if(scale < factor_clip) factor_clip = 1.0; else factor_clip /= scale; scale *= factor_clip; } if (settings->scale) { fprintf(stdout, "%8.6lf", scale); } if (scale > 0.0) dB = 20. * log10(scale); else dB = 0.0; audiophile_gain = dB; if (audiophile_gain < 0.1 && audiophile_gain > -0.1 && !settings->need_to_process) { fprintf(stderr, " No Album Gain adjustment or DC Offset correction required, exiting.\n"); if(write_to_log) write_log(" No Album Gain adjustment or DC Offset correction required, exiting.\n"); settings->set_album_gain = 1; } else { fprintf(stderr, " Recommended Album Gain: %+6.2f dB\tScale: %6.4f\n\n", audiophile_gain, scale); if(write_to_log) write_log(" Recommended Album Gain: %+6.2f dB\tScale: %6.4f\n\n", audiophile_gain, scale); } } if(settings->apply_gain) { /* Write radio and audiophile gains. */ total_files = 0.0; for (file = file_list; file; file = file->next_file) { if (file->filename == '\0') continue; if (settings->audiophile && settings->set_album_gain == 1) break; if (settings->radio && (file->track_gain < 0.1 && file->track_gain > -0.1) && !settings->need_to_process) { fprintf(stderr, " No Title Gain adjustment or DC Offset correction required for file: %s, skipping.\n", file->filename); if(write_to_log) write_log(" No Title Gain adjustment or DC Offset correction required for file: %s, skipping.\n", file->filename); } else if (!write_gains(file->filename, file->track_gain, audiophile_gain, file->track_peak, file->dc_offset, album_dc_offset, settings)) { fprintf(stderr, " Error processing GAIN for file - %s\n", file->filename); continue; } } } } fprintf(stderr, "\n WaveGain Processing completed normally\n"); if(write_to_log) write_log("\n WaveGain Processing completed normally\n\n"); #ifdef _WIN32 if (settings->cmd) { /* execute user command */ FILE_LIST* file; char buff[MAX_PATH]; char *b, *p, *q; double track_scale = 1.0; SetEnvironmentVariable("ALBUM_GAIN", ftos(audiophile_gain, "%.2lf")); SetEnvironmentVariable("ALBUM_SCALE", ftos(scale, "%.5lf")); SetEnvironmentVariable("ALBUM_NEW_PEAK", ftos(settings->album_peak * scale, "%.0lf")); SetEnvironmentVariable("ALBUM_PEAK", ftos(settings->album_peak, "%.0lf")); for (file = file_list; file; file = file->next_file) { if (file->filename == '\0') continue; if (dir[0] == '.' && dir[1] == '\\') dir += 2; strcpy(buff, file->filename); b = (buff[0] == '.' && buff[1] == '\\') ? buff+2 : buff; SetEnvironmentVariable("INPUT_FILE", b); p = strrchr(b, '\\'); if (p) { p[0] = '\0'; ++p; SetEnvironmentVariable("INPUT_FDIR", b); SetEnvironmentVariable("INPUT_RDIR", b); // assume dir = "." } else { p = b; SetEnvironmentVariable("INPUT_FDIR", "."); SetEnvironmentVariable("INPUT_RDIR", dir); } q = strrchr(p, '.'); if (q) q[0] = '\0'; SetEnvironmentVariable("INPUT_NAME", p); track_scale = (pow(10., file->track_gain * 0.05)); SetEnvironmentVariable("TRACK_SCALE", ftos(track_scale, "%.5lf")); SetEnvironmentVariable("TRACK_GAIN", ftos(file->track_gain, "%.2lf")); SetEnvironmentVariable("TRACK_NEW_PEAK", ftos(file->track_peak, "%.0lf")); SetEnvironmentVariable("TRACK_PEAK", ftos(file->track_peak / track_scale, "%.0lf")); SetEnvironmentVariable("DC_OFFSET_L", ftos((int)(file->dc_offset[0]*(-32768)), "%.0lf")); SetEnvironmentVariable("DC_OFFSET_R", ftos((int)(file->dc_offset[1]*(-32768)), "%.0lf")); fprintf(stderr, "\n Executing command on \"%s\":\n\n", file->filename); system(settings->cmd); } } #endif return 0; }
AudioProcessorState * AudioProcessor::get_state(vtime_t time) { AudioProcessorState *state = new AudioProcessorState; if (!state) return 0; // Channel order get_input_order(state->input_order); get_output_order(state->output_order); // Master gain state->master = get_master(); state->gain = get_gain(); // AGC options state->auto_gain = get_auto_gain(); state->normalize = get_normalize(); state->attack = get_attack(); state->release = get_release(); // DRC state->drc = get_drc(); state->drc_power = get_drc_power(); state->drc_level = get_drc_level(); // Matrix get_matrix(state->matrix); // Automatrix options state->auto_matrix = get_auto_matrix(); state->normalize_matrix = get_normalize_matrix(); state->voice_control = get_voice_control(); state->expand_stereo = get_expand_stereo(); // Automatrix levels state->clev = get_clev(); state->slev = get_slev(); state->lfelev = get_lfelev(); // Input/output gains get_input_gains(state->input_gains); get_output_gains(state->output_gains); // Input/output levels get_input_levels(time, state->input_levels); get_output_levels(time, state->output_levels); // SRC state->src_quality = get_src_quality(); state->src_att = get_src_att(); // Equalizer state->eq = get_eq(); state->eq_master_nbands = get_eq_nbands(CH_NONE); state->eq_master_bands = 0; if (state->eq_master_nbands) { state->eq_master_bands = new EqBand[state->eq_master_nbands]; get_eq_bands(CH_NONE, state->eq_master_bands, 0, state->eq_master_nbands); } for (int ch_name = 0; ch_name < CH_NAMES; ch_name++) { state->eq_nbands[ch_name] = get_eq_nbands(ch_name); state->eq_bands[ch_name] = 0; if (state->eq_nbands[ch_name]) { state->eq_bands[ch_name] = new EqBand[state->eq_nbands[ch_name]]; get_eq_bands(ch_name, state->eq_bands[ch_name], 0, state->eq_nbands[ch_name]); } } // Bass redirection state->bass_redir = get_bass_redir(); state->bass_freq = get_bass_freq(); state->bass_channels = get_bass_channels(); // Delays state->delay = get_delay(); state->delay_units = get_delay_units(); get_delays(state->delays); // Dithering state->dithering = get_dithering(); return state; }
int main(int argc, char *argv[]) { int err = 0; int src; int dst; int val; /* int i; for(i=0; i < argc; i++) printf(" %s ", argv[i]); printf("\n"); */ /* if((err =find_cards()) < 0) return err; */ if(argc < 4){ printf("\nusage %s <devnr> <src> <dst> [value] \n\n" " devnr ... ALSA-Device eg. for hw:0 is 0 \n" " src ... inputs 0-63 playback 64-127\n" " dst ... out channel 0-63\n" "\noptional if wanting to set a value:\n\n" " value ... gain 0=0 (mute), 32768=1 (unitGain), 65535 = max\n\n", argv[0]); if(find_cards() < 0) puts("No Hammerfall DSP MADI card found."); puts(""); printf("Version %s, 2003 - IEM, winfried ritsch\n",HDSPMM_VERSION); return -1; } cardid = atoi(argv[1]); snprintf(card_name[cardid], 6, "hw:%i", cardid); src = atoi(argv[2]); dst = atoi(argv[3]); if(argc == 4){ printf(" Get Mixer from %d to %d : %d \n",src,dst, get_gain(cardid,src,dst)); return 0; } /* arg is 5 */ val = atoi(argv[4]); if((err = set_gain(cardid,src,dst,val)) < 0 ) printf("Error: Could not set mixer from %d to %d gain %d:%s \n", src,dst,val,snd_strerror(err)); else printf("Set Mixer from %d to %d : %d \n",src,dst,val); return err; }