PlatformIO Community

Error when using sd library and audio library

I get this error when using sdfat library and teensy audio library:

Error:

In file included from C:\Users\E\.platformio\packages\framework-arduinoteensy\libraries\Audio/Audio.h:127:0,
                 from include/AudioSystem.h:5,
                 from src\AudioSystem.cpp:1:
C:\Users\E\.platformio\packages\framework-arduinoteensy\libraries\Audio/play_sd_raw.h:46:2: error: 'File' does not name a type
  File rawfile;
  ^
In file included from C:\Users\E\.platformio\packages\framework-arduinoteensy\libraries\Audio/Audio.h:128:0,
                 from include/AudioSystem.h:5,
                 from src\AudioSystem.cpp:1:
C:\Users\E\.platformio\packages\framework-arduinoteensy\libraries\Audio/play_sd_wav.h:49:2: error: 'File' does not name a type
  File wavfile;
  ^
Compiling .pio\build\teensy41\lib179\SerialFlash\SerialFlashDirectory.cpp.o
In file included from C:\Users\E\.platformio\packages\framework-arduinoteensy\libraries\Audio/Audio.h:127:0,
                 from include/AudioSystem.h:5,
                 from src\main.cpp:10:
C:\Users\E\.platformio\packages\framework-arduinoteensy\libraries\Audio/play_sd_raw.h:46:2: error: 'File' does not name a type
  File rawfile;
  ^
In file included from C:\Users\E\.platformio\packages\framework-arduinoteensy\libraries\Audio/Audio.h:128:0,
                 from include/AudioSystem.h:5,
                 from src\main.cpp:10:
C:\Users\E\.platformio\packages\framework-arduinoteensy\libraries\Audio/play_sd_wav.h:49:2: error: 'File' does not name a type
  File wavfile;
  ^
*** [.pio\build\teensy41\src\AudioSystem.cpp.o] Error 1
*** [.pio\build\teensy41\src\main.cpp.o] Error 1

but it works when i only use the sdfat library or audio library standalone.

main.cpp

#include "Arduino.h"
#include "SPI.h"

#include "Display.h"
Display display;
#include "Encoders.h"
Encoders encoders;
#include "Sd.h"
Sd sd;
#include "AudioSystem.h"
AudioSystem audio;

void setup()
{
    audio.begin();
    display.begin();
    sd.begin();
    encoders.begin();
}

void loop()
{

    encoders.value();
    encoders.button();
}

Audio.cpp

#include <AudioSystem.h>

// GUItool: begin automatically generated code
AudioSynthWaveform waveform1;             // xy=427,319
AudioSynthWaveform waveform2;             // xy=429,364
AudioSynthWaveformModulated waveformMod1; // xy=684,318
AudioOutputI2S i2s1;                      // xy=1000,323
AudioConnection patchCord1(waveform1, 0, waveformMod1, 0);
AudioConnection patchCord2(waveform2, 0, waveformMod1, 1);
AudioConnection patchCord3(waveformMod1, 0, i2s1, 0);
AudioConnection patchCord4(waveformMod1, 0, i2s1, 1);
AudioControlSGTL5000 sgtl5000_1;

// GUItool: end automatically generated code

void myControlChange(byte channel, byte control, byte value);

void AudioSystem::begin()
{
    AudioMemory(20);
    usbMIDI.setHandleControlChange(myControlChange);
    sgtl5000_1.enable();
    sgtl5000_1.volume(0.32);
}

void myControlChange(byte channel, byte control, byte value)
{
    switch (control)
    {
    case 100:
        waveform1.frequency(((float)value / 127));
        break;

    case 101:
        waveform2.frequency(((float)value / 127));
        break;
    }
}

AudioSystem.h

#ifndef AUDIO_H
#define AUDIO_H

#include <Arduino.h>
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>
#include <MIDIUSB.h>
#include <MIDI.h>


extern void myControlChange(byte channel, byte control, byte value);

class AudioSystem
{
public:
    void begin();
};

#endif

Sd.cpp

#include "Sd.h"

// SD_FAT_TYPE = 0 for SdFat/File as defined in SdFatConfig.h,
// 1 for FAT16/FAT32, 2 for exFAT, 3 for FAT16/FAT32 and exFAT.
#define SD_FAT_TYPE 2

/*
Change the value of SD_CS_PIN if you are using SPI and
your hardware does not use the default value, SS.
Common values are:
Arduino Ethernet shield: pin 4
Sparkfun SD shield: pin 8
Adafruit SD shields and modules: pin 10
*/

// SDCARD_SS_PIN is defined for the built-in SD on some boards.
#ifndef SDCARD_SS_PIN
const uint8_t SD_CS_PIN = SS;
#else  // SDCARD_SS_PIN
// Assume built-in SD is used.
const uint8_t SD_CS_PIN = SDCARD_SS_PIN;
#endif // SDCARD_SS_PIN

// Try max SPI clock for an SD. Reduce SPI_CLOCK if errors occur.
#define SPI_CLOCK SD_SCK_MHZ(200)

// Try to select the best SD card configuration.
#if HAS_SDIO_CLASS
#define SD_CONFIG SdioConfig(FIFO_SDIO)
#elif ENABLE_DEDICATED_SPI
#define SD_CONFIG SdSpiConfig(SD_CS_PIN, DEDICATED_SPI, SPI_CLOCK)
#else // HAS_SDIO_CLASS
#define SD_CONFIG SdSpiConfig(SD_CS_PIN, SHARED_SPI, SPI_CLOCK)
#endif // HAS_SDIO_CLASS

#if SD_FAT_TYPE == 2
SdExFat sd;
ExFile file;
#else // SD_FAT_TYPE
#error Invalid SD_FAT_TYPE
#endif // SD_FAT_TYPE

// Serial print stream
ArduinoOutStream cout(Serial);

// store error strings in flash to save RAM
#define error(s) sd.errorHalt(&Serial, F(s))


void Sd::begin()
{
    if (!sd.begin(SD_CONFIG))
    {
        sd.initErrorHalt(&Serial);
        return;
    }
    Serial.println("sd succes");
    
}

AudioSystem.h

#ifndef AUDIO_H
#define AUDIO_H

#include <Arduino.h>
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>
#include <MIDIUSB.h>
#include <MIDI.h>


extern void myControlChange(byte channel, byte control, byte value);

class AudioSystem
{
public:
    void begin();
};

#endif

Sd.h

#ifndef Sd_H
#define Sd_H

#include "Arduino.h"
#include "SPI.h"
#include "SdFat.h"
#include "sdios.h"

class Sd
{
public:
  void begin();
};

#endif

Dangerous to call a file close to a library file.

What does the verbose library dependency graph look like? Use the project task Advanced → Verbose Build to output it and post it here.

I highly suspect its picking up some wrong library, or is including one of your files instead of the right libraries because of your self-created Sd code files.

I changed the name of Sd.h and now it works.
Thanks!