{"action":"created","comment":{"url":"https://api.github.com/repos/Timmmm/soundio-rs/pulls/comments/189459466","pull_request_review_id":121644065,"id":189459466,"diff_hunk":"@@ -12,18 +12,27 @@ struct SineWavePlayer {\n \n impl SineWavePlayer {\n \tfn write_callback(&mut self, stream: &mut soundio::OutStreamWriter) {\n-\t\tlet frame_count_max = stream.frame_count_max();\n-\t\tif let Err(e) = stream.begin_write(frame_count_max) {\n-\t\t\tprintln!(\"Error writing to stream: {}\", e);\n-\t\t\treturn;\n-\t\t}\n-\t\t\n-\t\tlet phase_step = self.frequency / stream.sample_rate() as f64 * 2.0 * PI;\n+\t\tlet mut frames_left = stream.frame_count_max();\n+\n+\t\tloop {\n+\t\t\tif let Err(e) = stream.begin_write(frames_left) {\n+\t\t\t\tprintln!(\"Error writing to stream: {}\", e);\n+\t\t\t\treturn;\n+\t\t\t}\n+\t\t\tlet phase_step = self.frequency / stream.sample_rate() as f64 * 2.0 * PI;\n+\n+\t\t\tfor c in 0..stream.channel_count() {\n+\t\t\t\tfor f in 0..stream.frame_count() {\n+\t\t\t\t\tstream.set_sample(c, f, (self.phase.sin() * self.amplitude) as f32);\n+\t\t\t\t\tself.phase += phase_step;\n+\t\t\t\t}\n+\t\t\t}\n+\t\t\tstream.end_write();\n \n-\t\tfor c in 0..stream.channel_count() {\n-\t\t\tfor f in 0..stream.frame_count() {\n-\t\t\t\tstream.set_sample(c, f, (self.phase.sin() * self.amplitude) as f32);\n-\t\t\t\tself.phase += phase_step;\n+\t\t\tframes_left -= stream.frame_count();\n+\t\t\tif frames_left <= 0\n+\t\t\t{","path":"examples/sine/main.rs","position":34,"original_position":34,"commit_id":"ad298bfa5d158958c9348680af5986f41c0dd6f3","original_commit_id":"ad298bfa5d158958c9348680af5986f41c0dd6f3","user":{"login":"Timmmm","id":376842,"avatar_url":"https://avatars3.githubusercontent.com/u/376842?v=4","gravatar_id":"","url":"https://api.github.com/users/Timmmm","html_url":"https://github.com/Timmmm","followers_url":"https://api.github.com/users/Timmmm/followers","following_url":"https://api.github.com/users/Timmmm/following{/other_user}","gists_url":"https://api.github.com/users/Timmmm/gists{/gist_id}","starred_url":"https://api.github.com/users/Timmmm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Timmmm/subscriptions","organizations_url":"https://api.github.com/users/Timmmm/orgs","repos_url":"https://api.github.com/users/Timmmm/repos","events_url":"https://api.github.com/users/Timmmm/events{/privacy}","received_events_url":"https://api.github.com/users/Timmmm/received_events","type":"User","site_admin":false},"body":"Formatting","created_at":"2018-05-20T13:10:42Z","updated_at":"2018-05-20T13:14:24Z","html_url":"https://github.com/Timmmm/soundio-rs/pull/3#discussion_r189459466","pull_request_url":"https://api.github.com/repos/Timmmm/soundio-rs/pulls/3","author_association":"OWNER","_links":{"self":{"href":"https://api.github.com/repos/Timmmm/soundio-rs/pulls/comments/189459466"},"html":{"href":"https://github.com/Timmmm/soundio-rs/pull/3#discussion_r189459466"},"pull_request":{"href":"https://api.github.com/repos/Timmmm/soundio-rs/pulls/3"}}},"pull_request":{"url":"https://api.github.com/repos/Timmmm/soundio-rs/pulls/3","id":189071122,"html_url":"https://github.com/Timmmm/soundio-rs/pull/3","diff_url":"https://github.com/Timmmm/soundio-rs/pull/3.diff","patch_url":"https://github.com/Timmmm/soundio-rs/pull/3.patch","issue_url":"https://api.github.com/repos/Timmmm/soundio-rs/issues/3","number":3,"state":"open","locked":false,"title":"Fixed issue with latency piling up due to not looping through all available samples to read/write","user":{"login":"tzaeru","id":537240,"avatar_url":"https://avatars0.githubusercontent.com/u/537240?v=4","gravatar_id":"","url":"https://api.github.com/users/tzaeru","html_url":"https://github.com/tzaeru","followers_url":"https://api.github.com/users/tzaeru/followers","following_url":"https://api.github.com/users/tzaeru/following{/other_user}","gists_url":"https://api.github.com/users/tzaeru/gists{/gist_id}","starred_url":"https://api.github.com/users/tzaeru/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tzaeru/subscriptions","organizations_url":"https://api.github.com/users/tzaeru/orgs","repos_url":"https://api.github.com/users/tzaeru/repos","events_url":"https://api.github.com/users/tzaeru/events{/privacy}","received_events_url":"https://api.github.com/users/tzaeru/received_events","type":"User","site_admin":false},"body":"Hey,\r\n\r\nIt looks like the problem I talked of in issue #2 is related to that both reading and writing with soundio seems to happen in chunks. `begin_read` and `begin_write` can be called multiple times and they will return a value that is often less than `stream.frame_count_max`.\r\n\r\nI tried to copy how it's done in the official [microphone example](https://github.com/andrewrk/libsoundio/blob/master/example/sio_microphone.c) of libsoundio. You can see that both in the read and write callback, they loop with begin_read/write until all frames have been read/written.\r\n\r\nRight now, I seem to have fixed my issue.. Though I couldn't get player example to work.","created_at":"2018-05-18T16:08:22Z","updated_at":"2018-05-20T13:14:24Z","closed_at":null,"merged_at":null,"merge_commit_sha":"b492e1a495578b1a3d33f905c8208681ffb7c2de","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/Timmmm/soundio-rs/pulls/3/commits","review_comments_url":"https://api.github.com/repos/Timmmm/soundio-rs/pulls/3/comments","review_comment_url":"https://api.github.com/repos/Timmmm/soundio-rs/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Timmmm/soundio-rs/issues/3/comments","statuses_url":"https://api.github.com/repos/Timmmm/soundio-rs/statuses/ad298bfa5d158958c9348680af5986f41c0dd6f3","head":{"label":"tzaeru:read-loop-latency-fix","ref":"read-loop-latency-fix","sha":"ad298bfa5d158958c9348680af5986f41c0dd6f3","user":{"login":"tzaeru","id":537240,"avatar_url":"https://avatars0.githubusercontent.com/u/537240?v=4","gravatar_id":"","url":"https://api.github.com/users/tzaeru","html_url":"https://github.com/tzaeru","followers_url":"https://api.github.com/users/tzaeru/followers","following_url":"https://api.github.com/users/tzaeru/following{/other_user}","gists_url":"https://api.github.com/users/tzaeru/gists{/gist_id}","starred_url":"https://api.github.com/users/tzaeru/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tzaeru/subscriptions","organizations_url":"https://api.github.com/users/tzaeru/orgs","repos_url":"https://api.github.com/users/tzaeru/repos","events_url":"https://api.github.com/users/tzaeru/events{/privacy}","received_events_url":"https://api.github.com/users/tzaeru/received_events","type":"User","site_admin":false},"repo":{"id":133961940,"name":"soundio-rs","full_name":"tzaeru/soundio-rs","owner":{"login":"tzaeru","id":537240,"avatar_url":"https://avatars0.githubusercontent.com/u/537240?v=4","gravatar_id":"","url":"https://api.github.com/users/tzaeru","html_url":"https://github.com/tzaeru","followers_url":"https://api.github.com/users/tzaeru/followers","following_url":"https://api.github.com/users/tzaeru/following{/other_user}","gists_url":"https://api.github.com/users/tzaeru/gists{/gist_id}","starred_url":"https://api.github.com/users/tzaeru/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tzaeru/subscriptions","organizations_url":"https://api.github.com/users/tzaeru/orgs","repos_url":"https://api.github.com/users/tzaeru/repos","events_url":"https://api.github.com/users/tzaeru/events{/privacy}","received_events_url":"https://api.github.com/users/tzaeru/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/tzaeru/soundio-rs","description":"A Rust wrapper for libsoundio.","fork":true,"url":"https://api.github.com/repos/tzaeru/soundio-rs","forks_url":"https://api.github.com/repos/tzaeru/soundio-rs/forks","keys_url":"https://api.github.com/repos/tzaeru/soundio-rs/keys{/key_id}","collaborators_url":"https://api.github.com/repos/tzaeru/soundio-rs/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/tzaeru/soundio-rs/teams","hooks_url":"https://api.github.com/repos/tzaeru/soundio-rs/hooks","issue_events_url":"https://api.github.com/repos/tzaeru/soundio-rs/issues/events{/number}","events_url":"https://api.github.com/repos/tzaeru/soundio-rs/events","assignees_url":"https://api.github.com/repos/tzaeru/soundio-rs/assignees{/user}","branches_url":"https://api.github.com/repos/tzaeru/soundio-rs/branches{/branch}","tags_url":"https://api.github.com/repos/tzaeru/soundio-rs/tags","blobs_url":"https://api.github.com/repos/tzaeru/soundio-rs/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/tzaeru/soundio-rs/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/tzaeru/soundio-rs/git/refs{/sha}","trees_url":"https://api.github.com/repos/tzaeru/soundio-rs/git/trees{/sha}","statuses_url":"https://api.github.com/repos/tzaeru/soundio-rs/statuses/{sha}","languages_url":"https://api.github.com/repos/tzaeru/soundio-rs/languages","stargazers_url":"https://api.github.com/repos/tzaeru/soundio-rs/stargazers","contributors_url":"https://api.github.com/repos/tzaeru/soundio-rs/contributors","subscribers_url":"https://api.github.com/repos/tzaeru/soundio-rs/subscribers","subscription_url":"https://api.github.com/repos/tzaeru/soundio-rs/subscription","commits_url":"https://api.github.com/repos/tzaeru/soundio-rs/commits{/sha}","git_commits_url":"https://api.github.com/repos/tzaeru/soundio-rs/git/commits{/sha}","comments_url":"https://api.github.com/repos/tzaeru/soundio-rs/comments{/number}","issue_comment_url":"https://api.github.com/repos/tzaeru/soundio-rs/issues/comments{/number}","contents_url":"https://api.github.com/repos/tzaeru/soundio-rs/contents/{+path}","compare_url":"https://api.github.com/repos/tzaeru/soundio-rs/compare/{base}...{head}","merges_url":"https://api.github.com/repos/tzaeru/soundio-rs/merges","archive_url":"https://api.github.com/repos/tzaeru/soundio-rs/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/tzaeru/soundio-rs/downloads","issues_url":"https://api.github.com/repos/tzaeru/soundio-rs/issues{/number}","pulls_url":"https://api.github.com/repos/tzaeru/soundio-rs/pulls{/number}","milestones_url":"https://api.github.com/repos/tzaeru/soundio-rs/milestones{/number}","notifications_url":"https://api.github.com/repos/tzaeru/soundio-rs/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/tzaeru/soundio-rs/labels{/name}","releases_url":"https://api.github.com/repos/tzaeru/soundio-rs/releases{/id}","deployments_url":"https://api.github.com/repos/tzaeru/soundio-rs/deployments","created_at":"2018-05-18T14:02:23Z","updated_at":"2018-05-18T14:02:25Z","pushed_at":"2018-05-18T16:02:52Z","git_url":"git://github.com/tzaeru/soundio-rs.git","ssh_url":"git@github.com:tzaeru/soundio-rs.git","clone_url":"https://github.com/tzaeru/soundio-rs.git","svn_url":"https://github.com/tzaeru/soundio-rs","homepage":"","size":314,"stargazers_count":0,"watchers_count":0,"language":"Rust","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":null,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"Timmmm:master","ref":"master","sha":"38752c93f222b7fcdd167c00436978cb6512694e","user":{"login":"Timmmm","id":376842,"avatar_url":"https://avatars3.githubusercontent.com/u/376842?v=4","gravatar_id":"","url":"https://api.github.com/users/Timmmm","html_url":"https://github.com/Timmmm","followers_url":"https://api.github.com/users/Timmmm/followers","following_url":"https://api.github.com/users/Timmmm/following{/other_user}","gists_url":"https://api.github.com/users/Timmmm/gists{/gist_id}","starred_url":"https://api.github.com/users/Timmmm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Timmmm/subscriptions","organizations_url":"https://api.github.com/users/Timmmm/orgs","repos_url":"https://api.github.com/users/Timmmm/repos","events_url":"https://api.github.com/users/Timmmm/events{/privacy}","received_events_url":"https://api.github.com/users/Timmmm/received_events","type":"User","site_admin":false},"repo":{"id":75439972,"name":"soundio-rs","full_name":"Timmmm/soundio-rs","owner":{"login":"Timmmm","id":376842,"avatar_url":"https://avatars3.githubusercontent.com/u/376842?v=4","gravatar_id":"","url":"https://api.github.com/users/Timmmm","html_url":"https://github.com/Timmmm","followers_url":"https://api.github.com/users/Timmmm/followers","following_url":"https://api.github.com/users/Timmmm/following{/other_user}","gists_url":"https://api.github.com/users/Timmmm/gists{/gist_id}","starred_url":"https://api.github.com/users/Timmmm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Timmmm/subscriptions","organizations_url":"https://api.github.com/users/Timmmm/orgs","repos_url":"https://api.github.com/users/Timmmm/repos","events_url":"https://api.github.com/users/Timmmm/events{/privacy}","received_events_url":"https://api.github.com/users/Timmmm/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/Timmmm/soundio-rs","description":"A Rust wrapper for libsoundio.","fork":false,"url":"https://api.github.com/repos/Timmmm/soundio-rs","forks_url":"https://api.github.com/repos/Timmmm/soundio-rs/forks","keys_url":"https://api.github.com/repos/Timmmm/soundio-rs/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Timmmm/soundio-rs/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Timmmm/soundio-rs/teams","hooks_url":"https://api.github.com/repos/Timmmm/soundio-rs/hooks","issue_events_url":"https://api.github.com/repos/Timmmm/soundio-rs/issues/events{/number}","events_url":"https://api.github.com/repos/Timmmm/soundio-rs/events","assignees_url":"https://api.github.com/repos/Timmmm/soundio-rs/assignees{/user}","branches_url":"https://api.github.com/repos/Timmmm/soundio-rs/branches{/branch}","tags_url":"https://api.github.com/repos/Timmmm/soundio-rs/tags","blobs_url":"https://api.github.com/repos/Timmmm/soundio-rs/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Timmmm/soundio-rs/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Timmmm/soundio-rs/git/refs{/sha}","trees_url":"https://api.github.com/repos/Timmmm/soundio-rs/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Timmmm/soundio-rs/statuses/{sha}","languages_url":"https://api.github.com/repos/Timmmm/soundio-rs/languages","stargazers_url":"https://api.github.com/repos/Timmmm/soundio-rs/stargazers","contributors_url":"https://api.github.com/repos/Timmmm/soundio-rs/contributors","subscribers_url":"https://api.github.com/repos/Timmmm/soundio-rs/subscribers","subscription_url":"https://api.github.com/repos/Timmmm/soundio-rs/subscription","commits_url":"https://api.github.com/repos/Timmmm/soundio-rs/commits{/sha}","git_commits_url":"https://api.github.com/repos/Timmmm/soundio-rs/git/commits{/sha}","comments_url":"https://api.github.com/repos/Timmmm/soundio-rs/comments{/number}","issue_comment_url":"https://api.github.com/repos/Timmmm/soundio-rs/issues/comments{/number}","contents_url":"https://api.github.com/repos/Timmmm/soundio-rs/contents/{+path}","compare_url":"https://api.github.com/repos/Timmmm/soundio-rs/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Timmmm/soundio-rs/merges","archive_url":"https://api.github.com/repos/Timmmm/soundio-rs/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Timmmm/soundio-rs/downloads","issues_url":"https://api.github.com/repos/Timmmm/soundio-rs/issues{/number}","pulls_url":"https://api.github.com/repos/Timmmm/soundio-rs/pulls{/number}","milestones_url":"https://api.github.com/repos/Timmmm/soundio-rs/milestones{/number}","notifications_url":"https://api.github.com/repos/Timmmm/soundio-rs/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Timmmm/soundio-rs/labels{/name}","releases_url":"https://api.github.com/repos/Timmmm/soundio-rs/releases{/id}","deployments_url":"https://api.github.com/repos/Timmmm/soundio-rs/deployments","created_at":"2016-12-02T23:48:28Z","updated_at":"2018-05-18T13:12:35Z","pushed_at":"2018-05-18T16:08:23Z","git_url":"git://github.com/Timmmm/soundio-rs.git","ssh_url":"git@github.com:Timmmm/soundio-rs.git","clone_url":"https://github.com/Timmmm/soundio-rs.git","svn_url":"https://github.com/Timmmm/soundio-rs","homepage":"","size":312,"stargazers_count":7,"watchers_count":7,"language":"Rust","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":2,"mirror_url":null,"archived":false,"open_issues_count":2,"license":null,"forks":2,"open_issues":2,"watchers":7,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/Timmmm/soundio-rs/pulls/3"},"html":{"href":"https://github.com/Timmmm/soundio-rs/pull/3"},"issue":{"href":"https://api.github.com/repos/Timmmm/soundio-rs/issues/3"},"comments":{"href":"https://api.github.com/repos/Timmmm/soundio-rs/issues/3/comments"},"review_comments":{"href":"https://api.github.com/repos/Timmmm/soundio-rs/pulls/3/comments"},"review_comment":{"href":"https://api.github.com/repos/Timmmm/soundio-rs/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Timmmm/soundio-rs/pulls/3/commits"},"statuses":{"href":"https://api.github.com/repos/Timmmm/soundio-rs/statuses/ad298bfa5d158958c9348680af5986f41c0dd6f3"}},"author_association":"NONE"}}
{"actor":{"display_login":"Timmmm"}}