{"action":"created","comment":{"url":"https://api.github.com/repos/mosra/magnum-plugins/pulls/comments/81736631","pull_request_review_id":2693221,"id":81736631,"diff_hunk":"@@ -44,42 +84,107 @@ auto DrFlacImporter::doFeatures() const -> Features { return Feature::OpenData;\n bool DrFlacImporter::doIsOpened() const { return _data; }\n \n void DrFlacImporter::doOpenData(Containers::ArrayView<const char> data) {\n-    drflac* handle = drflac_open_memory(data.data(), data.size());\n+\n+    std::unique_ptr<drflac, DrFlacDeleter> handle(drflac_open_memory(data.data(), data.size()));\n     if(!handle) {\n         Error() << \"Audio::DrFlacImporter::openData(): failed to open and decode FLAC data\";\n         return;\n     }\n \n     uint64_t samples = handle->totalSampleCount;\n-    uint32_t frequency = handle->sampleRate;\n     uint8_t numChannels = handle->channels;\n     uint8_t bitsPerSample = handle->bitsPerSample;\n \n-    _frequency = frequency;\n-\n-    if(numChannels == 1 && bitsPerSample == 8)\n-        _format = Buffer::Format::Mono8;\n-    else if(numChannels == 1 && bitsPerSample == 16)\n-        _format = Buffer::Format::Mono16;\n-    else if(numChannels == 2 && bitsPerSample == 8)\n-        _format = Buffer::Format::Stereo8;\n-    else if(numChannels == 2 && bitsPerSample == 16)\n-        _format = Buffer::Format::Stereo16;\n-    else {\n+    // FLAC supports any bitspersample from 4 to 64, but DrFlac always gives us 32-bit samples\n+    // So we normalize bit amounts to multiples of 8, rounding up\n+    UnsignedInt normalizedBytesPerSample = (bitsPerSample + 7)/8;\n+\n+    if(numChannels == 0 || numChannels == 3 || numChannels == 5 || numChannels > 8 ||\n+       normalizedBytesPerSample == 0 || normalizedBytesPerSample > 8) {\n         Error() << \"Audio::DrFlacImporter::openData(): unsupported channel count\"\n                 << numChannels << \"with\" << bitsPerSample\n                 << \"bits per sample\";\n+        return;\n+    }\n \n-        drflac_close(handle);\n+    if(samples == 0) {\n+        Error() << \"Audio::DrFlacImporter::openData(): no samples\";\n         return;\n     }\n \n-    Containers::Array<char> tempData(samples*sizeof(int32_t));\n+    _frequency = handle->sampleRate;\n+    _format = flacFormatTable[numChannels-1][normalizedBytesPerSample-1];\n+    CORRADE_INTERNAL_ASSERT(_format != Buffer::Format{});\n+\n+    Containers::Array<char> tempData(samples*sizeof(Int));\n+    drflac_read_s32(handle.get(), samples, reinterpret_cast<Int*>(tempData.begin()));\n+\n+    _data = convert32PCM(tempData, samples, normalizedBytesPerSample);\n+\n+    // 8-bit needs to become unsigned\n+    if(normalizedBytesPerSample == 1) {\n+        // Convert to unsigned\n+        for(char& item : _data) {\n+            item = item - 128;\n+        }\n+    }\n+\n+    // 24-bit needs to become float\n+    else if(normalizedBytesPerSample == 3) {\n+        Containers::Array<Float> floatData(samples);\n+\n+        for (UnsignedInt i = 0; i < samples; ++i) {\n+\n+            UnsignedInt s0 = _data[i*3 + 0];\n+            UnsignedInt s1 = _data[i*3 + 1];\n+            UnsignedInt s2 = _data[i*3 + 2];\n+\n+            Int sample32 = (Int)(s0 << 8) | (s1 << 16) | (s2 << 24);","path":"src/MagnumPlugins/DrFlacAudioImporter/DrFlacImporter.cpp","position":121,"original_position":121,"commit_id":"f82643677dcb63cd0f2e1f1bfaabb706cb1449e8","original_commit_id":"f82643677dcb63cd0f2e1f1bfaabb706cb1449e8","user":{"login":"mosra","id":344828,"avatar_url":"https://avatars.githubusercontent.com/u/344828?v=3","gravatar_id":"","url":"https://api.github.com/users/mosra","html_url":"https://github.com/mosra","followers_url":"https://api.github.com/users/mosra/followers","following_url":"https://api.github.com/users/mosra/following{/other_user}","gists_url":"https://api.github.com/users/mosra/gists{/gist_id}","starred_url":"https://api.github.com/users/mosra/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mosra/subscriptions","organizations_url":"https://api.github.com/users/mosra/orgs","repos_url":"https://api.github.com/users/mosra/repos","events_url":"https://api.github.com/users/mosra/events{/privacy}","received_events_url":"https://api.github.com/users/mosra/received_events","type":"User","site_admin":false},"body":"Please don't use old-style casts. In this case use a \"constructor cast\":\r\n\r\n```cpp\r\nInt sample32 = Int((s0 << 8) | (s1 << 16) | (s2 << 24));\r\n```\r\n\r\nGCC/Clang should also emit warnings on this by default -- there are four such occurences in the code.","created_at":"2016-10-04T11:34:01Z","updated_at":"2016-10-04T11:34:01Z","html_url":"https://github.com/mosra/magnum-plugins/pull/19#discussion_r81736631","pull_request_url":"https://api.github.com/repos/mosra/magnum-plugins/pulls/19","_links":{"self":{"href":"https://api.github.com/repos/mosra/magnum-plugins/pulls/comments/81736631"},"html":{"href":"https://github.com/mosra/magnum-plugins/pull/19#discussion_r81736631"},"pull_request":{"href":"https://api.github.com/repos/mosra/magnum-plugins/pulls/19"}}},"pull_request":{"url":"https://api.github.com/repos/mosra/magnum-plugins/pulls/19","id":87416946,"html_url":"https://github.com/mosra/magnum-plugins/pull/19","diff_url":"https://github.com/mosra/magnum-plugins/pull/19.diff","patch_url":"https://github.com/mosra/magnum-plugins/pull/19.patch","issue_url":"https://api.github.com/repos/mosra/magnum-plugins/issues/19","number":19,"state":"open","locked":false,"title":"Enhance DrFlacAudioImporter to allow loading of any format below 24 bits","user":{"login":"Alicemargatroid","id":2868742,"avatar_url":"https://avatars.githubusercontent.com/u/2868742?v=3","gravatar_id":"","url":"https://api.github.com/users/Alicemargatroid","html_url":"https://github.com/Alicemargatroid","followers_url":"https://api.github.com/users/Alicemargatroid/followers","following_url":"https://api.github.com/users/Alicemargatroid/following{/other_user}","gists_url":"https://api.github.com/users/Alicemargatroid/gists{/gist_id}","starred_url":"https://api.github.com/users/Alicemargatroid/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Alicemargatroid/subscriptions","organizations_url":"https://api.github.com/users/Alicemargatroid/orgs","repos_url":"https://api.github.com/users/Alicemargatroid/repos","events_url":"https://api.github.com/users/Alicemargatroid/events{/privacy}","received_events_url":"https://api.github.com/users/Alicemargatroid/received_events","type":"User","site_admin":false},"body":"DrFlacAudioImporter can now load any format below 24-bits, and correctly loads them to the same specification as WavAudioImporter. \r\n\r\nI'm currently working on converting 24-bit audio to IEEE float, and 32-bit audio to IEEE double, but this is a quick patch to get 4, 8, 12, and 16 bit audio working for DrFlacAudioImporter, and improving test coverage.","created_at":"2016-09-30T00:24:34Z","updated_at":"2016-10-04T11:39:20Z","closed_at":null,"merged_at":null,"merge_commit_sha":"0a359b83deff4fd41d99c44de3a9a316d20c5e5c","assignee":{"login":"mosra","id":344828,"avatar_url":"https://avatars.githubusercontent.com/u/344828?v=3","gravatar_id":"","url":"https://api.github.com/users/mosra","html_url":"https://github.com/mosra","followers_url":"https://api.github.com/users/mosra/followers","following_url":"https://api.github.com/users/mosra/following{/other_user}","gists_url":"https://api.github.com/users/mosra/gists{/gist_id}","starred_url":"https://api.github.com/users/mosra/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mosra/subscriptions","organizations_url":"https://api.github.com/users/mosra/orgs","repos_url":"https://api.github.com/users/mosra/repos","events_url":"https://api.github.com/users/mosra/events{/privacy}","received_events_url":"https://api.github.com/users/mosra/received_events","type":"User","site_admin":false},"assignees":[{"login":"mosra","id":344828,"avatar_url":"https://avatars.githubusercontent.com/u/344828?v=3","gravatar_id":"","url":"https://api.github.com/users/mosra","html_url":"https://github.com/mosra","followers_url":"https://api.github.com/users/mosra/followers","following_url":"https://api.github.com/users/mosra/following{/other_user}","gists_url":"https://api.github.com/users/mosra/gists{/gist_id}","starred_url":"https://api.github.com/users/mosra/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mosra/subscriptions","organizations_url":"https://api.github.com/users/mosra/orgs","repos_url":"https://api.github.com/users/mosra/repos","events_url":"https://api.github.com/users/mosra/events{/privacy}","received_events_url":"https://api.github.com/users/mosra/received_events","type":"User","site_admin":false}],"milestone":null,"commits_url":"https://api.github.com/repos/mosra/magnum-plugins/pulls/19/commits","review_comments_url":"https://api.github.com/repos/mosra/magnum-plugins/pulls/19/comments","review_comment_url":"https://api.github.com/repos/mosra/magnum-plugins/pulls/comments{/number}","comments_url":"https://api.github.com/repos/mosra/magnum-plugins/issues/19/comments","statuses_url":"https://api.github.com/repos/mosra/magnum-plugins/statuses/f82643677dcb63cd0f2e1f1bfaabb706cb1449e8","head":{"label":"Alicemargatroid:master","ref":"master","sha":"f82643677dcb63cd0f2e1f1bfaabb706cb1449e8","user":{"login":"Alicemargatroid","id":2868742,"avatar_url":"https://avatars.githubusercontent.com/u/2868742?v=3","gravatar_id":"","url":"https://api.github.com/users/Alicemargatroid","html_url":"https://github.com/Alicemargatroid","followers_url":"https://api.github.com/users/Alicemargatroid/followers","following_url":"https://api.github.com/users/Alicemargatroid/following{/other_user}","gists_url":"https://api.github.com/users/Alicemargatroid/gists{/gist_id}","starred_url":"https://api.github.com/users/Alicemargatroid/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Alicemargatroid/subscriptions","organizations_url":"https://api.github.com/users/Alicemargatroid/orgs","repos_url":"https://api.github.com/users/Alicemargatroid/repos","events_url":"https://api.github.com/users/Alicemargatroid/events{/privacy}","received_events_url":"https://api.github.com/users/Alicemargatroid/received_events","type":"User","site_admin":false},"repo":{"id":69126661,"name":"magnum-plugins","full_name":"Alicemargatroid/magnum-plugins","owner":{"login":"Alicemargatroid","id":2868742,"avatar_url":"https://avatars.githubusercontent.com/u/2868742?v=3","gravatar_id":"","url":"https://api.github.com/users/Alicemargatroid","html_url":"https://github.com/Alicemargatroid","followers_url":"https://api.github.com/users/Alicemargatroid/followers","following_url":"https://api.github.com/users/Alicemargatroid/following{/other_user}","gists_url":"https://api.github.com/users/Alicemargatroid/gists{/gist_id}","starred_url":"https://api.github.com/users/Alicemargatroid/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Alicemargatroid/subscriptions","organizations_url":"https://api.github.com/users/Alicemargatroid/orgs","repos_url":"https://api.github.com/users/Alicemargatroid/repos","events_url":"https://api.github.com/users/Alicemargatroid/events{/privacy}","received_events_url":"https://api.github.com/users/Alicemargatroid/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/Alicemargatroid/magnum-plugins","description":"Plugins for Magnum graphics engine","fork":true,"url":"https://api.github.com/repos/Alicemargatroid/magnum-plugins","forks_url":"https://api.github.com/repos/Alicemargatroid/magnum-plugins/forks","keys_url":"https://api.github.com/repos/Alicemargatroid/magnum-plugins/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Alicemargatroid/magnum-plugins/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Alicemargatroid/magnum-plugins/teams","hooks_url":"https://api.github.com/repos/Alicemargatroid/magnum-plugins/hooks","issue_events_url":"https://api.github.com/repos/Alicemargatroid/magnum-plugins/issues/events{/number}","events_url":"https://api.github.com/repos/Alicemargatroid/magnum-plugins/events","assignees_url":"https://api.github.com/repos/Alicemargatroid/magnum-plugins/assignees{/user}","branches_url":"https://api.github.com/repos/Alicemargatroid/magnum-plugins/branches{/branch}","tags_url":"https://api.github.com/repos/Alicemargatroid/magnum-plugins/tags","blobs_url":"https://api.github.com/repos/Alicemargatroid/magnum-plugins/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Alicemargatroid/magnum-plugins/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Alicemargatroid/magnum-plugins/git/refs{/sha}","trees_url":"https://api.github.com/repos/Alicemargatroid/magnum-plugins/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Alicemargatroid/magnum-plugins/statuses/{sha}","languages_url":"https://api.github.com/repos/Alicemargatroid/magnum-plugins/languages","stargazers_url":"https://api.github.com/repos/Alicemargatroid/magnum-plugins/stargazers","contributors_url":"https://api.github.com/repos/Alicemargatroid/magnum-plugins/contributors","subscribers_url":"https://api.github.com/repos/Alicemargatroid/magnum-plugins/subscribers","subscription_url":"https://api.github.com/repos/Alicemargatroid/magnum-plugins/subscription","commits_url":"https://api.github.com/repos/Alicemargatroid/magnum-plugins/commits{/sha}","git_commits_url":"https://api.github.com/repos/Alicemargatroid/magnum-plugins/git/commits{/sha}","comments_url":"https://api.github.com/repos/Alicemargatroid/magnum-plugins/comments{/number}","issue_comment_url":"https://api.github.com/repos/Alicemargatroid/magnum-plugins/issues/comments{/number}","contents_url":"https://api.github.com/repos/Alicemargatroid/magnum-plugins/contents/{+path}","compare_url":"https://api.github.com/repos/Alicemargatroid/magnum-plugins/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Alicemargatroid/magnum-plugins/merges","archive_url":"https://api.github.com/repos/Alicemargatroid/magnum-plugins/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Alicemargatroid/magnum-plugins/downloads","issues_url":"https://api.github.com/repos/Alicemargatroid/magnum-plugins/issues{/number}","pulls_url":"https://api.github.com/repos/Alicemargatroid/magnum-plugins/pulls{/number}","milestones_url":"https://api.github.com/repos/Alicemargatroid/magnum-plugins/milestones{/number}","notifications_url":"https://api.github.com/repos/Alicemargatroid/magnum-plugins/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Alicemargatroid/magnum-plugins/labels{/name}","releases_url":"https://api.github.com/repos/Alicemargatroid/magnum-plugins/releases{/id}","deployments_url":"https://api.github.com/repos/Alicemargatroid/magnum-plugins/deployments","created_at":"2016-09-24T20:42:57Z","updated_at":"2016-09-24T20:42:59Z","pushed_at":"2016-10-03T01:37:43Z","git_url":"git://github.com/Alicemargatroid/magnum-plugins.git","ssh_url":"git@github.com:Alicemargatroid/magnum-plugins.git","clone_url":"https://github.com/Alicemargatroid/magnum-plugins.git","svn_url":"https://github.com/Alicemargatroid/magnum-plugins","homepage":"http://mosra.cz/blog/magnum.php","size":4943,"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":"mosra:master","ref":"master","sha":"c47793d02ced674abe4da187dc8b3c977628c3f0","user":{"login":"mosra","id":344828,"avatar_url":"https://avatars.githubusercontent.com/u/344828?v=3","gravatar_id":"","url":"https://api.github.com/users/mosra","html_url":"https://github.com/mosra","followers_url":"https://api.github.com/users/mosra/followers","following_url":"https://api.github.com/users/mosra/following{/other_user}","gists_url":"https://api.github.com/users/mosra/gists{/gist_id}","starred_url":"https://api.github.com/users/mosra/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mosra/subscriptions","organizations_url":"https://api.github.com/users/mosra/orgs","repos_url":"https://api.github.com/users/mosra/repos","events_url":"https://api.github.com/users/mosra/events{/privacy}","received_events_url":"https://api.github.com/users/mosra/received_events","type":"User","site_admin":false},"repo":{"id":2982886,"name":"magnum-plugins","full_name":"mosra/magnum-plugins","owner":{"login":"mosra","id":344828,"avatar_url":"https://avatars.githubusercontent.com/u/344828?v=3","gravatar_id":"","url":"https://api.github.com/users/mosra","html_url":"https://github.com/mosra","followers_url":"https://api.github.com/users/mosra/followers","following_url":"https://api.github.com/users/mosra/following{/other_user}","gists_url":"https://api.github.com/users/mosra/gists{/gist_id}","starred_url":"https://api.github.com/users/mosra/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mosra/subscriptions","organizations_url":"https://api.github.com/users/mosra/orgs","repos_url":"https://api.github.com/users/mosra/repos","events_url":"https://api.github.com/users/mosra/events{/privacy}","received_events_url":"https://api.github.com/users/mosra/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/mosra/magnum-plugins","description":"Plugins for Magnum graphics engine","fork":false,"url":"https://api.github.com/repos/mosra/magnum-plugins","forks_url":"https://api.github.com/repos/mosra/magnum-plugins/forks","keys_url":"https://api.github.com/repos/mosra/magnum-plugins/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mosra/magnum-plugins/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mosra/magnum-plugins/teams","hooks_url":"https://api.github.com/repos/mosra/magnum-plugins/hooks","issue_events_url":"https://api.github.com/repos/mosra/magnum-plugins/issues/events{/number}","events_url":"https://api.github.com/repos/mosra/magnum-plugins/events","assignees_url":"https://api.github.com/repos/mosra/magnum-plugins/assignees{/user}","branches_url":"https://api.github.com/repos/mosra/magnum-plugins/branches{/branch}","tags_url":"https://api.github.com/repos/mosra/magnum-plugins/tags","blobs_url":"https://api.github.com/repos/mosra/magnum-plugins/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mosra/magnum-plugins/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mosra/magnum-plugins/git/refs{/sha}","trees_url":"https://api.github.com/repos/mosra/magnum-plugins/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mosra/magnum-plugins/statuses/{sha}","languages_url":"https://api.github.com/repos/mosra/magnum-plugins/languages","stargazers_url":"https://api.github.com/repos/mosra/magnum-plugins/stargazers","contributors_url":"https://api.github.com/repos/mosra/magnum-plugins/contributors","subscribers_url":"https://api.github.com/repos/mosra/magnum-plugins/subscribers","subscription_url":"https://api.github.com/repos/mosra/magnum-plugins/subscription","commits_url":"https://api.github.com/repos/mosra/magnum-plugins/commits{/sha}","git_commits_url":"https://api.github.com/repos/mosra/magnum-plugins/git/commits{/sha}","comments_url":"https://api.github.com/repos/mosra/magnum-plugins/comments{/number}","issue_comment_url":"https://api.github.com/repos/mosra/magnum-plugins/issues/comments{/number}","contents_url":"https://api.github.com/repos/mosra/magnum-plugins/contents/{+path}","compare_url":"https://api.github.com/repos/mosra/magnum-plugins/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mosra/magnum-plugins/merges","archive_url":"https://api.github.com/repos/mosra/magnum-plugins/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mosra/magnum-plugins/downloads","issues_url":"https://api.github.com/repos/mosra/magnum-plugins/issues{/number}","pulls_url":"https://api.github.com/repos/mosra/magnum-plugins/pulls{/number}","milestones_url":"https://api.github.com/repos/mosra/magnum-plugins/milestones{/number}","notifications_url":"https://api.github.com/repos/mosra/magnum-plugins/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mosra/magnum-plugins/labels{/name}","releases_url":"https://api.github.com/repos/mosra/magnum-plugins/releases{/id}","deployments_url":"https://api.github.com/repos/mosra/magnum-plugins/deployments","created_at":"2011-12-14T20:43:25Z","updated_at":"2016-09-08T05:27:28Z","pushed_at":"2016-10-03T09:30:44Z","git_url":"git://github.com/mosra/magnum-plugins.git","ssh_url":"git@github.com:mosra/magnum-plugins.git","clone_url":"https://github.com/mosra/magnum-plugins.git","svn_url":"https://github.com/mosra/magnum-plugins","homepage":"http://mosra.cz/blog/magnum.php","size":3618,"stargazers_count":12,"watchers_count":12,"language":"C++","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":10,"mirror_url":null,"open_issues_count":1,"forks":10,"open_issues":1,"watchers":12,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/mosra/magnum-plugins/pulls/19"},"html":{"href":"https://github.com/mosra/magnum-plugins/pull/19"},"issue":{"href":"https://api.github.com/repos/mosra/magnum-plugins/issues/19"},"comments":{"href":"https://api.github.com/repos/mosra/magnum-plugins/issues/19/comments"},"review_comments":{"href":"https://api.github.com/repos/mosra/magnum-plugins/pulls/19/comments"},"review_comment":{"href":"https://api.github.com/repos/mosra/magnum-plugins/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/mosra/magnum-plugins/pulls/19/commits"},"statuses":{"href":"https://api.github.com/repos/mosra/magnum-plugins/statuses/f82643677dcb63cd0f2e1f1bfaabb706cb1449e8"}}}}
{"actor":{"display_login":"mosra"}}