{"action":"created","comment":{"url":"https://api.github.com/repos/urish/java-openal/pulls/comments/45559297","id":45559297,"diff_hunk":"@@ -13,71 +13,188 @@\n  * of the relevant Source object. The underlaying implementation uses a cyclic\n  * buffer array for streaming the incoming audio data into the given OpenAL\n  * source.\n- * \n+ *\n  * @author Uri Shaked\n  */\n-class SourceOutputStream extends OutputStream {\n-\tprivate static final int CYCLIC_BUFFER_COUNT = 2;\n-\n-\tprivate final Source source;\n-\tprivate final AudioFormat format;\n-\tprivate final Buffer[] buffers = new Buffer[CYCLIC_BUFFER_COUNT];\n-\n-\tprivate int queueHead = 0;\n-\tprivate int queueTail = 0;\n-\n-\tpublic SourceOutputStream(AL al, Source source, AudioFormat format) throws ALException {\n-\t\tsuper();\n-\t\tthis.source = source;\n-\t\tthis.format = format;\n-\t\tfor (int i = 0; i < buffers.length; i++) {\n-\t\t\tbuffers[i] = new Buffer(al);\n-\t\t}\n-\t}\n+public class SourceOutputStream extends OutputStream {\n \n-\t@Override\n-\tpublic void write(int b) throws IOException {\n-\t\twrite(new byte[] { (byte) b }, 0, 1);\n-\t}\n+    /**\n+     * \n+     */\n+    private int CYCLIC_BUFFER_COUNT = 3;\n+\n+    /**\n+     * \n+     */\n+    private final Source source;\n+    \n+    /**\n+     * \n+     */\n+    private final AudioFormat format;\n+    \n+    /**\n+     * \n+     */\n+    private Buffer[] buffers;\n+\n+    /**\n+     * \n+     */\n+    private int queueHead = 0;\n+    \n+    /**\n+     * \n+     */\n+    private int queueTail = 0;\n+\n+    /**\n+     * \n+     */\n+    private long samplesProcessed = 0;\n+    \n+    /**\n+     * \n+     */\n+    private final AL al;\n \n-\t@Override\n-\tpublic void write(byte[] b) throws IOException {\n-\t\twrite(b, 0, b.length);\n+    /**\n+     * \n+     * for compatibility\n+     * @param al\n+     * @param source\n+     * @param format\n+     * @throws ALException \n+     * @deprecated Use SourceOutputStream with the numberOfBuffer param\n+     */\n+    @Deprecated\n+    public SourceOutputStream(AL al, Source source, AudioFormat format) throws ALException {\n+\tsuper();\n+\tthis.al = al;\n+\tthis.source = source;\n+\tthis.format = format;\n+\tinitBuffers();\n+    }\n+    \n+    /**\n+     * \n+     * @param al\n+     * @param source\n+     * @param format\n+     * @param numberOfBuffer\n+     * @throws ALException \n+     */\n+    public SourceOutputStream(AL al, Source source, AudioFormat format, int numberOfBuffer) throws ALException {\t\n+\tsuper();\n+\tthis.al = al;\n+\tthis.source = source;\n+\tthis.format = format;\n+\tsetNumberOfBuffer(numberOfBuffer);\n+\tinitBuffers();\n+    }\n+\n+    /**\n+     * Set number and buffer and initialize them\n+     * @param numberOfBuffer \n+     */\n+    private void setNumberOfBuffer(int numberOfBuffer) throws ALException{\n+\tCYCLIC_BUFFER_COUNT = numberOfBuffer;\n+\tinitBuffers();\n+    }\n+    \n+    /**\n+     * \n+     * @return The number of buffer\n+     */\n+    public int getNumberOfBuffer(){\n+\treturn CYCLIC_BUFFER_COUNT;\n+    }\n+    \n+    /**\n+     * Initialize buffers (empty buffers)\n+     */\n+    private void initBuffers() throws ALException{\n+\tbuffers = new Buffer[CYCLIC_BUFFER_COUNT];\n+\tfor (int i = 0; i < buffers.length; i++) {\n+\t    buffers[i] = new Buffer(al);\n \t}\n+    }\n+    \n+    /**\n+     * samplesProcessed/sampleRate/channels -> ms\n+     * @return \n+     */\n+    public long getSamplesProcessed(){\n+\treturn this.samplesProcessed;\n+    }\n+\n+    /**\n+     * \n+     * @param b\n+     * @throws IOException \n+     */\n+    @Override\n+    public void write(int b) throws IOException {\n+\twrite(new byte[]{(byte) b}, 0, 1);\n+    }\n+\n+    /**\n+     * \n+     * @param b\n+     * @throws IOException \n+     */\n+    @Override\n+    public void write(byte[] b) throws IOException {\n+\twrite(b, 0, b.length);\n+    }\n \n-\t@Override\n-\tpublic void write(byte[] b, int off, int len) throws IOException {\n-\t\ttry {\n-\t\t\tint queueSize = source.getQueuedBufferCount();\n-\t\t\tif (queueSize >= buffers.length) {\n-\t\t\t\twhile (source.getProcessedBufferCount() == 0) {\n-\t\t\t\t\ttry {\n-\t\t\t\t\t\tThread.sleep(20);\n-\t\t\t\t\t} catch (InterruptedException e) {\n-\t\t\t\t\t\tthrow new IOException(\"IO Operation interrupted\", e);\n-\t\t\t\t\t}\n-\t\t\t\t}\n-\t\t\t\tsource.unqueueBuffer(buffers[queueTail]);\n-\t\t\t\tqueueTail = (queueTail + 1) % buffers.length;\n-\t\t\t}\n-\t\t\tif (off != 0) {\n-\t\t\t\tthrow new IOException(\"Offsets other than 0 are not currently supported\");\n-\t\t\t}\n-\t\t\tbuffers[queueHead].addBufferData(format, b, len);\n-\t\t\tsource.queueBuffer(buffers[queueHead]);\n-\t\t\tqueueHead = (queueHead + 1) % buffers.length;\n-\t\t\tif (source.getSourceState() == SourceState.INITIAL) {\n-\t\t\t\tsource.play();\n-\t\t\t}\n-\t\t} catch (ALException e) {\n-\t\t\tthrow new IOException(e);\n+    /**\n+     * \n+     * @param b\n+     * @param off\n+     * @param len\n+     * @throws IOException \n+     */\n+    @Override\n+    public void write(byte[] b, int off, int len) throws IOException {\n+\ttry {\n+\t    int queueSize = source.getQueuedBufferCount();\n+\t    if (queueSize >= buffers.length) {\n+\t\twhile (source.getProcessedBufferCount() == 0) {\n+\t\t    try {\n+\t\t\tThread.sleep(20);\n+\t\t    } catch (InterruptedException e) {\n+\t\t\tthrow new IOException(\"IO Operation interrupted\", e);\n+\t\t    }\n \t\t}\n+\t\tsource.unqueueBuffer(buffers[queueTail]);\n+\n+\t\tsamplesProcessed += buffers[queueTail].getIntParam(AL.AL_SIZE) / (buffers[queueTail].getIntParam(AL.AL_BITS) / 8);","path":"src/main/java/org/urish/openal/SourceOutputStream.java","position":212,"original_position":212,"commit_id":"ecaecd5f26fbbfc725cc6f5031b3bbbd5835489c","original_commit_id":"ecaecd5f26fbbfc725cc6f5031b3bbbd5835489c","user":{"login":"tokazio","id":7676865,"avatar_url":"https://avatars.githubusercontent.com/u/7676865?v=3","gravatar_id":"","url":"https://api.github.com/users/tokazio","html_url":"https://github.com/tokazio","followers_url":"https://api.github.com/users/tokazio/followers","following_url":"https://api.github.com/users/tokazio/following{/other_user}","gists_url":"https://api.github.com/users/tokazio/gists{/gist_id}","starred_url":"https://api.github.com/users/tokazio/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tokazio/subscriptions","organizations_url":"https://api.github.com/users/tokazio/orgs","repos_url":"https://api.github.com/users/tokazio/repos","events_url":"https://api.github.com/users/tokazio/events{/privacy}","received_events_url":"https://api.github.com/users/tokazio/received_events","type":"User","site_admin":false},"body":"Compute number of samples processed:\r\nsamplesProcessed/sampleRate/channels can give milliseconds processed","created_at":"2015-11-22T14:08:03Z","updated_at":"2015-11-22T14:08:03Z","html_url":"https://github.com/urish/java-openal/pull/5#discussion_r45559297","pull_request_url":"https://api.github.com/repos/urish/java-openal/pulls/5","_links":{"self":{"href":"https://api.github.com/repos/urish/java-openal/pulls/comments/45559297"},"html":{"href":"https://github.com/urish/java-openal/pull/5#discussion_r45559297"},"pull_request":{"href":"https://api.github.com/repos/urish/java-openal/pulls/5"}}},"pull_request":{"url":"https://api.github.com/repos/urish/java-openal/pulls/5","id":51465369,"html_url":"https://github.com/urish/java-openal/pull/5","diff_url":"https://github.com/urish/java-openal/pull/5.diff","patch_url":"https://github.com/urish/java-openal/pull/5.patch","issue_url":"https://api.github.com/repos/urish/java-openal/issues/5","number":5,"state":"open","locked":false,"title":"Bufferparam","user":{"login":"tokazio","id":7676865,"avatar_url":"https://avatars.githubusercontent.com/u/7676865?v=3","gravatar_id":"","url":"https://api.github.com/users/tokazio","html_url":"https://github.com/tokazio","followers_url":"https://api.github.com/users/tokazio/followers","following_url":"https://api.github.com/users/tokazio/following{/other_user}","gists_url":"https://api.github.com/users/tokazio/gists{/gist_id}","starred_url":"https://api.github.com/users/tokazio/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tokazio/subscriptions","organizations_url":"https://api.github.com/users/tokazio/orgs","repos_url":"https://api.github.com/users/tokazio/repos","events_url":"https://api.github.com/users/tokazio/events{/privacy}","received_events_url":"https://api.github.com/users/tokazio/received_events","type":"User","site_admin":false},"body":"Changed buffering system to make number and size of the streaming buffers editable.","created_at":"2015-11-22T13:59:49Z","updated_at":"2015-11-22T14:08:03Z","closed_at":null,"merged_at":null,"merge_commit_sha":"6938b645e6671918816a7cf05682f4df4135c299","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/urish/java-openal/pulls/5/commits","review_comments_url":"https://api.github.com/repos/urish/java-openal/pulls/5/comments","review_comment_url":"https://api.github.com/repos/urish/java-openal/pulls/comments{/number}","comments_url":"https://api.github.com/repos/urish/java-openal/issues/5/comments","statuses_url":"https://api.github.com/repos/urish/java-openal/statuses/ecaecd5f26fbbfc725cc6f5031b3bbbd5835489c","head":{"label":"tokazio:bufferparam","ref":"bufferparam","sha":"ecaecd5f26fbbfc725cc6f5031b3bbbd5835489c","user":{"login":"tokazio","id":7676865,"avatar_url":"https://avatars.githubusercontent.com/u/7676865?v=3","gravatar_id":"","url":"https://api.github.com/users/tokazio","html_url":"https://github.com/tokazio","followers_url":"https://api.github.com/users/tokazio/followers","following_url":"https://api.github.com/users/tokazio/following{/other_user}","gists_url":"https://api.github.com/users/tokazio/gists{/gist_id}","starred_url":"https://api.github.com/users/tokazio/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tokazio/subscriptions","organizations_url":"https://api.github.com/users/tokazio/orgs","repos_url":"https://api.github.com/users/tokazio/repos","events_url":"https://api.github.com/users/tokazio/events{/privacy}","received_events_url":"https://api.github.com/users/tokazio/received_events","type":"User","site_admin":false},"repo":{"id":46662840,"name":"java-openal","full_name":"tokazio/java-openal","owner":{"login":"tokazio","id":7676865,"avatar_url":"https://avatars.githubusercontent.com/u/7676865?v=3","gravatar_id":"","url":"https://api.github.com/users/tokazio","html_url":"https://github.com/tokazio","followers_url":"https://api.github.com/users/tokazio/followers","following_url":"https://api.github.com/users/tokazio/following{/other_user}","gists_url":"https://api.github.com/users/tokazio/gists{/gist_id}","starred_url":"https://api.github.com/users/tokazio/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tokazio/subscriptions","organizations_url":"https://api.github.com/users/tokazio/orgs","repos_url":"https://api.github.com/users/tokazio/repos","events_url":"https://api.github.com/users/tokazio/events{/privacy}","received_events_url":"https://api.github.com/users/tokazio/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/tokazio/java-openal","description":"OpenAL JNA Wrappers for Java","fork":true,"url":"https://api.github.com/repos/tokazio/java-openal","forks_url":"https://api.github.com/repos/tokazio/java-openal/forks","keys_url":"https://api.github.com/repos/tokazio/java-openal/keys{/key_id}","collaborators_url":"https://api.github.com/repos/tokazio/java-openal/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/tokazio/java-openal/teams","hooks_url":"https://api.github.com/repos/tokazio/java-openal/hooks","issue_events_url":"https://api.github.com/repos/tokazio/java-openal/issues/events{/number}","events_url":"https://api.github.com/repos/tokazio/java-openal/events","assignees_url":"https://api.github.com/repos/tokazio/java-openal/assignees{/user}","branches_url":"https://api.github.com/repos/tokazio/java-openal/branches{/branch}","tags_url":"https://api.github.com/repos/tokazio/java-openal/tags","blobs_url":"https://api.github.com/repos/tokazio/java-openal/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/tokazio/java-openal/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/tokazio/java-openal/git/refs{/sha}","trees_url":"https://api.github.com/repos/tokazio/java-openal/git/trees{/sha}","statuses_url":"https://api.github.com/repos/tokazio/java-openal/statuses/{sha}","languages_url":"https://api.github.com/repos/tokazio/java-openal/languages","stargazers_url":"https://api.github.com/repos/tokazio/java-openal/stargazers","contributors_url":"https://api.github.com/repos/tokazio/java-openal/contributors","subscribers_url":"https://api.github.com/repos/tokazio/java-openal/subscribers","subscription_url":"https://api.github.com/repos/tokazio/java-openal/subscription","commits_url":"https://api.github.com/repos/tokazio/java-openal/commits{/sha}","git_commits_url":"https://api.github.com/repos/tokazio/java-openal/git/commits{/sha}","comments_url":"https://api.github.com/repos/tokazio/java-openal/comments{/number}","issue_comment_url":"https://api.github.com/repos/tokazio/java-openal/issues/comments{/number}","contents_url":"https://api.github.com/repos/tokazio/java-openal/contents/{+path}","compare_url":"https://api.github.com/repos/tokazio/java-openal/compare/{base}...{head}","merges_url":"https://api.github.com/repos/tokazio/java-openal/merges","archive_url":"https://api.github.com/repos/tokazio/java-openal/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/tokazio/java-openal/downloads","issues_url":"https://api.github.com/repos/tokazio/java-openal/issues{/number}","pulls_url":"https://api.github.com/repos/tokazio/java-openal/pulls{/number}","milestones_url":"https://api.github.com/repos/tokazio/java-openal/milestones{/number}","notifications_url":"https://api.github.com/repos/tokazio/java-openal/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/tokazio/java-openal/labels{/name}","releases_url":"https://api.github.com/repos/tokazio/java-openal/releases{/id}","created_at":"2015-11-22T13:56:03Z","updated_at":"2015-11-22T13:56:03Z","pushed_at":"2015-11-22T13:58:16Z","git_url":"git://github.com/tokazio/java-openal.git","ssh_url":"git@github.com:tokazio/java-openal.git","clone_url":"https://github.com/tokazio/java-openal.git","svn_url":"https://github.com/tokazio/java-openal","homepage":"http://urish.github.io/java-openal/","size":53,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"urish:master","ref":"master","sha":"4d6d92e25e3f778d2b46c0b6bc762b5c65227f9d","user":{"login":"urish","id":892318,"avatar_url":"https://avatars.githubusercontent.com/u/892318?v=3","gravatar_id":"","url":"https://api.github.com/users/urish","html_url":"https://github.com/urish","followers_url":"https://api.github.com/users/urish/followers","following_url":"https://api.github.com/users/urish/following{/other_user}","gists_url":"https://api.github.com/users/urish/gists{/gist_id}","starred_url":"https://api.github.com/users/urish/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/urish/subscriptions","organizations_url":"https://api.github.com/users/urish/orgs","repos_url":"https://api.github.com/users/urish/repos","events_url":"https://api.github.com/users/urish/events{/privacy}","received_events_url":"https://api.github.com/users/urish/received_events","type":"User","site_admin":false},"repo":{"id":3945127,"name":"java-openal","full_name":"urish/java-openal","owner":{"login":"urish","id":892318,"avatar_url":"https://avatars.githubusercontent.com/u/892318?v=3","gravatar_id":"","url":"https://api.github.com/users/urish","html_url":"https://github.com/urish","followers_url":"https://api.github.com/users/urish/followers","following_url":"https://api.github.com/users/urish/following{/other_user}","gists_url":"https://api.github.com/users/urish/gists{/gist_id}","starred_url":"https://api.github.com/users/urish/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/urish/subscriptions","organizations_url":"https://api.github.com/users/urish/orgs","repos_url":"https://api.github.com/users/urish/repos","events_url":"https://api.github.com/users/urish/events{/privacy}","received_events_url":"https://api.github.com/users/urish/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/urish/java-openal","description":"OpenAL JNA Wrappers for Java","fork":false,"url":"https://api.github.com/repos/urish/java-openal","forks_url":"https://api.github.com/repos/urish/java-openal/forks","keys_url":"https://api.github.com/repos/urish/java-openal/keys{/key_id}","collaborators_url":"https://api.github.com/repos/urish/java-openal/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/urish/java-openal/teams","hooks_url":"https://api.github.com/repos/urish/java-openal/hooks","issue_events_url":"https://api.github.com/repos/urish/java-openal/issues/events{/number}","events_url":"https://api.github.com/repos/urish/java-openal/events","assignees_url":"https://api.github.com/repos/urish/java-openal/assignees{/user}","branches_url":"https://api.github.com/repos/urish/java-openal/branches{/branch}","tags_url":"https://api.github.com/repos/urish/java-openal/tags","blobs_url":"https://api.github.com/repos/urish/java-openal/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/urish/java-openal/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/urish/java-openal/git/refs{/sha}","trees_url":"https://api.github.com/repos/urish/java-openal/git/trees{/sha}","statuses_url":"https://api.github.com/repos/urish/java-openal/statuses/{sha}","languages_url":"https://api.github.com/repos/urish/java-openal/languages","stargazers_url":"https://api.github.com/repos/urish/java-openal/stargazers","contributors_url":"https://api.github.com/repos/urish/java-openal/contributors","subscribers_url":"https://api.github.com/repos/urish/java-openal/subscribers","subscription_url":"https://api.github.com/repos/urish/java-openal/subscription","commits_url":"https://api.github.com/repos/urish/java-openal/commits{/sha}","git_commits_url":"https://api.github.com/repos/urish/java-openal/git/commits{/sha}","comments_url":"https://api.github.com/repos/urish/java-openal/comments{/number}","issue_comment_url":"https://api.github.com/repos/urish/java-openal/issues/comments{/number}","contents_url":"https://api.github.com/repos/urish/java-openal/contents/{+path}","compare_url":"https://api.github.com/repos/urish/java-openal/compare/{base}...{head}","merges_url":"https://api.github.com/repos/urish/java-openal/merges","archive_url":"https://api.github.com/repos/urish/java-openal/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/urish/java-openal/downloads","issues_url":"https://api.github.com/repos/urish/java-openal/issues{/number}","pulls_url":"https://api.github.com/repos/urish/java-openal/pulls{/number}","milestones_url":"https://api.github.com/repos/urish/java-openal/milestones{/number}","notifications_url":"https://api.github.com/repos/urish/java-openal/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/urish/java-openal/labels{/name}","releases_url":"https://api.github.com/repos/urish/java-openal/releases{/id}","created_at":"2012-04-05T23:29:50Z","updated_at":"2015-09-22T12:31:17Z","pushed_at":"2015-11-22T13:59:51Z","git_url":"git://github.com/urish/java-openal.git","ssh_url":"git@github.com:urish/java-openal.git","clone_url":"https://github.com/urish/java-openal.git","svn_url":"https://github.com/urish/java-openal","homepage":"http://urish.github.io/java-openal/","size":136,"stargazers_count":5,"watchers_count":5,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":5,"mirror_url":null,"open_issues_count":1,"forks":5,"open_issues":1,"watchers":5,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/urish/java-openal/pulls/5"},"html":{"href":"https://github.com/urish/java-openal/pull/5"},"issue":{"href":"https://api.github.com/repos/urish/java-openal/issues/5"},"comments":{"href":"https://api.github.com/repos/urish/java-openal/issues/5/comments"},"review_comments":{"href":"https://api.github.com/repos/urish/java-openal/pulls/5/comments"},"review_comment":{"href":"https://api.github.com/repos/urish/java-openal/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/urish/java-openal/pulls/5/commits"},"statuses":{"href":"https://api.github.com/repos/urish/java-openal/statuses/ecaecd5f26fbbfc725cc6f5031b3bbbd5835489c"}}}}