Forum Rule: Always post complete source code & details to reproduce any issue!
Page 4 of 4 FirstFirst ... 2 3 4
Results 76 to 82 of 82

Thread: Discussion about a simple way to change the sample-rate

  1. #76
    Junior Member
    Join Date
    Jan 2019

    I just tried the code out in message #44 and received the following error message when. compiling.

    'clkArr' was not declared in this scope

    Any ideas?


  2. #77
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Looking at the code its definition is based on the value of the F_PLL.

    What Teensy and clock speed is in use?

    Write a short sketch using the same compile params and speed and Serial.print( F_PLL ) and Serial.print( F_CPU )

  3. #78
    Junior Member
    Join Date
    Jan 2019
    Thanks for replying so quick!

    I'm using T3.5 running at 168MHz. I just changed it to 120MHz and it compiled OK!!

  4. #79
    Hi Frank,
    I wanted to tryout your sample rate changing code for the Teensy 4, which I pulled from CorBee's Bat Detector repo on github. It seems that it's not perhaps compatible with the Teensy 4 as I2S0_MCR & I2S_MCR_DUF are showing up as undefined during compilation. On a more recent thread Paul mentioned that the 3.6 and 4 have different ways of using the MCLK as seen here. What changes should be needed for the Teensy 4? Any resources I should look into?

  5. #80
    Good day,

    I encounter the same issue as mentioned in the last post. How can we adapt the code for the Teensy 4.1?

    Thank you,

  6. #81
    Junior Member
    Join Date
    Aug 2020
    Hi all

    This is my first post on this forum and it touches on a subject that I am having difficulty getting my head around. I know this thread is now somewhat ancient history but it turned up when I was searching for a way of resolving my particular problem

    Unlike some I am not interested in a high audio sample rate but in a relatively low one. The reason is that I want to play a simple WAV file that has been stored on the flash memory of an Adafruit Feather M4 Express. The 2MB of space available allows the storage of about 2 minutes an 8 bit mono audio with sample rate of 16000 Hz. I wish to play this over one of the internal DACs on the SAMD51.

    I have used an updated version of the SamdAudio library to get it working on Feather M0 Express ( ) but that will not compile for the M4.

    I have tried using the Adafruit fork of the Teensy Audio library and managed to get the example sketch WavFilePlayer.ino (with a tiny mod) to compile and load. Clearly, however, 2MB of on board flash is not going give any useful period of sound at stereo 44117 Hz. and I can get it playing about 11 seconds of music.

    I noted the section of code below but I am not sure if it is relevant to my problem or even how to implement it in the sketch.
    Quote Originally Posted by Frank B View Post
    Here's the same for the internal DACs :

    void setDACFreq(int freq) {
    const unsigned config = PDB_SC_TRGSEL(15) | PDB_SC_PDBEN | PDB_SC_CONT | PDB_SC_PDBIE | PDB_SC_DMAEN;
        PDB0_SC = 0;
        PDB0_IDLY = 1;
        PDB0_MOD = round((float)F_BUS / freq ) - 1;    
        PDB0_SC = config | PDB_SC_LDOK;
        PDB0_SC = config | PDB_SC_SWTRIG;
        PDB0_CH0C1 = 0x0101;    
    edit: Added one line
    I noticed the following section of code in AudioStream.h and wondered if it could be modified to give me the 16000 sample rate that I require.
    #if defined(__MK20DX128__) || defined(__MK20DX256__) || defined(__MK64FX512__) || defined(__MK66FX1M0__)
    #define AUDIO_SAMPLE_RATE_EXACT 44117.64706 // 48 MHz / 1088, or 96 MHz * 2 / 17 / 256
    #elif defined(__MKL26Z64__)
    #define AUDIO_SAMPLE_RATE_EXACT 22058.82353 // 48 MHz / 2176, or 96 MHz * 1 / 17 / 256
    #elif defined(__SAMD51__)
    //#define AUDIO_CLKRATE (SystemCoreClock >> 6)
    //#define AUDIO_SAMPLE_RATE_EXACT 22058.82353 // 120 MHz / 64 / 85 
    //#define AUDIO_TC_FREQ 22000
    #define AUDIO_SAMPLE_RATE_EXACT 44014.085 // 100 MHz / 16 / 142
    #define AUDIO_TC_FREQ 44100
    #endif // SAMD51
    It seems to me that if the following were defined with different values I may be able to get the 16000 Hz that I require:

    AUDIO_SAMPLE_RATE_EXACT 44014.085 // 100 MHz / 16 / 142
    AUDIO_TC_FREQ 44100

    Does anyone have any idea of how this may be made to function?

    perhaps defining
    AUDIO_SAMPLE_RATE_EXACT 16025.641 // 100 MHz / 16 / 390
    AUDIO_TC_FREQ 16000

    It seems too easy and I am not sure if that "390" has to be specified somewhere else or even if it can be used.

  7. #82
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    This forum is for Teensy. If you're using Adafruit's hardware (and their modified copies of Teensy's software), ask for support on Adafruit's forum.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts