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

Thread: Naming Convention for .RAW Files?

  1. #1
    Junior Member
    Join Date
    Feb 2019

    Naming Convention for .RAW Files?

    Hi there,

    I'm running into a weird problem with a project I'm working on where I'm wanting to record and playback audio using a Teensy 3.6. I've copied the code I'm working with below, but the important parts should be the #define SAMPLE_NAME line and the record() and playSample() functions at the bottom.

    Anyways, the gist of the code is that I want the Teensy (1) to record from the AudioInputAnalog object when a button is pressed and the audio level passes a certain threshold and (2) to play back the recorded audio from the AudioOutputAnalogStereo object when a trigger signal appears.

    The problem I'm running into is that the sketch works as is, but if I define SAMPLE_NAME to be something else the Teensy crashes when I try to play back the recorded audio. So far, I've found that the sketch works when SAMPLE_NAME is defined as 'Sample.raw' and 'TstAudIO.raw', but not when it is defined as 'Beta.raw', 'BetaOne.raw', 'BetaOnee.raw', 'Test.raw', or 'Z.raw'.

    I'm guessing there are some sorts of naming conventions that .raw files need to follow in order for them to be played with an AudioPlaySdRaw object, and that 'Sample.raw' and 'TstAudIO.raw' follow them while the others don't. However, the only convention I'm aware of is that the name needs to be 8 or fewer characters and the extension needs to be 3 or fewer. Are there other conventions that I'm not aware of?

    Or, is there something substantive about how SAMPLE_NAME is working in this sketch that I'm missing? The only places 'SAMPLE_NAME' shows up are in the #define line at the top and the record() and playSample() functions at the bottom, and I'm not seeing any issues in those places that are jumping out to me.

    Anyways, any thoughts you could spare would be a huge help. Thanks!

    #include <Audio.h>
    #include <Wire.h>
    #include <SPI.h>
    #include <SD.h>
    #include <Bounce.h>
    #include <SerialFlash.h>
    #define REC_PIN_0             7
    #define INPUT_PIN             A1
    #define TRIG_PIN_0            0
    #define SAMPLE_NAME           "Sample.raw"
    #define SDCARD_CS_PIN         BUILTIN_SDCARD
    #define REC_THRESHOLD         .05
    AudioInputAnalog              input(INPUT_PIN);
    AudioAnalyzePeak              level;
    AudioRecordQueue              recQueue;
    AudioPlaySdRaw                samplePlayer;
    AudioOutputAnalogStereo       outputs;
    AudioConnection               inToRec(input, 0, recQueue, 0);
    AudioConnection               inToLevel(input, 0, level, 0);
    AudioConnection               sampToOuts(samplePlayer, 0, outputs, 0);
    Bounce recButton = Bounce(REC_PIN_0, 10);
    Bounce trigIn = Bounce(TRIG_PIN_0, 10);
    void setup() {
      //Audio Setup
      //Serial Setup
      while (!Serial) {}
      //Trig/Rec Setup
      pinMode(REC_PIN_0, INPUT_PULLUP);
      pinMode(TRIG_PIN_0, INPUT_PULLDOWN);
      //SD Setup
      while (!(SD.begin(SDCARD_CS_PIN))) {
        Serial.println("Unable to access the SD card");
      Serial.println("setup() complete"); 
    void loop() {
    void updateRecButtons() {
      if (recButton.fallingEdge()) {
        Serial.println("Record Button Pressed");
    void updateTrigIns() {
      if (trigIn.risingEdge()) {
        Serial.println("Sample Triggered");
    void record() {
      Serial.println("Entering record()");
      //Setup file to record into
      if(SD.exists(SAMPLE_NAME)) {
        Serial.print("Deleting ");
      File file =, FILE_WRITE);
      if(!file) {
        Serial.println("Error: File Not Found");
        while (digitalRead(REC_PIN_0) == LOW) {}
      //Wait until Signal is Present
      if (level.available());                    //flushes any old values in level
      while(1) {
        if (recButton.risingEdge()) {
          Serial.println("Button Released before Recording Started");
        if (level.available() && ( > REC_THRESHOLD)) break;
      //Start Recording
      Serial.println("Starting to Record");
      while (!recButton.risingEdge()) {
        if (recQueue.available() >= 2) {
          byte buffer[512];
          memcpy(buffer, recQueue.readBuffer(), 256);
          memcpy(buffer+256, recQueue.readBuffer(), 256);
          file.write(buffer, 512);
      //Finish Recording
      Serial.println("Record Button Released");
      while (recQueue.available() >= 2) {
        file.write((byte*)recQueue.readBuffer(), 256);
      Serial.println("Exiting record()");
    void playSample() {
      if (!SD.exists(SAMPLE_NAME)) {
        Serial.print("File ");
        Serial.println(" not found");
      } else {
        Serial.println("Playing sample");

  2. #2
    Junior Member
    Join Date
    Feb 2019
    Bump. Am I right to be thinking it has to do with naming conventions, or is it likely to be something else?

  3. #3
    Junior Member
    Join Date
    Feb 2019
    After some more poking around, I found out that using touch from my computer's command line to create files on the sd card with names that previously didn't work led to some of them working (although some of them still did not work). Any thoughts on what touch might be doing that would cause this to happen?

    Also, unfortunately I tried wiping my sd card and reformatting it, and now I can't get any files to work. Any thoughts on why this might be?

  4. #4
    Senior Member
    Join Date
    Nov 2012
    when SAMPLE_NAME is defined as 'Sample.raw' and 'TstAudIO.raw', but not when it is defined as 'Beta.raw', .....
    There should not be a problem with any of the names you've mentioned, but you've used single quotes here. Could it be something as simple as using single quotes instead of double quotes in the code?


  5. #5
    Junior Member
    Join Date
    Feb 2019
    Thanks for the reply. I've been using double quotes in the code. Single quotes is just a habit I've picked up while writing. The fact that some of the names worked ok using touch makes me think there's something up with how my SD card is setup or with how the Teensy/my computer creates the .raw file. But I'm not sure what those things could be...

  6. #6
    Junior Member
    Join Date
    Feb 2019
    I'm pretty sure the problem was a bad install of the Arduino IDE. Now that I've reinstalled things seem to be working correctly.

Posting Permissions

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