user15159: I have setup a MCP3002 to convert an analog signal to digital signal. When I read it directly through serial and convert it to a wav file, it sounds relative clear. Serial is limited for samples per second though, I can get about 7000 sps.
When I send the signal directly to a server I can reach around 17.500 sps. however when I convert this to a wav file, it also sounds relative clear, but with a slight distortion/'robot voice' through the audio.
Is there a simple way to prevent this, or why is this happening?
The code how I read the SPI is in this question:
Reading data from MCP3002

user7508: From the code you linked to, it appears the SPI port is completely
controlled by the software:
void loop() {
    ...
    msb = SPI.transfer(cmd);
    lsb = SPI.transfer(0);
    ...
}

This means that the timing of the SPI transaction (when exactly it
starts) and, by extension, the timing of the ADC conversion, is
dependent on the timing of your code execution. You have no good control
on that timing. It depends on what other things may be in your loop, and
on the other interrupt sources (timers, network...).
The least you can do is set up a timer interrupt, and run the SPI from
the interrupt handler. Your timings should then be more consistent. You
will still have some jitter due to the interrupt handler being delayed
by some critical sections, including other interrupts. But it may be
good enough for your application.
For best results, you would ideally want the timing to be completely
controlled by hardware. Maybe there is a way to trigger the SPI port
from a timer. This depends on the specific MCU you are using: you will
have to dig into the datasheet.

15159: <p>I have setup a MCP3002 to convert an analog signal to digital signal. When I read it directly through serial and convert it to a wav file, it sounds relative clear. Serial is limited for samples per second though, I can get about 7000 sps.</p>

<p>When I send the signal directly to a server I can reach around 17.500 sps. however when I convert this to a wav file, it also sounds relative clear, but with a slight distortion/'robot voice' through the audio.</p>

<p>Is there a simple way to prevent this, or why is this happening?</p>

<p>The code how I read the SPI is in this question:
<a href="https://arduino.stackexchange.com/questions/69573/reading-data-from-the-mcp3002">Reading data from MCP3002</a></p>
 7508: <p>From the code you linked to, it appears the SPI port is completely
controlled by the software:</p>

<pre class="lang-cpp prettyprint-override"><code>void loop() {
    ...
    msb = SPI.transfer(cmd);
    lsb = SPI.transfer(0);
    ...
}
</code></pre>

<p>This means that the timing of the SPI transaction (when exactly it
starts) and, by extension, the timing of the ADC conversion, is
dependent on the timing of your code execution. You have no good control
on that timing. It depends on what other things may be in your loop, and
on the other interrupt sources (timers, network...).</p>

<p>The least you can do is set up a timer interrupt, and run the SPI from
the interrupt handler. Your timings should then be more consistent. You
will still have some jitter due to the interrupt handler being delayed
by some critical sections, including other interrupts. But it may be
good enough for your application.</p>

<p>For best results, you would ideally want the timing to be completely
controlled by hardware. Maybe there is a way to trigger the SPI port
from a timer. This depends on the specific MCU you are using: you will
have to dig into the datasheet.</p>
