-
Notifications
You must be signed in to change notification settings - Fork 33
Evaluating SD Card Performance
Writing audio to the SD card is very important to some users of the Tympan. Everyone wants to be able to have confidence that the audio written to the SD card is continuous, with no drop-outs or other kinds of "hiccups". It turns out that, as long as your Tympan sketch is not using 100% of the CPU, the most important factor for ensuring smooth writing to the SD card is the specific SD card that you use. Low quality SD cards will not allow you to write audio smoothly.
As of writing this (June 2021), we always use SanDisk Ultra 32GB or SanDisk Extreme 32GB. The Ultra is what we have been using since 2018. We started getting the Extreme recently when we had a hard time finding Ultra. We've only ever used the 32GB version.
There may be better choices now.
This document discusses different ways that one can evaluate whether the SD card that you have is good for writing audio. There are many ways that SD cards can be evaluated. We are not experts. Please improve this list of techniques!
For best SD card performance in any device, you should ensure that your SD card is properly formatted. Also, if you occasionally reformat your SD card, it will ensure that its performance stays high. You should use the official SD formatting software, here: https://www.sdcard.org/downloads/formatter/. No, really, this is important. It can have a huge impact on SD write performance! Really!
This is a short test, so it is not the best test for ensuring that you have good performance in the field. But, if you show bad performance here, you will definitely have bad performance in the field. So, make sure that your SD card shows good results!
With the latest Teensyduino (for me right now, that is V1.54 Beta #5), you get the SdFat library during the Teensyduino installation. It comes with example sketches that let you test your SD card. In the Arduino IDE, go File->Examples->SdFat->TeensySdioDemo. If you are using a Tympan RevD (which is a Teensy 3.6) or a Tympan Reve (which is a Teensy 4.1), no changes to the sketch are necessary. Simply compile and run.
Once it is compiled and on your Tympan, open the Serial Monitor. You'll see that it is offering you four choices. I don't know which is best, but I choose the first or second option. It then tries to read and write from the SD card using different sized packets.
Here are the results that I get for "FIFO SDIO Mode" with my SanDisk Ultra 32GB on a Tympan RevD (Teensy 3.6):
size,write,read
bytes,KB/sec,KB/sec
512,12874.12,18889.05
1024,13210.95,18950.37
2048,12539.87,19236.09
4096,12569.44,19227.23
8192,13911.39,19368.93
16384,13455.59,19388.90
32768,13586.18,19412.46
The middle column is the write speed (kB/sec), which is the relevant value for our desire to smoothly write audio. If your values are a lot lower than these values, you will want to find better card.
Here are the results that I get for "FIFO SDIO Mode" with my SanDisk Ultra 32GB on a Tympan RevE (Teensy 4.1):
size,write,read
bytes,KB/sec,KB/sec
512,18153.43,22817.27
1024,19680.30,22843.05
2048,21409.72,22901.17
4096,9049.92,22921.26
8192,19744.27,22942.01
16384,19728.62,22950.80
32768,18330.47,22955.00
For this FIFO mode test, the RevE is about 20% faster than the RevD, which is great. But, if you choose to do the DMA mode test instead of FIFO mode (again, I do not know which is a better representation of how Tympan writes audio), I aw no difference in the write speed between the RevD and RevE. So, RevE is not necessarily faster in writing to SD than RevD; it depends upon the write mode.
As another comparison, I looked at the write speed for the SanDisk Ultra to the SanDisk Extreme, both of which are pretty good cards. In my test, I saw that the Extreme is about 20-30% faster in FIFO mode. But, in DMA mode, I saw that the Extreme can be very different from the Ultra. In some tests, the Extreme showed a write speed that was only 52% of the Ultra. In another test, the Extreme showed 126% of the write speed of the Ultra. Averaging across all tests, the Extreme in DMA mode had a write speed that was only 75% of the Ultra (ie, it was 25% slower).
Which card is better? It appears to be a complicated question. Both cards, though, are way better than the five other cards that I tested in 2018. Those other cards were showing write speeds that were much lower: ranging from 15% to 57% of the write speed of the Ultra, with the overall average being 35% the write speed of the Ultra. So, yes, the choice of SD card can make a very large difference.
This testing is a lot harder because a "hiccup" is an intermittent thing. It is difficult to force hiccups to happen. The hiccup is usually caused, I believe, by an unusually long latency between your hardware asking the SD card if it can start writing and the SD card replying with a "yes, go ahead!". This can be a very short delay or a very long one. And, it seems to be independent of how fast the actual write speed (as measured with the previous test) once it is able to get started. You can have a super-fast write speed along with a super-long latency. If the latency is too long, though, the Tympan will have run out of audio buffer, and you'll loose some audio. You will have gotten a "hiccup".
Right now, I can only offer a description of my test approach, not a real step-by-step with example code. Below is what I tend to do.
- Setup
- Four channel system, recording all 4 channels, sample rate at 96 kHz with a block size of 128 points.
- Ideally, you’re also running a heavy audio processing load, but I don’t have a great example to point to. Either way, the 4-chan / 96 kHz combination puts a lot of stress on the SD system, which is good
- In the sketch, prior to sending the recorded audio stream to the SD card, you actually replace one of the four audio streams with a synthesized sine wave (1kHz) via the Tympan library. This makes a known signal that we can look for hiccups in
- Or, you could feed a sine wave into the Tympan’s pink jack (as maybe generated from a 2nd Tympan) and skip the synthesized signal described above. This is actually a better test but requires a second device to generate the sine wave.
- Either way, if it hiccups, it hiccups on all 4 channels, so we only need to put the known signal into one of the channels, not all four.
- Four channel system, recording all 4 channels, sample rate at 96 kHz with a block size of 128 points.
- Recording
- Let it record for 20 minutes.
- At the end of the recording, look for warning messages in the Serial Monitor. This might point to moments in time that are suspect…it’ll help focus your manual review of the data in the next step
- Analysis
- Copy recording to PC, open in Audacity (or whatever), switch to spectrogram view
- Again, you need switch to spectrogram view in order to more easily see the hiccup (the discontinuity in the recording)
- Scroll through the recording looking for anything that doesn’t look like a steady 1kHz tone
- You only need to look at the one channel holding the sine wav, no need to look at the other 3 channels
- The 1 kHz tone will look like a steady horizontal line; a hiccup will appear as a super-narrow vertical line
- You have to be zoomed in in time by a surprising amount in order to see the super-short hiccups. As a result, it can take a long time to scroll through manually. Ugh.
- Copy recording to PC, open in Audacity (or whatever), switch to spectrogram view
- Alternative Analysis:
- I sometimes try to program something in Matlab to scan through the file automatically to detect the hiccup. I never got an algorithm that was totally dependable, but it was sorta helpful