Hi,
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?
Thanks!
Hi,
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?
Thanks!
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 )
Thanks for replying so quick!
I'm using T3.5 running at 168MHz. I just changed it to 120MHz and it compiled OK!!
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?
Thanks
-Akshay
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,
Jaco
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 ( https://github.com/Gambalunga/Audio_FeatherM0 ) 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.
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.
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:Code:#ifndef AUDIO_SAMPLE_RATE_EXACT #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_PRESCALER TC_CTRLA_PRESCALER_DIV64 //#define AUDIO_SAMPLE_RATE_EXACT 22058.82353 // 120 MHz / 64 / 85 //#define AUDIO_TC_FREQ 22000 #define AUDIO_CLKRATE (VARIANT_GCLK2_FREQ >> 4) #define AUDIO_PRESCALER TC_CTRLA_PRESCALER_DIV16 #define AUDIO_SAMPLE_RATE_EXACT 44014.085 // 100 MHz / 16 / 142 #define AUDIO_TC_FREQ 44100 #endif // SAMD51 #endif // AUDIO_SAMPLE_RATE_EXACT
AUDIO_CLKRATE (VARIANT_GCLK2_FREQ >> 4)
AUDIO_PRESCALER TC_CTRLA_PRESCALER_DIV16
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
and
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.
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.
@FrankB, I am having a hard time understanding how to change the sampling frequency of the PT8211 using your routines...
When I try to use your routines I2S_MDR_DIVIDE and I2S_MDR_FRACT are not defined.
These are my #include
#include <Arduino.h>
#include <Audio.h>
#include <AudioStream.h>
#include <DMAChannel.h>
What am I missing?
Thank you so much!
On a Teensy4?
Try this:
Code:#include <utility/imxrt_hw.h> void setI2SFreq(int freq) { //Teensy 4 // PLL between 27*24 = 648MHz und 54*24=1296MHz int n1 = 4; //SAI prescaler 4 => (n1*n2) = multiple of 4 int n2 = 1 + (24000000 * 27) / (freq * 256 * n1); double C = ((double)freq * 256 * n1 * n2) / 24000000; int c0 = C; int c2 = 10000; int c1 = C * c2 - (c0 * c2); set_audioClock(c0, c1, c2, true); CCM_CS1CDR = (CCM_CS1CDR & ~(CCM_CS1CDR_SAI1_CLK_PRED_MASK | CCM_CS1CDR_SAI1_CLK_PODF_MASK)) | CCM_CS1CDR_SAI1_CLK_PRED(n1-1) // &0x07 | CCM_CS1CDR_SAI1_CLK_PODF(n2-1); // &0x3f }
Thank you for all your great contributions to the Forum, @frankB
This works pretty good! thanks Frank B,
I'm getting some issues with abrupt changes to lower values, sound turns off if I switch from 44100 to 22050, but it works fine with other values ...and I have no idea why,
45100 -> 22550 ok
44100 -> 22050 no sound
43100 -> 21550 ok
I don't know, why. Maybe try to disable the interrupts when switching the rate. I have never tried that - But I know of an application that sets 176khZ in one step, without problems.