Page 1 of 1

using slower sample rate

PostPosted: Thu Apr 10, 2014 10:54 pm
by rputra
Hi I'm quite new with this codec shield. I'm using maple board from leaflabs to interface with the audio codec shield. For some reason, I want to generate 1kHz sine wave at 2.145kHz sample rate instead of using the default 44.1Khz. But, I could not do it, the output waveform is just a really noisy sine wave which is not even at 1Khz.

This is part of my code:
Code: Select all
#define SAMPLE_RATE 2
//#define SAMPLE_RATE 44

int16 sinewave[] __FLASH__ = {
  #include <>

const uint16 realSamplerate = 2450;
//const uint16 realSamplerate = 44100;
const uint16 sineSize = 1024;
uint16 currentFreqL = 1000;
int16 tempL;
uint16 locationL;

samplesPerSinewaveL = realSamplerate / currentFreqL;
sineIncL = sineSize/ samplesPerSinewaveL;   

tempL = sinewave[locationL];
locationL += sineIncL;
locationL &= 0x03ff;

Re: using slower sample rate

PostPosted: Fri Apr 11, 2014 12:32 am
by guest
i would suggest running the sine_generator test code, and seeing if you can generate a 1khz tone by turning the knob. what im suspecting is happening, is that your increment calculation is turncating, and you are jumping ahead by 512 samples each time. but, if you start at position 0, you jump to 512, and then to 0, etc. the values at 0 and 512 are identical, and therefore no output is produced.

Re: using slower sample rate

PostPosted: Mon May 12, 2014 5:43 pm
by rputra
Thanks, that is exactly what happened. I tried to generate a little bit higher frequency (i.e. at 1.25 kHz), and it worked.