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

Thread: AudioConnection costructors

  1. #1
    Member darioconcilio's Avatar
    Join Date
    Feb 2016
    Location
    Varese, Italy
    Posts
    52

    AudioConnection costructors

    Hi to all,
    Has AudioConnection class a costructors with 0 parameter?
    I can't find header file of this class, I'm finding in ..\Arduino\hardware\teensy\avr\libraries\Audio
    Is it correct my search or not?

  2. #2

  3. #3
    Member darioconcilio's Avatar
    Join Date
    Feb 2016
    Location
    Varese, Italy
    Posts
    52
    Thank's Paul, but It could add a costructors without parameter?
    Sothat I could create an AudioConnection in my header file, and then I'll instance varaible in cpp file?

  4. #4
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    19,929
    I do not understand what you're asking. Maybe if you explain *why* or illustrate with some code, it might make sense?

    However, if you look at how the AudioConnection connection code works, a constructors without a way to define the connection would be silly.

  5. #5
    Senior Member
    Join Date
    Nov 2015
    Location
    Wales
    Posts
    579
    Do you mean a declaration then a later definition:
    Code:
    AudioConnection *audioCon = NULL;
    In your header

    Then in setup():
    Code:
    extern AudioConnection *audioCon;
    audioCon = new AudioConnection(arg1, arg2...)
    Last edited by Xenoamor; 02-12-2016 at 02:21 PM.

  6. #6
    Member darioconcilio's Avatar
    Join Date
    Feb 2016
    Location
    Varese, Italy
    Posts
    52
    Great! You are wonderful!
    Thank you.

  7. #7
    Senior Member
    Join Date
    Dec 2014
    Posts
    253
    Sothat I could create an AudioConnection in my header file, and then I'll instance varaible in cpp file?
    audioCon = new AudioConnection(arg1, arg2...)
    Using "new" in embedded systems is generally a bad idea, because any "churn" on the heap will be hard to plan for and test 100%.

    A better method is to separate the declaration, and the definition. In C++, this is how almost everything is done. In your header, you do something like:

    Code:
    /* myfile.h */
    
    class AudioConnection;
    extern AudioConnection theAudio;
    Then in the source file, you do:

    Code:
    /* myfile.cpp */
    
    #include "myfile.h"
    #include <AudioConnection.h>
    
    AudioConnection theAudio(arg1, arg2, ...);
    Now, any file that wants to use theAudio can #include "myfile.h" can use "theAudio" global variable.

    Note that the method described by Xenoamor will NOT WORK if you #include the header from more than one cpp file, because it will fail with a duplicate defined symbol linker error.

  8. #8
    Senior Member
    Join Date
    Nov 2015
    Location
    Wales
    Posts
    579
    Ah of course, you want extern in the header as the declaration.
    Cheers Jwatte! I'm still really rather green when it comes to c++

Posting Permissions

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