Shop OBEX P1 Docs P2 Docs Learn Events
Audio recording — Parallax Forums

Audio recording

d2rkd2rk Posts: 31
edited 2014-04-16 14:19 in Propeller 1
Hi!

I'm trying to record data to WAV from the mic, that is connected to MCP3202. The function for MCP3202 driver that takes a sample has the following view:
mov  value, #0
andn outa, cs_mask  ' begin communication
or outa, di_mask  ' start bit
or outa, ck_mask
andn outa, ck_mask
or outa, di_mask  ' single ended mode
or outa, ck_mask
andn outa, ck_mask
andn outa, di_mask  ' channel 0
or outa, ck_mask
andn outa, ck_mask
andn outa, di_mask  ' MSB only format
or outa, ck_mask
andn outa, ck_mask
or   outa, ck_mask  ' read 13 bits
test do_mask, ina wc
rcl  value, #1
andn outa, ck_mask
or   outa, ck_mask
test do_mask, ina wc
rcl  value, #1
andn outa, ck_mask
or   outa, ck_mask
test do_mask, ina wc
rcl  value, #1
andn outa, ck_mask
or   outa, ck_mask
test do_mask, ina wc
rcl  value, #1
andn outa, ck_mask
or   outa, ck_mask
test do_mask, ina wc
rcl  value, #1
andn outa, ck_mask
or   outa, ck_mask
test do_mask, ina wc
rcl  value, #1
andn outa, ck_mask
or   outa, ck_mask
test do_mask, ina wc
rcl  value, #1
andn outa, ck_mask
or   outa, ck_mask
test do_mask, ina wc
rcl  value, #1
andn outa, ck_mask
or   outa, ck_mask
test do_mask, ina wc
rcl  value, #1
andn outa, ck_mask
or   outa, ck_mask
test do_mask, ina wc
rcl  value, #1
andn outa, ck_mask
and value, sample_mask  ' trim value (12-bits)
or  outa, cs_mask  ' end communication

The main recording loop looks us follows:
void record() {
  int32_t clocks_per_sample = CLKFREQ / 16000;  /* 16KHz sample rate */
  int32_t time_counter = clocks_per_sample + CNT;
  uint16_t i = 0;
  uint16_t j = 0;
  uint16_t sample;
  mcp3202_init();
  while (1) {
    time_counter = waitcnt2(time_counter, clocks_per_sample);
    for (i = 0; i < BUFFER_BLOCK_SIZE; ++i) {
      sample = mcp3202_get_sample();
      buffer[j++] = sample;
    }
    j &= BUFFER_SIZE - 1;
    blocks_counter = (blocks_counter + 1) & (BUFFER_NUM_BLOCKS - 1);
  }
}

Another function reads the buffer and writes the data to the SD card with required WAV header. The file is playable but too noisy. I can here just some fragments. Where can be the problem?

Thanks.

Comments

Sign In or Register to comment.