{"action":"created","issue":{"url":"https://api.github.com/repos/TonicAudio/Tonic/issues/253","labels_url":"https://api.github.com/repos/TonicAudio/Tonic/issues/253/labels{/name}","comments_url":"https://api.github.com/repos/TonicAudio/Tonic/issues/253/comments","events_url":"https://api.github.com/repos/TonicAudio/Tonic/issues/253/events","html_url":"https://github.com/TonicAudio/Tonic/issues/253","id":55782133,"number":253,"title":"outsource DSP functions","user":{"login":"andik","id":147864,"avatar_url":"https://avatars.githubusercontent.com/u/147864?v=3","gravatar_id":"","url":"https://api.github.com/users/andik","html_url":"https://github.com/andik","followers_url":"https://api.github.com/users/andik/followers","following_url":"https://api.github.com/users/andik/following{/other_user}","gists_url":"https://api.github.com/users/andik/gists{/gist_id}","starred_url":"https://api.github.com/users/andik/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andik/subscriptions","organizations_url":"https://api.github.com/users/andik/orgs","repos_url":"https://api.github.com/users/andik/repos","events_url":"https://api.github.com/users/andik/events{/privacy}","received_events_url":"https://api.github.com/users/andik/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-01-28T16:48:51Z","updated_at":"2015-01-28T20:55:19Z","closed_at":null,"body":"Hey guys,\r\n\r\nas I look into the various (control-)generators of Tonic, I see this `#ifdef __APPLE__ ...  #else ... #endif` stuff all around, for example in the ADSR. I personally think this makes the code hard to comprehend and hard to maintain/adapt.\r\nI propose therefore a `TonicDSP.h` Headerfile which is used to abstract the DSP stuff away as much as possible...\r\n\r\nfor example (from ADSR)\r\n```c++\r\nnamespace Tonic { \r\n  namespace dsp {\r\n    inline void ramp(float start, float increment, float* buffer, int numSamples) {\r\n      #ifdef USE_APPLE_ACCELERATE\r\n        // starting point\r\n        start += increment;\r\n        // vector calculation\r\n        vDSP_vramp(&start, &increment, buffer, 1, numSamples);\r\n        // end point\r\n        start += increment*(numSamples-1);\r\n      #else\r\n        for (int i=0; i<numSamples; i++){\r\n          start += increment;\r\n          *buffer++ = start;\r\n        }\r\n      #endif\r\n    }\r\n  }\r\n}\r\n```\r\nanother option would be macros:\r\n\r\n```c++\r\n#ifdef USE_APPLE_ACCELERATE\r\n  #define TONIC_DSP_RAMP(start, increment, buffer, numSamples) \\\r\n    vDSP_vramp(&start, &increment, buffer, 1, numSamples);\r\n#else\r\n  #define TONIC_DSP_RAMP(start, increment, buffer, numSamples) \\\r\n    for (int i=0; i<numSamples; i++){                          \\\r\n      start += increment;                                      \\\r\n      *buffer++ = start;                                       \\\r\n    }\r\n#endif\r\n```\r\nI prefer the first.\r\n\r\none could create that header, mark it as DSP Port Header and add the DSP Functions whenever one finds one. This way nearly no immediate efford is required. And it would also help to port Tonic to new platforms..."},"comment":{"url":"https://api.github.com/repos/TonicAudio/Tonic/issues/comments/71913896","html_url":"https://github.com/TonicAudio/Tonic/issues/253#issuecomment-71913896","issue_url":"https://api.github.com/repos/TonicAudio/Tonic/issues/253","id":71913896,"user":{"login":"ndonald2","id":1433497,"avatar_url":"https://avatars.githubusercontent.com/u/1433497?v=3","gravatar_id":"","url":"https://api.github.com/users/ndonald2","html_url":"https://github.com/ndonald2","followers_url":"https://api.github.com/users/ndonald2/followers","following_url":"https://api.github.com/users/ndonald2/following{/other_user}","gists_url":"https://api.github.com/users/ndonald2/gists{/gist_id}","starred_url":"https://api.github.com/users/ndonald2/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ndonald2/subscriptions","organizations_url":"https://api.github.com/users/ndonald2/orgs","repos_url":"https://api.github.com/users/ndonald2/repos","events_url":"https://api.github.com/users/ndonald2/events{/privacy}","received_events_url":"https://api.github.com/users/ndonald2/received_events","type":"User","site_admin":false},"created_at":"2015-01-28T20:55:19Z","updated_at":"2015-01-28T20:55:19Z","body":"Yes, this is a great idea. I had started down this road awhile back but never saw it through. Another good option might be to have multiple .cpp implementation files for the core DSP header that each use platform macros to compile the whole thing or nothing.\r\n\r\ni.e.\r\n\r\n```c++\r\n// TonicDSP_apple.cpp\r\n#ifdef USE_APPLE_ACCELERATE\r\n#include \"TonicDSP.h\"\r\n...\r\n// All the implementations for the DSP functions\r\n...\r\n#endif\r\n```\r\n\r\nand so on."}}