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

Thread: <Audio.h> in external .hpp/.cpp file compile errors

  1. #1
    Member Van's Avatar
    Join Date
    Mar 2018
    Location
    Dresden, Germany
    Posts
    35

    <Audio.h> in external .hpp/.cpp file compile errors

    Hi guys,

    similar to this thread:
    https://forum.pjrc.com/threads/50688-lt-MIDI-h-gt-in-external-hpp-cpp-file-and-callbacks-question

    what is the workaround?

    here is my .ino:

    Code:
    #include "AudioEngine.hpp"
    
    
    AudioEngine audioEngine;
    
    void setup() {
      // put your setup code here, to run once:
    
    }
    
    void loop() {
      // put your main code here, to run repeatedly:
      audioEngine.playBD();
      delay(1000);
    }
    here is the .hpp



    Code:
    #ifndef AudioEngine_hpp
    #define AudioEngine_hpp
    
    #include <stdio.h>
    #include "Arduino.h"
    #include "Audio.h"
    #include <synth_simple_drum.h>
    
    
    AudioSynthSimpleDrum bd1;
    AudioMixer4          mixerLow;
    AudioOutputAnalog    dac1;
    
    AudioConnection      patchLow1(bd1, 0, mixerLow, 0);
    AudioConnection      patchGlobal(mixerLow, 0, dac1, 0);
    
    class AudioEngine
    {
      public:
        AudioEngine();
        void playBD();
        
    };
    
    #endif /* AudioEngine_hpp */
    and here is the .cpp


    Code:
    #include "AudioEngine.hpp"
    
    AudioEngine::AudioEngine()
    {
        bd1.frequency(60);
        bd1.length(100);
        bd1.secondMix(0.5);
        bd1.pitchMod(1.0);
        mixerLow.gain(0, 0.5);
        
        AudioMemory(20);
        dac1.analogReference(INTERNAL);   // normal volume
    }
    
    void AudioEngine::playBD()
    {
        bd1.noteOn();
    }
    and here the error:

    Code:
    /var/folders/5j/8x9_vr3d0bzc2lfwylqv167h0000gn/T/arduino_build_582612/sketch/testAudioEngine.ino.cpp.o:(.bss.patchGlobal+0x0): multiple definition of `patchGlobal'
    /var/folders/5j/8x9_vr3d0bzc2lfwylqv167h0000gn/T/arduino_build_582612/sketch/AudioEngine.cpp.o:(.bss.patchGlobal+0x0): first defined here
    /Applications/Arduino.app/Contents/Java/hardware/tools/arm/bin/../lib/gcc/arm-none-eabi/5.4.1/../../../../arm-none-eabi/bin/ld: Disabling relaxation: it will not work with multiple definitions
    /var/folders/5j/8x9_vr3d0bzc2lfwylqv167h0000gn/T/arduino_build_582612/sketch/testAudioEngine.ino.cpp.o: In function `$d':
    /Users/koko/Arduino/projects/Schillinger/tests/testAudioEngine/testAudioEngine.ino:15: multiple definition of `patchLow1'
    /var/folders/5j/8x9_vr3d0bzc2lfwylqv167h0000gn/T/arduino_build_582612/sketch/AudioEngine.cpp.o:/var/folders/5j/8x9_vr3d0bzc2lfwylqv167h0000gn/T/arduino_build_582612/sketch/AudioEngine.cpp:19: first defined here
    /var/folders/5j/8x9_vr3d0bzc2lfwylqv167h0000gn/T/arduino_build_582612/sketch/testAudioEngine.ino.cpp.o: In function `$d':
    /Users/koko/Arduino/projects/Schillinger/tests/testAudioEngine/testAudioEngine.ino:15: multiple definition of `dac1'
    /var/folders/5j/8x9_vr3d0bzc2lfwylqv167h0000gn/T/arduino_build_582612/sketch/AudioEngine.cpp.o:/var/folders/5j/8x9_vr3d0bzc2lfwylqv167h0000gn/T/arduino_build_582612/sketch/AudioEngine.cpp:19: first defined here
    /var/folders/5j/8x9_vr3d0bzc2lfwylqv167h0000gn/T/arduino_build_582612/sketch/testAudioEngine.ino.cpp.o: In function `$d':
    /Users/koko/Arduino/projects/Schillinger/tests/testAudioEngine/testAudioEngine.ino:15: multiple definition of `mixerLow'
    /var/folders/5j/8x9_vr3d0bzc2lfwylqv167h0000gn/T/arduino_build_582612/sketch/AudioEngine.cpp.o:/var/folders/5j/8x9_vr3d0bzc2lfwylqv167h0000gn/T/arduino_build_582612/sketch/AudioEngine.cpp:19: first defined here
    /var/folders/5j/8x9_vr3d0bzc2lfwylqv167h0000gn/T/arduino_build_582612/sketch/testAudioEngine.ino.cpp.o: In function `$d':
    /Users/koko/Arduino/projects/Schillinger/tests/testAudioEngine/testAudioEngine.ino:15: multiple definition of `bd1'
    /var/folders/5j/8x9_vr3d0bzc2lfwylqv167h0000gn/T/arduino_build_582612/sketch/AudioEngine.cpp.o:/var/folders/5j/8x9_vr3d0bzc2lfwylqv167h0000gn/T/arduino_build_582612/sketch/AudioEngine.cpp:19: first defined here
    collect2: error: ld returned 1 exit status


    thanks in advance and cheers! van


    ps: my main.ino file ist getting BIG..
    Last edited by Van; 04-06-2018 at 02:41 PM.

Posting Permissions

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