{"action":"created","comment":{"url":"https://api.github.com/repos/tux3/qTox/pulls/comments/64118857","id":64118857,"diff_hunk":"@@ -486,16 +498,30 @@ void Audio::doCapture()\n     }\n #endif\n \n-    for (size_t i = 0; i < AUDIO_FRAME_SAMPLE_COUNT * AUDIO_CHANNELS; ++i)\n-        buf[i] *= inGain;\n+    for (quint32 i = 0; i < AUDIO_FRAME_SAMPLE_COUNT * AUDIO_CHANNELS; ++i)\n+    {\n+        int16_t ampPCM = static_cast<int16_t>(qRound(buf[i] * gain));\n+        buf[i] = static_cast<int16_t>(ampPCM);\n+    }\n \n     emit frameAvailable(buf, AUDIO_FRAME_SAMPLE_COUNT, AUDIO_CHANNELS, AUDIO_SAMPLE_RATE);\n }\n \n /**\n+@internal\n+*/\n+void Audio::privateSetGain(qreal percentage)\n+{\n+    percentage = std::max(0.0, std::min(percentage, 1.0));\n+    gainPercentage = percentage;\n+\n+    gain = (percentage > 0.0) ? 10.0 * qAbs(log10(percentage * 100.0)) : 0.0;","path":"src/audio/audio.cpp","position":null,"original_position":105,"commit_id":"f60865d5dbba0caceee03d732f3fa77b9c689446","original_commit_id":"6f5d5c4d89e882a886aca9155f24ee79d761e3e7","user":{"login":"antis81","id":440517,"avatar_url":"https://avatars.githubusercontent.com/u/440517?v=3","gravatar_id":"","url":"https://api.github.com/users/antis81","html_url":"https://github.com/antis81","followers_url":"https://api.github.com/users/antis81/followers","following_url":"https://api.github.com/users/antis81/following{/other_user}","gists_url":"https://api.github.com/users/antis81/gists{/gist_id}","starred_url":"https://api.github.com/users/antis81/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/antis81/subscriptions","organizations_url":"https://api.github.com/users/antis81/orgs","repos_url":"https://api.github.com/users/antis81/repos","events_url":"https://api.github.com/users/antis81/events{/privacy}","received_events_url":"https://api.github.com/users/antis81/received_events","type":"User","site_admin":false},"body":"Yeah, I just remembered why I put it there. Actually removing the abs changes \"nothing\" here as values are always within range 1..100 (percentage * 100.0) -> I'll re-add the abs to be on the safe side. Btw. Percentage is already clipped above.\r\n\r\nStill 1% results in a 0 gain factor…??","created_at":"2016-05-20T23:03:22Z","updated_at":"2016-05-20T23:03:22Z","html_url":"https://github.com/tux3/qTox/pull/3311#discussion_r64118857","pull_request_url":"https://api.github.com/repos/tux3/qTox/pulls/3311","_links":{"self":{"href":"https://api.github.com/repos/tux3/qTox/pulls/comments/64118857"},"html":{"href":"https://github.com/tux3/qTox/pull/3311#discussion_r64118857"},"pull_request":{"href":"https://api.github.com/repos/tux3/qTox/pulls/3311"}}},"pull_request":{"url":"https://api.github.com/repos/tux3/qTox/pulls/3311","id":70253141,"html_url":"https://github.com/tux3/qTox/pull/3311","diff_url":"https://github.com/tux3/qTox/pull/3311.diff","patch_url":"https://github.com/tux3/qTox/pull/3311.patch","issue_url":"https://api.github.com/repos/tux3/qTox/issues/3311","number":3311,"state":"open","locked":false,"title":"feat(audio): add real gain control of the input device","user":{"login":"antis81","id":440517,"avatar_url":"https://avatars.githubusercontent.com/u/440517?v=3","gravatar_id":"","url":"https://api.github.com/users/antis81","html_url":"https://github.com/antis81","followers_url":"https://api.github.com/users/antis81/followers","following_url":"https://api.github.com/users/antis81/following{/other_user}","gists_url":"https://api.github.com/users/antis81/gists{/gist_id}","starred_url":"https://api.github.com/users/antis81/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/antis81/subscriptions","organizations_url":"https://api.github.com/users/antis81/orgs","repos_url":"https://api.github.com/users/antis81/repos","events_url":"https://api.github.com/users/antis81/events{/privacy}","received_events_url":"https://api.github.com/users/antis81/received_events","type":"User","site_admin":false},"body":"This PR might put a smile on some qTox user's faces as it brings into play some long awaited feature. We now have a usable and controllable **Audio Gain**, no really! :smile:\r\n\r\nThe gain is calculated with the common `10*log10()` algorithm, which is normally used for dB calculation of the electrical power level - and it gives pretty good results. Values can be set via qTox's public Audio API as percentage values (between 0 and 1).\r\n\r\nNote: This PR also brings back const-correctness to `Audio`; some minor cleanup with naming conventions also included.\r\n\r\n:warning: **Important:** As this has quite an impact on qTox's Audio experience --> Anyone who is able to compile qTox is invited to try this PR from a users view point!\r\n\r\nOn my system I'm using the following values with splendid results (checked vs. [Tox EchoBot](https://toxme.io/u/echobot)):\r\n\r\n* System settings:\r\n    * Master Volume: ~80%\r\n    * Gain: ~50% (~10dB)\r\n* qTox Audio Settings:\r\n    * Master volume: ~70-75%\r\n    * Gain: ~50-65%\r\n\r\nHave fun talking and probing this!","created_at":"2016-05-16T20:10:01Z","updated_at":"2016-05-20T23:03:22Z","closed_at":null,"merged_at":null,"merge_commit_sha":"2c62cb98dd1cbca076095d6846655c914b29c29b","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/tux3/qTox/pulls/3311/commits","review_comments_url":"https://api.github.com/repos/tux3/qTox/pulls/3311/comments","review_comment_url":"https://api.github.com/repos/tux3/qTox/pulls/comments{/number}","comments_url":"https://api.github.com/repos/tux3/qTox/issues/3311/comments","statuses_url":"https://api.github.com/repos/tux3/qTox/statuses/f60865d5dbba0caceee03d732f3fa77b9c689446","head":{"label":"antis81:audio/gain","ref":"audio/gain","sha":"f60865d5dbba0caceee03d732f3fa77b9c689446","user":{"login":"antis81","id":440517,"avatar_url":"https://avatars.githubusercontent.com/u/440517?v=3","gravatar_id":"","url":"https://api.github.com/users/antis81","html_url":"https://github.com/antis81","followers_url":"https://api.github.com/users/antis81/followers","following_url":"https://api.github.com/users/antis81/following{/other_user}","gists_url":"https://api.github.com/users/antis81/gists{/gist_id}","starred_url":"https://api.github.com/users/antis81/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/antis81/subscriptions","organizations_url":"https://api.github.com/users/antis81/orgs","repos_url":"https://api.github.com/users/antis81/repos","events_url":"https://api.github.com/users/antis81/events{/privacy}","received_events_url":"https://api.github.com/users/antis81/received_events","type":"User","site_admin":false},"repo":{"id":40208997,"name":"qTox","full_name":"antis81/qTox","owner":{"login":"antis81","id":440517,"avatar_url":"https://avatars.githubusercontent.com/u/440517?v=3","gravatar_id":"","url":"https://api.github.com/users/antis81","html_url":"https://github.com/antis81","followers_url":"https://api.github.com/users/antis81/followers","following_url":"https://api.github.com/users/antis81/following{/other_user}","gists_url":"https://api.github.com/users/antis81/gists{/gist_id}","starred_url":"https://api.github.com/users/antis81/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/antis81/subscriptions","organizations_url":"https://api.github.com/users/antis81/orgs","repos_url":"https://api.github.com/users/antis81/repos","events_url":"https://api.github.com/users/antis81/events{/privacy}","received_events_url":"https://api.github.com/users/antis81/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/antis81/qTox","description":"Powerful Tox client that follows the Tox design guidelines.","fork":true,"url":"https://api.github.com/repos/antis81/qTox","forks_url":"https://api.github.com/repos/antis81/qTox/forks","keys_url":"https://api.github.com/repos/antis81/qTox/keys{/key_id}","collaborators_url":"https://api.github.com/repos/antis81/qTox/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/antis81/qTox/teams","hooks_url":"https://api.github.com/repos/antis81/qTox/hooks","issue_events_url":"https://api.github.com/repos/antis81/qTox/issues/events{/number}","events_url":"https://api.github.com/repos/antis81/qTox/events","assignees_url":"https://api.github.com/repos/antis81/qTox/assignees{/user}","branches_url":"https://api.github.com/repos/antis81/qTox/branches{/branch}","tags_url":"https://api.github.com/repos/antis81/qTox/tags","blobs_url":"https://api.github.com/repos/antis81/qTox/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/antis81/qTox/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/antis81/qTox/git/refs{/sha}","trees_url":"https://api.github.com/repos/antis81/qTox/git/trees{/sha}","statuses_url":"https://api.github.com/repos/antis81/qTox/statuses/{sha}","languages_url":"https://api.github.com/repos/antis81/qTox/languages","stargazers_url":"https://api.github.com/repos/antis81/qTox/stargazers","contributors_url":"https://api.github.com/repos/antis81/qTox/contributors","subscribers_url":"https://api.github.com/repos/antis81/qTox/subscribers","subscription_url":"https://api.github.com/repos/antis81/qTox/subscription","commits_url":"https://api.github.com/repos/antis81/qTox/commits{/sha}","git_commits_url":"https://api.github.com/repos/antis81/qTox/git/commits{/sha}","comments_url":"https://api.github.com/repos/antis81/qTox/comments{/number}","issue_comment_url":"https://api.github.com/repos/antis81/qTox/issues/comments{/number}","contents_url":"https://api.github.com/repos/antis81/qTox/contents/{+path}","compare_url":"https://api.github.com/repos/antis81/qTox/compare/{base}...{head}","merges_url":"https://api.github.com/repos/antis81/qTox/merges","archive_url":"https://api.github.com/repos/antis81/qTox/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/antis81/qTox/downloads","issues_url":"https://api.github.com/repos/antis81/qTox/issues{/number}","pulls_url":"https://api.github.com/repos/antis81/qTox/pulls{/number}","milestones_url":"https://api.github.com/repos/antis81/qTox/milestones{/number}","notifications_url":"https://api.github.com/repos/antis81/qTox/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/antis81/qTox/labels{/name}","releases_url":"https://api.github.com/repos/antis81/qTox/releases{/id}","deployments_url":"https://api.github.com/repos/antis81/qTox/deployments","created_at":"2015-08-04T21:03:49Z","updated_at":"2015-09-26T06:45:21Z","pushed_at":"2016-05-20T22:29:10Z","git_url":"git://github.com/antis81/qTox.git","ssh_url":"git@github.com:antis81/qTox.git","clone_url":"https://github.com/antis81/qTox.git","svn_url":"https://github.com/antis81/qTox","homepage":"http://utoxisfinished.info","size":17166,"stargazers_count":0,"watchers_count":0,"language":"C++","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"tux3:master","ref":"master","sha":"064a25dd6aa2b19520871fce1d4d05ec34c9ba3d","user":{"login":"tux3","id":5155966,"avatar_url":"https://avatars.githubusercontent.com/u/5155966?v=3","gravatar_id":"","url":"https://api.github.com/users/tux3","html_url":"https://github.com/tux3","followers_url":"https://api.github.com/users/tux3/followers","following_url":"https://api.github.com/users/tux3/following{/other_user}","gists_url":"https://api.github.com/users/tux3/gists{/gist_id}","starred_url":"https://api.github.com/users/tux3/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tux3/subscriptions","organizations_url":"https://api.github.com/users/tux3/orgs","repos_url":"https://api.github.com/users/tux3/repos","events_url":"https://api.github.com/users/tux3/events{/privacy}","received_events_url":"https://api.github.com/users/tux3/received_events","type":"User","site_admin":false},"repo":{"id":21179164,"name":"qTox","full_name":"tux3/qTox","owner":{"login":"tux3","id":5155966,"avatar_url":"https://avatars.githubusercontent.com/u/5155966?v=3","gravatar_id":"","url":"https://api.github.com/users/tux3","html_url":"https://github.com/tux3","followers_url":"https://api.github.com/users/tux3/followers","following_url":"https://api.github.com/users/tux3/following{/other_user}","gists_url":"https://api.github.com/users/tux3/gists{/gist_id}","starred_url":"https://api.github.com/users/tux3/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tux3/subscriptions","organizations_url":"https://api.github.com/users/tux3/orgs","repos_url":"https://api.github.com/users/tux3/repos","events_url":"https://api.github.com/users/tux3/events{/privacy}","received_events_url":"https://api.github.com/users/tux3/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/tux3/qTox","description":"Powerful Tox chat client that follows the Tox design guidelines.","fork":false,"url":"https://api.github.com/repos/tux3/qTox","forks_url":"https://api.github.com/repos/tux3/qTox/forks","keys_url":"https://api.github.com/repos/tux3/qTox/keys{/key_id}","collaborators_url":"https://api.github.com/repos/tux3/qTox/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/tux3/qTox/teams","hooks_url":"https://api.github.com/repos/tux3/qTox/hooks","issue_events_url":"https://api.github.com/repos/tux3/qTox/issues/events{/number}","events_url":"https://api.github.com/repos/tux3/qTox/events","assignees_url":"https://api.github.com/repos/tux3/qTox/assignees{/user}","branches_url":"https://api.github.com/repos/tux3/qTox/branches{/branch}","tags_url":"https://api.github.com/repos/tux3/qTox/tags","blobs_url":"https://api.github.com/repos/tux3/qTox/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/tux3/qTox/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/tux3/qTox/git/refs{/sha}","trees_url":"https://api.github.com/repos/tux3/qTox/git/trees{/sha}","statuses_url":"https://api.github.com/repos/tux3/qTox/statuses/{sha}","languages_url":"https://api.github.com/repos/tux3/qTox/languages","stargazers_url":"https://api.github.com/repos/tux3/qTox/stargazers","contributors_url":"https://api.github.com/repos/tux3/qTox/contributors","subscribers_url":"https://api.github.com/repos/tux3/qTox/subscribers","subscription_url":"https://api.github.com/repos/tux3/qTox/subscription","commits_url":"https://api.github.com/repos/tux3/qTox/commits{/sha}","git_commits_url":"https://api.github.com/repos/tux3/qTox/git/commits{/sha}","comments_url":"https://api.github.com/repos/tux3/qTox/comments{/number}","issue_comment_url":"https://api.github.com/repos/tux3/qTox/issues/comments{/number}","contents_url":"https://api.github.com/repos/tux3/qTox/contents/{+path}","compare_url":"https://api.github.com/repos/tux3/qTox/compare/{base}...{head}","merges_url":"https://api.github.com/repos/tux3/qTox/merges","archive_url":"https://api.github.com/repos/tux3/qTox/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/tux3/qTox/downloads","issues_url":"https://api.github.com/repos/tux3/qTox/issues{/number}","pulls_url":"https://api.github.com/repos/tux3/qTox/pulls{/number}","milestones_url":"https://api.github.com/repos/tux3/qTox/milestones{/number}","notifications_url":"https://api.github.com/repos/tux3/qTox/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/tux3/qTox/labels{/name}","releases_url":"https://api.github.com/repos/tux3/qTox/releases{/id}","deployments_url":"https://api.github.com/repos/tux3/qTox/deployments","created_at":"2014-06-24T20:09:04Z","updated_at":"2016-05-18T08:25:14Z","pushed_at":"2016-05-20T22:29:11Z","git_url":"git://github.com/tux3/qTox.git","ssh_url":"git@github.com:tux3/qTox.git","clone_url":"https://github.com/tux3/qTox.git","svn_url":"https://github.com/tux3/qTox","homepage":"","size":22049,"stargazers_count":932,"watchers_count":932,"language":"C++","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":273,"mirror_url":null,"open_issues_count":487,"forks":273,"open_issues":487,"watchers":932,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/tux3/qTox/pulls/3311"},"html":{"href":"https://github.com/tux3/qTox/pull/3311"},"issue":{"href":"https://api.github.com/repos/tux3/qTox/issues/3311"},"comments":{"href":"https://api.github.com/repos/tux3/qTox/issues/3311/comments"},"review_comments":{"href":"https://api.github.com/repos/tux3/qTox/pulls/3311/comments"},"review_comment":{"href":"https://api.github.com/repos/tux3/qTox/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/tux3/qTox/pulls/3311/commits"},"statuses":{"href":"https://api.github.com/repos/tux3/qTox/statuses/f60865d5dbba0caceee03d732f3fa77b9c689446"}}}}
{"actor":{"display_login":"antis81"}}