Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 10 of 10

Thread: Teensy 4.1 extra memory question

  1. #1
    Junior Member
    Join Date
    Sep 2019
    Location
    Sevilla, Spain
    Posts
    19

    Teensy 4.1 extra memory question

    Hi all,
    working on a project with T_4.1 here, would like to know a little more about the flash memory on this board,
    I've seen some detailed information about the memory on T_4.0 product page but didn't find anything about T_4.1

    I would like to know if the extra flash memory could be used for playFlashRaw,
    if not, is there a (more or less easy) way to copy audio files from the microSD card to the flash memory?
    I know wav2sketch but need something to do the task within the Teensy itself

    thanks in advance

  2. #2
    Senior Member+ MichaelMeissner's Avatar
    Join Date
    Nov 2012
    Location
    Ayer Massachussetts
    Posts
    3,828

    Cool

    There is the memory on the board itself that is similar in spirit to the Teensy 4.0 (except a few things are larger). For read-only sounds, you would initialize it as a large const char array, and have it downloaded via the normal installation process. You would typically want to use 'const FLASHMEM' to declare this array. In the Teensy 4.1 you have 8 megabytes of memory minus the reserved size for program reload and EEPROM (64K) and minus the size of the initialized code/data that is copied to the SDRAM memory at sketch startup. The Teensy 4.0 only had 2 megabytes of flash memory. This means you have 6 more megabytes of space to put read-only data.

    Then there are two sets of solder pads underneath the Teensy 4.1 that allow you to solder 2 psram chips, or 1 psram chip and 1 flash memory chip to the Teensy.

    The psram chip is volatile memory, in that every time you power cycle the chip, the contents vanish. But you can use this chip as normal memory (though I believe access may be slower if the values aren't in the cache). The only known chip that works is the 8 megabyte (64 megabit) psram chip that a few vendors sell (pjrc.com, adafruit.com, aliexpress.com, electrodragon.com, exp-tech.de).

    The flash memory is persistent storage. Typically you would mount a filesystem on the flash memory, and access it via files. The typical size for the flash memory is 16 megabytes (256 megabit).

    Teensydunio 1.53 will automatically initialize both chips if they exist. The memory address starts at 0x70000000.

    At the moment, the filesystem used for flash memory tends to be SPIFFS. At the moment, there is no support for audio support for files with SPIFFS in Teensydunio 1.53. Paul has said one of the things he would like to do in 1.54 is add support to the audio system to handle file systems.

    I put a little more information in the unofficial wiki page for Teensy:

  3. #3
    Senior Member
    Join Date
    May 2015
    Location
    USA
    Posts
    560
    > access may be slower

    I did a quick test of initializing an array of 200,000 uint16s and it was 23 times slower.

  4. #4
    Senior Member+ MichaelMeissner's Avatar
    Join Date
    Nov 2012
    Location
    Ayer Massachussetts
    Posts
    3,828
    Quote Originally Posted by jonr View Post
    > access may be slower

    I did a quick test of initializing an array of 200,000 uint16s and it was 23 times slower.
    Well it is cached. So if the data is concentrated in one spot, after the first time through the loop, it will be much faster. It should be faster than the current micro SD card using the default SD library.

  5. #5
    Junior Member
    Join Date
    Sep 2019
    Location
    Sevilla, Spain
    Posts
    19
    ey! thanks a lot for the info, I'm getting crazy trying to figure out how to manage this,
    my idea was making a function in my sketch so the raw files in the SD card were copied to the flash memory (because the playRaw from SD has a very limited performance)
    just soldered a flash chip on the bottom, installed teensy41_extram, SPIFFS_t4 and extRAM_SPIFFS_t4 libraries ,
    ran a test sketch and it works,
    but if the external can't be used for the audio library then the only option is wav2sketch and use the internal flash, am I correct?
    trying to convert files right now with wav2sketch but at the moment it does nothing :_(

  6. #6
    Senior Member
    Join Date
    May 2015
    Location
    USA
    Posts
    560
    A little more testing of EXTMEM speed. Writing up to 48 uint16s was as fast as ram.

  7. #7
    Junior Member
    Join Date
    Sep 2019
    Location
    Sevilla, Spain
    Posts
    19
    Quote Originally Posted by MichaelMeissner View Post
    The Teensy 4.0 only had 2 megabytes of flash memory. This means you have 6 more megabytes of space to put read-only data.
    The problem I'm facing now is that AudioPlayMemory object takes lots of ram for every added sample file, so I still have plenty of flash memory left, but with only 10 samples (converted with wav2sketch) the compiler says I'm using more than 100% of the ram

    RAM: [==========] 101.7% (used 533172 bytes from 524288 bytes)
    Flash: [ ] 4.1% (used 330832 bytes from 8126464 bytes)

    and I need to load lots of samples (minimum 64)... so if the extra program memory is not useful because what I need can't be done with AudioPlayMemory, and the flash memory chip I've just placed on the t_4.1 can't be used for audio the only option is to use an external flash chip,

    do you see other alternative?

  8. #8
    Quote Originally Posted by M4ngu View Post
    do you see other alternative?
    Can you place the samples in Flash and copy the current one into ram before playing it ?

  9. #9
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    7,406
    Question can you not simply have the samples stay in flash memory?

    If I look at the example sketch SamplePlayer, I see that it's samples are stored in flash memory...
    That is if I look at the cpp files. I see stuff like:
    Code:
    #include "AudioSampleKick.h"
    #include <Arduino.h>
    // Converted from kick.wav, using 22050 Hz, 16 bit PCM encoding
    PROGMEM
    const unsigned int AudioSampleKick[2561] = {
    0x820013EC,0xFFDC0027,0xFF710095,0x038DFF4C,0xFBA10105,0x0037FB6E,0x09D2011A,0x007504CA,
    0x024BF6BF,0xF77B0AFF,0xFB72F723,0xEF3DEBAD,0x0F7009D6,0x09DD1736,0xF26EFA3E,0x0D7002FB,
    0xFF4401F1,0x06B20406,0xF83306AF,0xFC9DF1A9,0xFCC601C7,0x0423F387,0x11F011ED,0xF727066F,
    ...
    So the main data should be left in the FLASH and not take up your main memory...

    You might take a look at your files and see if they are marked as PROGMEM ?

    As I looked at some other examples like the ADAT_DrumSamplePlayer sketch and See for example:

    It's gong file starts off like:
    Code:
    #include "AudioSampleGong.h"
    
    // Converted from gong.wav, using 11025 Hz, u-law encoding
    const unsigned int AudioSampleGong[27633] = {
    0x0301AFA4,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,
    0x00000000,0x00000000,0x00000000,0x00000000,0x00008000,0x00000000,0x00000000,0x80800000,
    0x00000000,0x00000000,0x00000080,0x00000000,0x00000000,0x00000000,0x00000080,0x00000000,
    0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,
    So in this case it will eat real memory. I was going to show the differences in size, but appears like this example currently does not build.

    Code:
    Linking everything together
    ...
    C:\Users\kurte\AppData\Local\Temp\arduino_build_320855\sketch\ADAT_DrumSamplePlayer.ino.cpp.o: In function `AudioOutputADAT::AudioOutputADAT()':
    C:\arduino-1.8.13\hardware\teensy\avr\libraries\Audio/output_adat.h:34: undefined reference to `AudioOutputADAT::begin()'
    C:\Users\kurte\AppData\Local\Temp\arduino_build_320855\sketch\ADAT_DrumSamplePlayer.ino.cpp.o: In function `AudioStream::AudioStream(unsigned char, audio_block_struct**)':
    C:\arduino-1.8.13\hardware\teensy\avr\cores\teensy4/AudioStream.h:133: undefined reference to `vtable for AudioOutputADAT'
    collect2.exe: error: ld returned 1 exit status
    Multiple libraries were found for "SPI.h"
     Used: C:\Users\kurte\Documents\Arduino\libraries\SPI
     Not used: C:\arduino-1.8.13\hardware\teensy\avr\libraries\SPI
    Multiple libraries were found for "SD.h"
     Used: C:\arduino-1.8.13\hardware\teensy\avr\libraries\SD
     Not used: C:\arduino-1.8.13\libraries\SD
    Multiple libraries were found for "Wire.h"
     Used: C:\Users\kurte\Documents\Arduino\libraries\Wire
     Not used: C:\arduino-1.8.13\hardware\teensy\avr\libraries\Wire
    Using library Audio at version 1.3 in folder: C:\arduino-1.8.13\hardware\teensy\avr\libraries\Audio 
    Using library SPI at version 1.0 in folder: C:\Users\kurte\Documents\Arduino\libraries\SPI 
    Using library SD at version 1.2.2 in folder: C:\arduino-1.8.13\hardware\teensy\avr\libraries\SD 
    Using library SerialFlash at version 0.5 in folder: C:\arduino-1.8.13\hardware\teensy\avr\libraries\SerialFlash 
    Using library Wire at version 1.0 in folder: C:\Users\kurte\Documents\Arduino\libraries\Wire 
    Error compiling for board Teensy 4.1.
    Maybe some one who uses this should take a look.

  10. #10
    Junior Member
    Join Date
    Sep 2019
    Location
    Sevilla, Spain
    Posts
    19
    Quote Originally Posted by KurtE View Post
    Question can you not simply have the samples stay in flash memory?

    If I look at the example sketch SamplePlayer, I see that it's samples are stored in flash memory...
    That is if I look at the cpp files. I see stuff like:
    Code:
    #include "AudioSampleKick.h"
    #include <Arduino.h>
    // Converted from kick.wav, using 22050 Hz, 16 bit PCM encoding
    PROGMEM
    const unsigned int AudioSampleKick[2561] = {
    0x820013EC,0xFFDC0027,0xFF710095,0x038DFF4C,0xFBA10105,0x0037FB6E,0x09D2011A,0x007504CA,
    0x024BF6BF,0xF77B0AFF,0xFB72F723,0xEF3DEBAD,0x0F7009D6,0x09DD1736,0xF26EFA3E,0x0D7002FB,
    0xFF4401F1,0x06B20406,0xF83306AF,0xFC9DF1A9,0xFCC601C7,0x0423F387,0x11F011ED,0xF727066F,
    ...
    So the main data should be left in the FLASH and not take up your main memory...

    You might take a look at your files and see if they are marked as PROGMEM ?
    thanks dude, you pointed the problem, it needs also this:
    Code:
    #include <Arduino.h>
    now working fine, now I need to find how to make an array for all those samples, my first attempt with an array of pointers didn't work btw
    thanks again guys for the help, much appreciated ;-)

Posting Permissions

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