Exemple #1
0
int note_init(struct note_t *self_p,
              int note,
              int32_t *waveform_p,
              size_t length,
              float frequency,
              float vibrato,
              long attack,
              long decay,
              long release,
              int sample_rate)
{
    self_p->note = note;

    oscillator_init(&self_p->oscillator,
                    waveform_p,
                    length,
                    frequency,
                    vibrato,
                    sample_rate);

    return (envelope_init(&self_p->envelope,
                          attack,
                          decay,
                          release));
}
Exemple #2
0
vorbis_packet_t *vorbis_packet_init(uint16_t *blocksize, uint8_t nb_chan){

  vorbis_pkt_cache_t *packet = malloc(sizeof(vorbis_pkt_cache_t));

  if(packet == NULL)
    return NULL;

  packet->base.nb_chan = nb_chan;
  packet->base.size = blocksize[1];
  packet->init = 0;

  //Init filter
  packet->filter = calloc(blocksize[1],sizeof(sample_t));

  //Init envelope
  packet->envelope = envelope_init(blocksize);
  
  //Init packet cache
  packet->cache = malloc(nb_chan * sizeof(sample_t*));
  if(packet->cache == NULL)
    return NULL;
  for(uint32_t i=0;i<nb_chan;i++){
    packet->cache[i] = malloc(blocksize[1] * sizeof(sample_t));
    if(packet->cache[i] == NULL)
      return NULL;
    for(uint32_t j=0;j<blocksize[1];j++)
      packet->cache[i][j] = 0;
  }

  //Dec_residues
  packet->base.dec_residues = malloc(nb_chan * sizeof(sample_t*));
  if(packet->base.dec_residues == NULL)
    return NULL;

  packet->base.dec_residues[0] = malloc(nb_chan * (blocksize[1]/2) * sizeof(sample_t));
  if(packet->base.dec_residues[0] == NULL)
    return NULL;
  for(uint8_t i=1;i<nb_chan;i++){
    packet->base.dec_residues[i] = malloc( blocksize[1]/2 * sizeof(sample_t));
    if(packet->base.dec_residues[i] == NULL)
      return NULL;
  }

  //do not decode
  packet->base.do_not_decode = malloc(nb_chan * sizeof(uint8_t));
  if(packet->base.do_not_decode == NULL)
    return NULL;

  //no residue
  packet->base.no_residue = malloc(nb_chan * sizeof(uint8_t));
  if(packet->base.no_residue == NULL)
    return NULL;

  //pcm
  packet->base.pcm = malloc(nb_chan * sizeof(int16_t*));
  if(packet->base.pcm == NULL)
    return NULL;
  for(uint8_t i=0;i<nb_chan;i++){
    packet->base.pcm[i] = malloc( blocksize[1] * sizeof(int16_t));
    if(packet->base.pcm[i] == NULL)
      return NULL;
  }

  //residues
  packet->base.residues = malloc(nb_chan * sizeof(sample_t*));
  if(packet->base.residues == NULL)
    return NULL;

  //spectral
  packet->base.spectral = malloc(nb_chan * sizeof(sample_t*));
  if(packet->base.spectral == NULL)
    return NULL;
  
  for(uint8_t i=0;i<nb_chan;i++){
    packet->base.spectral[i] = malloc( blocksize[1]/2 * sizeof(sample_t));
    if(packet->base.spectral[i] == NULL)
      return NULL;
  }

  //temporal
  packet->base.temporal = malloc(nb_chan * sizeof(sample_t*));
  if(packet->base.temporal == NULL)
    return NULL;
  for(uint8_t i=0;i<nb_chan;i++){
    packet->base.temporal[i] = malloc( blocksize[1] * sizeof(sample_t));
    if(packet->base.temporal[i] == NULL)
      return NULL;
  }

  return (vorbis_packet_t*)packet;
}