Ejemplo n.º 1
0
main(int argc, char* argv[])
{
  if (argc != 4)
  {
    fprintf(stderr, "\nUsage: itu_encoder -[a|u] <PCM-File> <ADPCM-File>");
    exit(-1);
  }
  I_file = argv[2];
  O_file = argv[3];

  put_sample(1);

  reset_encoder();
  LAW = argv[1][1] == 'u' ? u_LAW : A_LAW;

  ExitFlag = FALSE;
  while (!ExitFlag)
  {
    get_sample();
    if (ExitFlag)
      break;
    O = encoder(I);
    put_sample(2);
  }

  put_sample(3);
  return (0);
}
/**
 * Used to process a data frame that has just been uploaded.
 */
void block_uploaded(struct rx_frame* rx) {
  uint32_t mem_addr;
  uint32_t checksum, actual_checksum;

  if (rx->length >= MEMORY_RECORD_SIZE) {
    /* Copy the record from the radio packet. Skip the header and memory address */
    memcpy(record, rx->data+5, MEMORY_RECORD_SIZE);

    /* Calculate the checksum */
    actual_checksum = calculate_checksum(record);
    /* Read the checksum */
    checksum = get_checksum(record);

    if (checksum == actual_checksum) {
      /* Extract the memory address */
      mem_addr = get_memory_address_from_rx(rx);

      /* Acknowledge the frame */
      send_upload_ack(rx->source_address, mem_addr, checksum);

      /* Write the record out to memory */
      put_sample(record);

      console_puts("Radio Upload Frame OK\n");
    } else {
      console_puts("Radio Upload Frame Checksum Error!\n");
      console_printf("Frame: %04x\nCalc: %04x\n", checksum, actual_checksum);
    }
  } else {
    console_puts("Radio Upload Frame too short!\n");
  }
}
Ejemplo n.º 3
0
static PyObject*
Sine_Stereo_read(decoders_Sine_Stereo* self, PyObject* args) {
    pcm_FrameList *framelist;
    int requested_frames;
    int frames_to_read;
    int i;
    double d;
    int ia;
    int *samples;

    if (self->closed) {
        PyErr_SetString(PyExc_ValueError, "cannot read closed stream");
        return NULL;
    }

    if (!PyArg_ParseTuple(args, "i", &requested_frames))
        return NULL;

    frames_to_read = MIN(MAX(requested_frames, 1), self->remaining_pcm_frames);

    framelist = new_FrameList(self->audiotools_pcm,
                              2,
                              self->bits_per_sample,
                              frames_to_read);
    samples = framelist->samples;

    for (i = 0; i < frames_to_read; i++) {
        d = ((self->a1 * sin(self->theta1)) +
             (self->a2 * sin(self->theta2))) * (double)(self->full_scale);
        ia = (int)(d + 0.5);
        put_sample(samples, 0, 2, i, ia);
        d = -((self->a1 * sin(self->theta1 * self->fmult)) +
              (self->a2 * sin(self->theta2 * self->fmult))) *
            (double)(self->full_scale);
        ia = (int)(d + 0.5);
        put_sample(samples, 1, 2, i, ia);
        self->theta1 += self->delta1;
        self->theta2 += self->delta2;
    }

    self->remaining_pcm_frames -= frames_to_read;

    return (PyObject*)framelist;
}