Exemplo n.º 1
0
cvec_t * new_cvec( uint_t length) {
  cvec_t * s = AUBIO_NEW(cvec_t);
  s->length = length/2 + 1;
  s->norm = AUBIO_ARRAY(smpl_t,s->length);
  s->phas = AUBIO_ARRAY(smpl_t,s->length);
  return s;
}
Exemplo n.º 2
0
cvec_t * new_cvec(uint_t length) {
  cvec_t * s;
  if ((sint_t)length <= 0) {
    return NULL;
  }
  s = AUBIO_NEW(cvec_t);
  s->length = length/2 + 1;
  s->norm = AUBIO_ARRAY(smpl_t,s->length);
  s->phas = AUBIO_ARRAY(smpl_t,s->length);
  return s;
}
Exemplo n.º 3
0
aubio_audio_unit_t * new_aubio_audio_unit(uint_t samplerate,
    uint_t sw_input_channels, uint_t sw_output_channels,
    uint_t blocksize)
{
  aubio_audio_unit_t * o = AUBIO_NEW(aubio_audio_unit_t);
  o->hw_output_channels = 2;
  o->hw_input_channels = 2;
  o->sw_output_channels = sw_output_channels;
  o->sw_input_channels = sw_input_channels;
  o->samplerate = samplerate;
  o->latency = PREFERRED_LATENCY;
  o->blocksize = blocksize;

  o->au_ios_start = 0;
  o->au_ios_end = 0;

  o->verbose = 0;
  o->input_enabled = true;
  o->prevent_feedback = 1;
  o->dio_error = 0;

  o->total_frames = 0;

  /* the integers coming from and to the audio unit */
  o->au_ios_outbuf = AUBIO_ARRAY(SInt16, AU_IOS_MAX_FRAMES * o->hw_output_channels);
  o->au_ios_inbuf = AUBIO_ARRAY(SInt16, AU_IOS_MAX_FRAMES * o->hw_input_channels);

  /* the floats coming from and to the device callback */
  o->output_frames = new_fmat(sw_output_channels, blocksize);
  o->input_frames = new_fmat(sw_input_channels, blocksize);

  /* check for some sizes */
  if ( o->hw_output_channels != o->output_frames->height ) {
    AUBIO_ERR ("got hw_output_channels = %d, but output_frames has %d rows\n",
        o->hw_output_channels, o->output_frames->height);
  }
  if ( o->blocksize != o->output_frames->length ) {
    AUBIO_ERR ("got blocksize = %d, but output_frames has length %d\n",
        o->blocksize, o->output_frames->length);
  }
  if ( o->hw_input_channels != o->input_frames->height ) {
    AUBIO_ERR ("got hw_input_channels = %d, but input_frames has %d rows\n",
        o->hw_input_channels, o->input_frames->height);
  }
  if ( o->blocksize != o->input_frames->length ) {
    AUBIO_ERR ("got blocksize = %d, but input_frames has length %d\n",
        o->blocksize, o->input_frames->length);
  }

  return o;
}
Exemplo n.º 4
0
aubio_pvoc_t * new_aubio_pvoc (uint_t win_s, uint_t hop_s, uint_t channels) {
	aubio_pvoc_t * pv = AUBIO_NEW(aubio_pvoc_t);

	if (win_s < 2*hop_s) {
		AUBIO_ERR("Hop size bigger than half the window size!\n");
		AUBIO_ERR("Resetting hop size to half the window size.\n");
                hop_s = win_s / 2;
	}

	if (hop_s < 1) {
		AUBIO_ERR("Hop size is smaller than 1!\n");
		AUBIO_ERR("Resetting hop size to half the window size.\n");
                hop_s = win_s / 2;
	}
	
	pv->fft      = new_aubio_mfft(win_s,channels);

	/* remember old */
	pv->data     = new_fvec (win_s, channels);
	pv->synth    = new_fvec (win_s, channels);

	/* new input output */
	pv->dataold  = new_fvec  (win_s-hop_s, channels);
	pv->synthold = new_fvec (win_s-hop_s, channels);
	pv->w        = AUBIO_ARRAY(smpl_t,win_s);
	aubio_window(pv->w,win_s,aubio_win_hanningz);

	pv->channels = channels;
	pv->hop_s    = hop_s;
	pv->win_s    = win_s;

	return pv;
}
Exemplo n.º 5
0
aubio_sink_sndfile_t * new_aubio_sink_sndfile(const char_t * path, uint_t samplerate) {
  aubio_sink_sndfile_t * s = AUBIO_NEW(aubio_sink_sndfile_t);
  s->max_size = MAX_SIZE;

  if (path == NULL) {
    AUBIO_ERR("sink_sndfile: Aborted opening null path\n");
    return NULL;
  }

  if (s->path) AUBIO_FREE(s->path);
  s->path = AUBIO_ARRAY(char_t, strnlen(path, PATH_MAX) + 1);
  strncpy(s->path, path, strnlen(path, PATH_MAX) + 1);

  s->samplerate = 0;
  s->channels = 0;

  // negative samplerate given, abort
  if ((sint_t)samplerate < 0) goto beach;
  // zero samplerate given. do not open yet
  if ((sint_t)samplerate == 0) return s;

  s->samplerate = samplerate;
  s->channels = 1;

  if (aubio_sink_sndfile_open(s) != AUBIO_OK) {;
    goto beach;
  }
  return s;

beach:
  del_aubio_sink_sndfile(s);
  return NULL;
}
Exemplo n.º 6
0
uint_t aubio_sink_sndfile_open(aubio_sink_sndfile_t *s) {
  /* set output format */
  SF_INFO sfinfo;
  AUBIO_MEMSET(&sfinfo, 0, sizeof (sfinfo));
  sfinfo.samplerate = s->samplerate;
  sfinfo.channels   = s->channels;
  sfinfo.format     = SF_FORMAT_WAV | SF_FORMAT_PCM_16;

  /* try creating the file */
  s->handle = sf_open (s->path, SFM_WRITE, &sfinfo);

  if (s->handle == NULL) {
    /* show libsndfile err msg */
    AUBIO_ERR("sink_sndfile: Failed opening %s. %s\n", s->path, sf_strerror (NULL));
    return AUBIO_FAIL;
  }

  s->scratch_size = s->max_size*s->channels;
  /* allocate data for de/interleaving reallocated when needed. */
  if (s->scratch_size >= MAX_SIZE * MAX_CHANNELS) {
    AUBIO_ERR("sink_sndfile: %d x %d exceeds maximum aubio_sink_sndfile buffer size %d\n",
        s->max_size, s->channels, MAX_CHANNELS * MAX_CHANNELS);
    return AUBIO_FAIL;
  }
  s->scratch_data = AUBIO_ARRAY(smpl_t,s->scratch_size);

  return AUBIO_OK;
}
Exemplo n.º 7
0
Arquivo: fvec.c Projeto: aubio/aubio
fvec_t * new_fvec(uint_t length) {
  fvec_t * s;
  if ((sint_t)length <= 0) {
    return NULL;
  }
  s = AUBIO_NEW(fvec_t);
  s->length = length;
  s->data = AUBIO_ARRAY(smpl_t, s->length);
  return s;
}
Exemplo n.º 8
0
lvec_t * new_lvec( uint_t length) {
  lvec_t * s = AUBIO_NEW(lvec_t);
  uint_t j;
  s->length = length;
  s->data = AUBIO_ARRAY(lsmp_t, s->length);
  for (j=0; j< s->length; j++) {
    s->data[j]=0.;
  }
  return s;
}
Exemplo n.º 9
0
aubio_fft_t * new_aubio_fft (uint_t winsize) {
  aubio_fft_t * s = AUBIO_NEW(aubio_fft_t);
#ifdef HAVE_FFTW3
  uint_t i;
  s->winsize  = winsize;
  /* allocate memory */
  s->in       = AUBIO_ARRAY(real_t,winsize);
  s->out      = AUBIO_ARRAY(real_t,winsize);
  s->compspec = new_fvec(winsize);
  /* create plans */
  pthread_mutex_lock(&aubio_fftw_mutex);
#ifdef HAVE_COMPLEX_H
  s->fft_size = winsize/2 + 1;
  s->specdata = (fft_data_t*)fftw_malloc(sizeof(fft_data_t)*s->fft_size);
  s->pfw = fftw_plan_dft_r2c_1d(winsize, s->in,  s->specdata, FFTW_ESTIMATE);
  s->pbw = fftw_plan_dft_c2r_1d(winsize, s->specdata, s->out, FFTW_ESTIMATE);
#else
  s->fft_size = winsize;
  s->specdata = (fft_data_t*)fftw_malloc(sizeof(fft_data_t)*s->fft_size);
  s->pfw = fftw_plan_r2r_1d(winsize, s->in,  s->specdata, FFTW_R2HC, FFTW_ESTIMATE);
  s->pbw = fftw_plan_r2r_1d(winsize, s->specdata, s->out, FFTW_HC2R, FFTW_ESTIMATE);
#endif
  pthread_mutex_unlock(&aubio_fftw_mutex);
  for (i = 0; i < s->winsize; i++) {
    s->in[i] = 0.;
    s->out[i] = 0.;
  }
  for (i = 0; i < s->fft_size; i++) {
    s->specdata[i] = 0.;
  }
#else
  s->winsize = winsize;
  s->fft_size = winsize / 2 + 1;
  s->compspec = new_fvec(winsize);
  s->in    = AUBIO_ARRAY(double, s->winsize);
  s->out   = AUBIO_ARRAY(double, s->winsize);
  s->ip    = AUBIO_ARRAY(int   , s->fft_size);
  s->w     = AUBIO_ARRAY(double, s->fft_size);
  s->ip[0] = 0;
#endif
  return s;
}
Exemplo n.º 10
0
aubio_pitchmcomb_t *
new_aubio_pitchmcomb (uint_t bufsize, uint_t hopsize)
{
  aubio_pitchmcomb_t *p = AUBIO_NEW (aubio_pitchmcomb_t);
  /* bug: should check if size / 8 > post+pre+1 */
  uint_t i, j;
  uint_t spec_size;
  p->spec_partition = 4;
  p->ncand = 5;
  p->npartials = 5;
  p->cutoff = 1.;
  p->threshold = 0.01;
  p->win_post = 8;
  p->win_pre = 7;
  // p->tau              = samplerate/bufsize;
  p->alpha = 9.;
  p->goodcandidate = 0;
  p->phasefreq = bufsize / hopsize / TWO_PI;
  p->phasediff = TWO_PI * hopsize / bufsize;
  spec_size = bufsize / p->spec_partition;
  //p->pickerfn = quadpick;
  //p->biquad = new_biquad(0.1600,0.3200,0.1600, -0.5949, 0.2348);
  /* allocate temp memory */
  p->newmag = new_fvec (spec_size);
  /* array for median */
  p->scratch = new_fvec (spec_size);
  /* array for phase */
  p->theta = new_fvec (spec_size);
  /* array for adaptative threshold */
  p->scratch2 = new_fvec (p->win_post + p->win_pre + 1);
  /* array of spectral peaks */
  p->peaks = AUBIO_ARRAY (aubio_spectralpeak_t, spec_size);
  for (i = 0; i < spec_size; i++) {
    p->peaks[i].bin = 0.;
    p->peaks[i].ebin = 0.;
    p->peaks[i].mag = 0.;
  }
  /* array of pointers to spectral candidates */
  p->candidates = AUBIO_ARRAY (aubio_spectralcandidate_t *, p->ncand);
  for (i = 0; i < p->ncand; i++) {
    p->candidates[i] = AUBIO_NEW (aubio_spectralcandidate_t);
    p->candidates[i]->ecomb = AUBIO_ARRAY (smpl_t, spec_size);
    for (j = 0; j < spec_size; j++) {
      p->candidates[i]->ecomb[j] = 0.;
    }
    p->candidates[i]->ene = 0.;
    p->candidates[i]->ebin = 0.;
    p->candidates[i]->len = 0.;
  }
  return p;
}