{"action":"opened","issue":{"url":"https://api.github.com/repos/BelaPlatform/Bela/issues/125","repository_url":"https://api.github.com/repos/BelaPlatform/Bela","labels_url":"https://api.github.com/repos/BelaPlatform/Bela/issues/125/labels{/name}","comments_url":"https://api.github.com/repos/BelaPlatform/Bela/issues/125/comments","events_url":"https://api.github.com/repos/BelaPlatform/Bela/issues/125/events","html_url":"https://github.com/BelaPlatform/Bela/issues/125","id":176434842,"number":125,"title":"analogWrite should write all of the successive frames unconditionally","user":{"login":"giuliomoro","id":4260604,"avatar_url":"https://avatars.githubusercontent.com/u/4260604?v=3","gravatar_id":"","url":"https://api.github.com/users/giuliomoro","html_url":"https://github.com/giuliomoro","followers_url":"https://api.github.com/users/giuliomoro/followers","following_url":"https://api.github.com/users/giuliomoro/following{/other_user}","gists_url":"https://api.github.com/users/giuliomoro/gists{/gist_id}","starred_url":"https://api.github.com/users/giuliomoro/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/giuliomoro/subscriptions","organizations_url":"https://api.github.com/users/giuliomoro/orgs","repos_url":"https://api.github.com/users/giuliomoro/repos","events_url":"https://api.github.com/users/giuliomoro/events{/privacy}","received_events_url":"https://api.github.com/users/giuliomoro/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/BelaPlatform/Bela/labels/core","name":"core","color":"5319e7"},{"url":"https://api.github.com/repos/BelaPlatform/Bela/labels/discussion","name":"discussion","color":"e99695"}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2016-09-12T17:28:23Z","updated_at":"2016-09-12T17:28:23Z","closed_at":null,"body":"It currently checks if BELA_FLAG_ANALOG_OUTPUTS_PERSIST is set before writing till the end of buffer, which means there is a branching every time you write:\r\n\r\n```\r\n// analogWrite()\r\n//\r\n// Sets a given analog output channel to a value for the current frame and, if persistent outputs are\r\n// enabled, for all subsequent frames\r\nstatic inline void analogWrite(BelaContext *context, int frame, int channel, float value) {\r\n    if(context->flags & BELA_FLAG_ANALOG_OUTPUTS_PERSIST) {\r\n        for(unsigned int f = frame; f < context->analogFrames; f++)\r\n            context->analogOut[frame * context->analogOutChannels + channel] = value;\r\n    }\r\n    else\r\n        context->analogOut[frame * context->analogOutChannels + channel] = value;\r\n}\r\n```\r\n\r\nnow, this is not necessarily very bad, as `analogWrite()` is not supposed to be called for every sample, but once or less every buffer. Yet, it may be confusing because `digitalWrite` does not behave the same (i.e.: writing to the end of the buffer is unconditional).\r\n\r\nIn the current implementation, when `BELA_FLAG_ANALOG_OUTPUTS_PERSIST` is not set, `analogWrite` basically decays to `analogWriteOnce`.\r\nI believe the rationale behind this was that if `BELA_FLAG_ANALOG_OUTPUTS_PERSIST` is not set, then outputs would not persist across buffers, therefore writing to the end of buffer would not make much sense, as the next buffer would not be init'ed to that same value.\r\n\r\nI advise we make this unconditional and users are advised against using `analogWrite()` altogether when `BELA_FLAG_ANALOG_OUTPUTS_PERSIST` is not set "}}
{"actor":{"display_login":"giuliomoro"}}