8bit recording with Audio Adaptor Board for Teensy

Status
Not open for further replies.

muffinsticks

New member
Hi everyone ( and paul if hes looking!),

I am looking to do some recording short voice clips using the input on the Audio Adaptor Board for Teensy.
My main concern is keeping the clip byte size as small as possible while still being able to hear what is being said in the voice clip during playback.
I was wondering if recording 8 bit instead of 16 bit is an option already in the Audio library?

Thanks,
Muffinsticks
 
You could modify the File > Examples > Audio > Recorder example to convert the 16 bit data to only 8 bits.

Find this code:

Code:
void continueRecording() {
  if (queue1.available() >= 2) {
    byte buffer[512];
    // Fetch 2 blocks from the audio library and copy
    // into a 512 byte buffer.  The Arduino SD library
    // is most efficient when full 512 byte sector size
    // writes are used.
    memcpy(buffer, queue1.readBuffer(), 256);
    queue1.freeBuffer();
    memcpy(buffer+256, queue1.readBuffer(), 256);
    queue1.freeBuffer();
    // write all 512 bytes to the SD card
    elapsedMicros usec = 0;
    frec.write(buffer, 512);
    // Uncomment these lines to see how long SD writes
    // are taking.  A pair of audio blocks arrives every
    // 5802 microseconds, so hopefully most of the writes
    // take well under 5802 us.  Some will take more, as
    // the SD library also must write to the FAT tables
    // and the SD card controller manages media erase and
    // wear leveling.  The queue1 object can buffer
    // approximately 301700 us of audio, to allow time
    // for occasional high SD card latency, as long as
    // the average write time is under 5802 us.
    //Serial.print("SD write, us=");
    //Serial.println(usec);
  }
}

Perhaps modify it to grab 4 blocks, instead of only 2. Of course, instead of memcpy(), you'd write loops to read the 16 bit samples and copy only 8 of the bits to the buffer which gets written to the SD card.
 
No, you can't simply reduce the sample rate by discarding data. If you try, you'll get a problem called "aliasing".

TL;DR = You *must* filter the signal to remove everything above half the new sample frequency before you discard any data.

Plenty of info online.

http://www.mstarlabs.com/dsp/antialiasing/antial.html

http://dspguru.com/dsp/faqs/multirate/decimation

The good news is the audio lib has 3 types of filters. All filters have a roll-off rate, which means you always have a sacrifice some of the spectrum you wanted to get enough attenuation in the part you need to filter away.
 
Would it possible to change the sampling frequency of the SGTL5000?

The SGTL5000 can accept an external standard master
clock at a multiple of the sampling frequency (i.e. 256*Fs,
385*Fs, 512*Fs). In addition it can take non-standard
frequencies and use the internal PLL to derive the audio
clocks. The device supports 8.0 kHz, 11.025 kHz, 16 kHz,
22.05 kHz, 24 kHz, 32 kHz, 44.1kHz, 48 kHz, 96 kHz
sampling frequencies.

https://www.pjrc.com/teensy/SGTL5000.pdf

would this be a big undertaking?
 
Would it possible to change the sampling frequency of the SGTL5000?

The SGTL5000 can accept an external standard master
clock at a multiple of the sampling frequency (i.e. 256*Fs,
385*Fs, 512*Fs). In addition it can take non-standard
frequencies and use the internal PLL to derive the audio
clocks. The device supports 8.0 kHz, 11.025 kHz, 16 kHz,
22.05 kHz, 24 kHz, 32 kHz, 44.1kHz, 48 kHz, 96 kHz
sampling frequencies.

https://www.pjrc.com/teensy/SGTL5000.pdf

would this be a big undertaking?
Sure you can change sampling rate of audioboard, but adapting Paul's audio software to the new sampling rate may not be so easy. So, you have to write your own software.

Edit: I didn't see Paul's reply (replied to an older Search result)
 
Can i ask a question, too ? I don't know much about aliasing, analog electronics, and so on..
How does the ADC work ? Doe it sample the voltage at the beginning of the conversion-process, or how does this work ? What happens to the resulting values when the voltage is changing during the conversion ?
 
How does the ADC work ?

The ADC built into Teensy uses a sample and hold circuit and successive approximation based on capacitive charge redistribution. Successive approximation is similar to binary search. The signal is checked for half voltage, and then if it's higher, it's checked for 3/4 of the voltage, and so on. Each round gives another bit. The sample time is adjustable by one of the hardware registers. After the sample time ends and conversion begins, Teensy is basically ignoring the input voltage.

The SGTL5000 (probably) uses an oversampling sigma-delta modulator and decimation filter. Because the modulator clocks very fast (probably half or a quarter of MCLK) the signal is being measured more or less continuously, as far as audio bandwidth is concerned. Sigma-delta modulation is a craft analog feedback circuit which allows a low res ADC, which is likely just 1 bit in SGTL5000, to have its massive measurement errors "noise shaped" into only the higher frequencies where they are spectrally separate from the audio signal. The results we get over I2S are the output of a digital filter. The filter discards all the extra high frequency stuff and reduces the rate to 44 kHz.
 
Last edited:
Status
Not open for further replies.
Back
Top