The audio3 code uses double buffers. The ADC reads the buffer until it’s full, then switched to the other buffer. When a buffer is full, the loop code sends it out using TCP. If the network was really slow, it’s possible that the send would not complete before the DMA code switches back to that buffer. The sample code does not detect this, and instead just sends out corrupted data.
The optimal size for writing to TCP is 1024 bytes in most cases. You can make it 512 bytes, but contrary to what you might think, making it larger makes the performance worse, so there is no reason to make it larger than 1024 bytes.
Also, there is never any reason to put a delay in when writing to TCP. With the Photon, if write returns -16 you must just send the same buffer again. That will allow you to send at the maximum rate possible.
The reason buffers larger than 1024 bytes are not helpful is that there is an internal buffer in the TCP stack. I think it’s about 3K. In order for write to succeed, there must be enough empty space in the buffer to write the whole thing. If you try to do large writes, it has to wait so long for there to be enough free space in the buffer than the buffer usually empties out before it can be refilled. The -16 return code means there wasn’t enough free space.
The same thing happens when you use really small buffers, say 100 bytes. The reason is that the loop only runs 1000 times per second, and you can’t keep the buffer full.
Since you can only have 2 DMA buffers, if you want to make the buffers bigger you should split the TCP writes up into 1024 byte writes for best performance.
Tha maximum ADC sample rate is 6 M samples/sec but it’s really hard to use at that rate because it generates data faster than you can reasonably consume it. There’s probably a minimum rate, but it depends on what prescaler value and timer you use. With a large prescaler it probably could sample quite slowly, like seconds per sample.
Here are the documents that I often reference:
STM32F205xx Data Sheet
STM32F2xx Standard Library
STM32F205 Programming Manual
STM32F205 Reference Manual