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

Thread: RAW headerless file playing at a super slow BPM

  1. #1
    Junior Member
    Join Date
    Mar 2020
    Posts
    14

    RAW headerless file playing at a super slow BPM

    Hello!

    So I'm trying to get it to where I can simply put in an SD card full of audio samples roughly around 4 beats, or 1 full measure. Before getting into all the craziness about how to scroll through all the tracks, or putting 1 sample of 1 measure playing alongside a sample that is 2 measures, right now i'm just trying to play one sample in a seamless loop. Having it play twice through 2 mixers and having the second playback of the same track a millisecond before the other one finishes isn't precise enough because various bpm's would require different lengths before the finish in order to make it a seamless loop playing 'in time' . Therefore I decided to try it as a RAW file and hope it'll just loop without having to parse the header first. That totally worked by the way! The problem? It is playing the raw file in a much slower BPM than it originally played. Any thoughts?

    Code:
    #include <Audio.h>
    #include <Wire.h>
    #include <SPI.h>
    #include <SD.h>
    #include <SerialFlash.h>
    
    AudioPlaySdRaw           playSdRaw1;     //xy=267,209
    AudioOutputI2S           i2s1;           //xy=605,196
    AudioConnection          patchCord1(playSdRaw1, 0, i2s1, 0);
    AudioConnection          patchCord2(playSdRaw1, 0, i2s1, 1);
    AudioControlSGTL5000     sgtl5000_1;     //xy=457,320
    
    #define SDCARD_CS_PIN    10
    #define SDCARD_MOSI_PIN  11
    #define SDCARD_SCK_PIN   13
    
    void setup() {
      Serial.begin(9600);
      AudioMemory(8);
      sgtl5000_1.enable();
      sgtl5000_1.volume(0.5);
      SPI.setMOSI(SDCARD_MOSI_PIN);
      SPI.setSCK(SDCARD_SCK_PIN);
      if (!(SD.begin(SDCARD_CS_PIN))) {
        while (1) {
          Serial.println("Unable to access the SD card");
          delay(500);
        }
      }
      delay(1000);
    }
    
    void loop() {
      if (playSdRaw1.isPlaying() == false) {
        Serial.println("Start playing");
        playSdRaw1.play("DRUMRAW1.RAW");
        delay(10); // wait for library to parse WAV info
      }
    
    }
    Last edited by Frank B; 03-25-2020 at 08:29 PM. Reason: added code tags

  2. #2
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    6,525
    Might be a problem with your raw file.
    It must be 44100Hz, 16 Bit, two channel (stereo).

  3. #3
    Junior Member
    Join Date
    Mar 2020
    Posts
    14
    Quote Originally Posted by Frank B View Post
    Might be a problem with your raw file.
    It must be 44100Hz, 16 Bit, two channel (stereo).
    Well Frank, I was (with full on smug self satisfaction btw) about to comment on here rather pompously that of course I had exported the file under these specs. In fact, just to ensure no one might second guess me I decided to export another one of the samples just to make sure in the bright lights that I was indeed doing it right. Then for some reason I tried that file and.......it totally worked!!!!!

    I'm not going to even question it, I swear the first file I did was 44100Hz, 16 big (signed PCM) and 2 channel stereo as well as little endian, but for some reason that first file plays at like half time. the second file I did again worked perfectly though and sure enough, looping is entirely seamless and it will be seamless surely no matter how long the file is too so there won't be need for any weird math algorithms to determine how much before the end of the first clip I should be starting the second one. I'm this much closer to my Commuter Groove Box. Thank you Frank B you totally saved the freaking day!

Posting Permissions

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