static int series_view_allocate (series_view *sview) { int err = 0; if (sview == NULL) { return E_DATA; } if (sview->points != NULL) { /* already allocated */ return 0; } else { int T = sample_size(dataset); sview->points = mymalloc(T * sizeof *sview->points); if (sview->points == NULL) { err = E_ALLOC; } else { sview->npoints = T; } } if (sview->varnum > 0) { /* single series view */ series_view_fill_points(sview); } return err; }
int SND_Out_File::tell_write() { if (!good()) return -1; return ((static_cast<int>(file.tellp()) - sizeof(header)) / (header.channels * sample_size())); }
bool SND_In_File::seek_read(int pos) { if (pos < 0) file.seekg(0, ios::end); else file.seekg(header.hdr_size + header.channels * sample_size() * pos); return true; }
void time_series_menu_state (gboolean s) { gboolean sx = extended_ts(dataset); gboolean panel = dataset_is_panel(dataset); gboolean realpan = multi_unit_panel_sample(dataset); gboolean ur; if (mdata->ui == NULL) { return; } /* FIXME: we (may) need to enable/disable function packages that have menu attachments here. */ /* unit-root tests: require time-series or panel data, and a time series length greater than 5 */ if (panel) { ur = dataset->pd > 5; } else { ur = s && sample_size(dataset) > 5; } /* Plots */ flip(mdata->ui, "/menubar/View/GraphVars/TSPlot", sx); flip(mdata->ui, "/menubar/View/MultiPlots/MultiTS", sx); flip(mdata->ui, "/menubar/Variable/VarTSPlot", sx && !realpan); flip(mdata->ui, "/menubar/Variable/PanPlot", realpan); /* Variable menu */ flip(mdata->ui, "/menubar/Variable/URTests", ur); if (ur && !s) { /* time-series only "ur" option */ flip(mdata->ui, "/menubar/Variable/URTests/fractint", s); } flip(mdata->ui, "/menubar/Variable/URTests/levinlin", ur && panel); flip(mdata->ui, "/menubar/Variable/corrgm", s); flip(mdata->ui, "/menubar/Variable/pergm", s); flip(mdata->ui, "/menubar/Variable/Filter", s); #ifdef HAVE_X12A flip(mdata->ui, "/menubar/Variable/X12A", get_x12a_ok()); #endif #ifdef HAVE_TRAMO flip(mdata->ui, "/menubar/Variable/Tramo", get_tramo_ok()); #endif flip(mdata->ui, "/menubar/Variable/Hurst", s); /* Model menu */ flip(mdata->ui, "/menubar/Model/TSModels", s); /* Sample menu */ flip(mdata->ui, "/menubar/Data/DataCompact", s && (COMPACTABLE(dataset) || dated_weekly_data(dataset))); flip(mdata->ui, "/menubar/Data/DataExpand", s && EXPANSIBLE(dataset)); }
bool SND_Out_File::seek_write(int pos) { if (!good()) return false; if (pos < 0) file.seekp(0, ios::end); else file.seekp(sizeof(header) + header.channels * sample_size() * pos); return true; }
int main() { int sample_sz; long long population_sz = 1000000; float confidence_level = 95.0; float confidence_interval = 2.0; sample_sz = sample_size(population_sz, confidence_level, confidence_interval); printf("SAMPLE SIZE: %d\n", sample_sz); return 0; }
/// Advance to next sample void advance() { assert(!at_end()); m_offset += sample_size(); m_sample_index += 1; m_chunk_sample += 1; if (m_chunk_sample >= m_stsc->samples_for_chunk(m_chunk_index)) { m_chunk_index += 1; m_chunk_sample = 0; m_offset = 0; } }
void score_value(const Model & model, AlignedFloats scores) const { if (DIST_DEBUG_LEVEL >= 1) { DIST_ASSERT_EQ(scores.size(), counts().size()); } const size_t size = counts().size(); const float shift = -fast_log(sample_size() + model.alpha); const float * __restrict__ in = VectorFloat_data(shifted_scores_); float * __restrict__ out = VectorFloat_data(scores); for (size_t i = 0; i < size; ++i) { out[i] = in[i] + shift; } }
bool Converter::convert_linear2pcm(Chunk &in, Chunk &out) { size_t n = MIN(in.size, nsamples); size_t out_size = n * sample_size(format) * spk.nch(); samples_t samples = in.samples; samples.reorder_from_std(spk, order); convert(out_rawdata, samples, n); out.set_rawdata(out_rawdata, out_size, in.sync, in.time); in.drop_samples(n); return !out.is_dummy(); }
bool Converter::init() { ///////////////////////////////////////////////////////// // Initialize convertor: // * find conversion function // * allocate buffer // * reset filter state if (spk.format == format) // no conversion required; no buffer required return true; convert = find_conversion(format, spk); if (convert == 0) return false; buf.allocate(spk.nch() * nsamples * sample_size(format)); if (format == FORMAT_LINEAR) { // set channel pointers out_samples[0] = (sample_t *)buf.begin(); for (int ch = 1; ch < spk.nch(); ch++) out_samples[ch] = out_samples[ch-1] + nsamples; out_rawdata = 0; } else { // set rawdata pointer out_rawdata = buf.begin(); out_samples.zero(); } reset(); return true; }
void softmixer_process_buffer(char *buf, size_t size, const struct sound_params *sound_params) { debug ("Processing %u bytes...", size); if(mixer_real==100 && !mix_mono) return; int do_softmix = mixer_real != 100; long sound_endianness = sound_params->fmt & SFMT_MASK_ENDIANNESS; long sound_format = sound_params->fmt & SFMT_MASK_FORMAT; int samplesize = sample_size(sound_format); int is_float = (sound_params->fmt & SFMT_MASK_FORMAT) == SFMT_FLOAT; int need_endianness_swap = 0; if((sound_endianness != SFMT_NE) && (samplesize > 1) && (!is_float)) { need_endianness_swap = 1; } /* setup samples to perform arithmetic */ if(need_endianness_swap) { debug ("Converting endianness before mixing"); if(samplesize == 4) swap_endianness_32((int32_t *)buf, size / sizeof(int32_t)); else swap_endianness_16((int16_t *)buf, size / sizeof(int16_t)); } switch(sound_format) { case SFMT_U8: if(do_softmix) process_buffer_u8((uint8_t *)buf, size); if(mix_mono) mix_mono_u8((uint8_t *)buf, sound_params->channels, size); break; case SFMT_S8: if(do_softmix) process_buffer_s8((int8_t *)buf, size); if(mix_mono) mix_mono_s8((int8_t *)buf, sound_params->channels, size); break; case SFMT_U16: if(do_softmix) process_buffer_u16((uint16_t *)buf, size / sizeof(uint16_t)); if(mix_mono) mix_mono_u16((uint16_t *)buf, sound_params->channels, size / sizeof(uint16_t)); break; case SFMT_S16: if(do_softmix) process_buffer_s16((int16_t *)buf, size / sizeof(int16_t)); if(mix_mono) mix_mono_s16((int16_t *)buf, sound_params->channels, size / sizeof(int16_t)); break; case SFMT_U32: if(do_softmix) process_buffer_u32((uint32_t *)buf, size / sizeof(uint32_t)); if(mix_mono) mix_mono_u32((uint32_t *)buf, sound_params->channels, size / sizeof(uint32_t)); break; case SFMT_S32: if(do_softmix) process_buffer_s32((int32_t *)buf, size / sizeof(int32_t)); if(mix_mono) mix_mono_s32((int32_t *)buf, sound_params->channels, size / sizeof(int32_t)); break; case SFMT_FLOAT: if(do_softmix) process_buffer_float((float *)buf, size / sizeof(float)); if(mix_mono) mix_mono_float((float *)buf, sound_params->channels, size / sizeof(float)); break; } /* restore sample-endianness */ if(need_endianness_swap) { debug ("Restoring endianness after mixing"); if(samplesize == 4) swap_endianness_32((int32_t *)buf, size / sizeof(int32_t)); else swap_endianness_16((int16_t *)buf, size / sizeof(int16_t)); } }
void AudioBuffer::resize_samples(unsigned _num_samples) { const unsigned ss = sample_size(); m_data.resize(ss*_num_samples); }
void BM::set_mean(double a_over_a_plus_b){ double n = sample_size(); double a = a_over_a_plus_b * n; double b = (1 - a_over_a_plus_b) * n; set_params(a, b); }
double BM::mean()const{return a()/sample_size();}
static int add_midas_matrices (int yno, const int *xlist, const DATASET *dset, midas_info *minfo, int nmidas, int *pslopes) { gretl_matrix *X = NULL; gretl_matrix *y = NULL; gretl_matrix *b = NULL; gretl_matrix *c = NULL; int hfslopes = 0; int init_err = 0; int i, T, nx = 0; int err = 0; T = sample_size(dset); if (xlist != NULL) { nx = xlist[0]; X = gretl_matrix_data_subset(xlist, dset, dset->t1, dset->t2, M_MISSING_ERROR, &err); if (!err) { err = private_matrix_add(X, "MX___"); } if (!err) { b = gretl_zero_matrix_new(nx, 1); if (b!= NULL) { err = private_matrix_add(b, "bx___"); } else { err = E_ALLOC; } } } if (!err) { /* for initialization only */ y = gretl_column_vector_alloc(T); if (y != NULL) { memcpy(y->val, dset->Z[yno] + dset->t1, T * sizeof(double)); } else { init_err = 1; } } if (!err) { /* count the HF slope coeffs */ for (i=0; i<nmidas && !err; i++) { if (takes_coeff(minfo[i].type)) { hfslopes++; } } /* "full-length" coeff vector */ c = gretl_zero_matrix_new(nx + hfslopes, 1); if (c == NULL) { init_err = 1; } } if (!err && !init_err) { gretl_matrix *XZ = NULL; if (hfslopes > 0) { XZ = build_XZ(X, dset, minfo, T, nmidas, hfslopes); if (XZ == NULL) { /* fallback, ignoring "Z" */ c->rows = nx; } } if (XZ != NULL) { init_err = gretl_matrix_ols(y, XZ, c, NULL, NULL, NULL); } else { init_err = gretl_matrix_ols(y, X, c, NULL, NULL, NULL); } gretl_matrix_free(XZ); } #if MIDAS_DEBUG if (!err && !init_err) { gretl_matrix_print(c, "MIDAS OLS initialization"); } #endif if (!err) { if (!init_err) { /* initialize X coeffs from OLS */ for (i=0; i<nx; i++) { b->val[i] = c->val[i]; } } if (hfslopes > 0) { /* initialize hf slopes, with fallback to zero */ int use_c = !init_err && c->rows > nx; char tmp[16]; double bzi; for (i=0; i<nmidas && !err; i++) { if (takes_coeff(minfo[i].type)) { sprintf(tmp, "bmlc___%d", i+1); bzi = use_c ? c->val[nx+i] : 0.0; err = private_scalar_add(bzi, tmp); } } } } gretl_matrix_free(y); gretl_matrix_free(c); /* we're finished with the per-term laglists now */ for (i=0; i<nmidas; i++) { if (!minfo[i].prelag) { free(minfo[i].laglist); } minfo[i].laglist = NULL; } #if MIDAS_DEBUG fprintf(stderr, "add_midas_matrices: returning %d\n", err); #endif *pslopes = hfslopes; return err; }
DATASET *midas_aux_dataset (const int *list, const DATASET *dset, int *err) { DATASET *mset = NULL; gretlopt opt = 0; int mpd, pd = dset->pd; int T, m = list[0]; int yr, mon; int daily = 0; if (m < 3 || gretl_list_has_separator(list)) { *err = E_INVARG; } else if (!dataset_is_time_series(dset)) { *err = E_INVARG; } else if (pd != 1 && pd != 4 && pd != 12) { /* host dataset should be annual, quarterly or monthly */ *err = E_PDWRONG; } if (*err) { return NULL; } if (pd == 1) { /* annual: midas series should be quarterly or monthly */ if (m != 4 && m != 12) { *err = E_INVARG; } else { mpd = m; } } else if (pd == 4) { /* quarterly: midas series should be monthly or daily */ if (m == 3) { mpd = 12; } else if (m == midas_days_per_period(5, 4)) { mpd = 5; } else if (m == midas_days_per_period(6, 4)) { mpd = 6; } else if (m == midas_days_per_period(7, 4)) { mpd = 7; } else { *err = E_INVARG; } } else { /* monthly: midas series should be daily */ if (m == midas_days_per_period(5, 12)) { mpd = 5; } else if (m == midas_days_per_period(6, 12)) { mpd = 6; } else if (m == midas_days_per_period(7, 12)) { mpd = 7; } else { *err = E_INVARG; } } if (*err) { return NULL; } if (!gretl_is_midas_list(list, dset)) { gretl_warnmsg_set("The argument does not seem to be a MIDAS list"); } T = sample_size(dset) * m; if (mpd >= 5 && mpd <= 7) { /* we'll add markers for daily dates */ daily = 1; opt = OPT_M; } mset = create_auxiliary_dataset(1, T, opt); if (mset == NULL) { *err = E_ALLOC; } if (!*err) { char *p, obs[OBSLEN]; int nonex, qtr = 0; int i, t, s, m3 = 0; mset->pd = mpd; mset->structure = TIME_SERIES; strcpy(mset->varname[0], dset->varname[list[1]]); p = strrchr(mset->varname[0], '_'); if (p != NULL) *p = '\0'; ntodate(obs, dset->t1, dset); if (mpd == 4) { sprintf(mset->stobs, "%d:1", atoi(obs)); } else if (mpd == 12) { sprintf(mset->stobs, "%d:01", atoi(obs)); } if (daily && pd == 4) { m3 = m / 3; } /* loop across observations in low-frequency dataset */ s = 0; for (t=dset->t1; t<=dset->t2; t++) { if (daily) { ntodate(obs, t, dset); sscanf(obs, "%d:%d", &yr, &mon); if (pd == 4) { qtr = mon; } } /* read data right-to-left! */ for (i=m; i>0; i--) { int vi = list[i]; if (daily) { if (pd == 4) { mon = quarter_to_month(qtr, m, m-i+1); nonex = daily_index_to_date(mset->S[s], yr, mon, (m-i) % m3, mpd); } else { nonex = daily_index_to_date(mset->S[s], yr, mon, m-i, mpd); } if (nonex) { /* skip any non-existent daily dates */ mset->t2 -= 1; } else { mset->Z[0][s++] = dset->Z[vi][t]; } } else { mset->Z[0][s++] = dset->Z[vi][t]; } } } if (daily) { strcpy(mset->stobs, mset->S[0]); strcpy(mset->endobs, mset->S[mset->t2]); mset->markers = DAILY_DATE_STRINGS; } mset->sd0 = get_date_x(mset->pd, mset->stobs); if (!daily) { ntodate(mset->endobs, mset->t2, mset); } } return mset; }
void AudioBuffer::reserve_us(uint64_t _us) { unsigned bytes = m_spec.us_to_samples(_us) * sample_size(); m_data.reserve(bytes); }
void AudioBuffer::resize_frames(unsigned _num_frames) { const unsigned ss = sample_size(); const unsigned ch = channels(); m_data.resize(ss*ch*_num_frames); }