Git Product home page Git Product logo

teensy-sample-flashloader's Introduction

teensy sample flashloader

lib-teensy41 example-loadsample

load .RAW audio samples from micro-SD card to external psram or flash memory on teensy 4.1

NB: This library currently only works with .RAW audio files - .WAV files are not supported.

  • Use Audacity to convert your audio samples to .RAW format (16 bits/sample, 44100 samples/sec, signed integer samples).
  • playWav method does NOT work. only playRaw currently works.
  • You can play a .WAV file using playRaw(...) but the 44 byte wav header will produce a tiny fragment of noise at the begging of the sample...
#include <Arduino.h>
#include <SD.h>
#include <Audio.h>
#include <TeensyVariablePlayback.h>
#include "flashloader.h"

// GUItool: begin automatically generated code
AudioPlayArrayResmp      rraw_a1;        //xy=321,513
AudioOutputI2S           i2s1;           //xy=675,518
AudioConnection          patchCord1(rraw_a1, 0, i2s1, 0);
AudioConnection          patchCord2(rraw_a1, 0, i2s1, 1);
AudioControlSGTL5000     sgtl5000_1;     //xy=521,588
// GUItool: end automatically generated code

unsigned long lastSamplePlayed = 0;
newdigate::audiosample *sample;

void setup() {
    Serial.begin(9600);
    AudioMemory(20);
    sgtl5000_1.enable();
    sgtl5000_1.volume(0.5f, 0.5f);
    
    rraw_a1.enableInterpolation(true);

    Serial.print("Initializing SD card...");
    while (!SD.begin(BUILTIN_SDCARD)) {
      Serial.println("initialization failed!");
      delay(1000);
    }
    Serial.println("initialization done.");

    newdigate::flashloader loader;
    sample = loader.loadSample("KICK.RAW");
}

const int numChannels = 1; // 1 for mono, 2 for stereo...

void loop() {
    unsigned currentMillis = millis();
    if (currentMillis > lastSamplePlayed + 500) {
        if (!rraw_a1.isPlaying()) {
            rraw_a1.playRaw(sample->sampledata, sample->samplesize/2, numChannels);
            lastSamplePlayed = currentMillis;

            Serial.print("Memory: ");
            Serial.print(AudioMemoryUsage());
            Serial.print(",");
            Serial.print(AudioMemoryUsageMax());
            Serial.println();
        }
    }
    delay(10);
}

teensy-sample-flashloader's People

Contributors

newdigate avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

teensy-sample-flashloader's Issues

Support for loading from QPI NAND Flash chips?

Hi, I was wondering if it would be straight forward to implement an option to load samples from the SD card into QPI NAND flash chips, like the 256MB NAND chip (W25N02) that the Teensy supports.

I was interested in having more than 8MB of PSRAM to load samples from, since I'm working on a project where that limit will likely be met pretty easily with multiple samples being played at one time.

Thanks so much in advance for any consideration.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.