Audio recording
d2rk
Posts: 31
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:
The main recording loop looks us follows:
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.
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
If you can read SPIN code take a look at this object: http://obex.parallax.com/object/330. It does WAV recording very well.
You're likely going to want a 2 cog solution. One producer and one consumer.