A buffer enters the first stage and moves through every stage in order. It is completed after all of its frames leave the final stage.
AudioBufferPipeline
public AudioBufferPipeline(int framesPerSecond, List<String> stageNames)
framesPerSecond is the maximum number of frames that each stage can process during one second.stageNames contains the processing stages in the order in which every audio frame must visit them.public boolean addBuffer(String bufferId, int frameCount)
frameCount frames to the end of the first stage's queue.true when the buffer is added.false when bufferId has already been used. In this case, the pipeline remains unchanged.public List<String> processSecond()
framesPerSecond and the number of frames that were waiting at that stage when the method started.public List<String> getStageLoads()
"stageName,queuedFrames".stageNames.processSecond.processSecond.1 ≤ framesPerSecond ≤ 1,000,000,0001 ≤ stageNames.size() ≤ 501 ≤ stageNames.get(i).length() ≤ 1001 ≤ bufferId.length() ≤ 1001 ≤ frameCount ≤ 1,000,000,000100,000 buffers will be successfully added.100,000 calls will be made to processSecond.AudioBufferPipeline(framesPerSecond = 4, stageNames = ["decode", "filter", "playback"])
Creates an empty three-stage pipeline in which each stage processes at most four frames per second.
addBuffer(bufferId = "voice", frameCount = 6)
Output: true
processSecond()
Output: []
Four frames move from decode to filter.
getStageLoads()
Output: ["decode,2", "filter,4", "playback,0"]
processSecond()
Output: []
getStageLoads()
Output: ["decode,0", "filter,2", "playback,4"]
processSecond()
Output: []
The first four frames leave the final stage, while the remaining two frames enter it.
processSecond()
Output: ["voice"]
The final two frames leave playback, so the buffer completes.
AudioBufferPipeline(framesPerSecond = 5, stageNames = ["clean", "encode"])
addBuffer(bufferId = "intro", frameCount = 2)
Output: true
addBuffer(bufferId = "speech", frameCount = 3)
Output: true
processSecond()
Output: []
Both buffers move from clean to encode.
processSecond()
Output: ["intro", "speech"]
Both buffers leave the final stage. Their identifiers are returned in submission order.
addBuffer(bufferId = "intro", frameCount = 1)
Output: false
The identifier "intro" cannot be reused after completion.
AudioBufferPipeline(framesPerSecond = 3, stageNames = ["playback"])
addBuffer(bufferId = "music", frameCount = 7)
Output: true
processSecond()
Output: []
getStageLoads()
Output: ["playback,4"]
processSecond()
Output: []
getStageLoads()
Output: ["playback,1"]
processSecond()
Output: ["music"]
The seventh and final frame leaves the only stage during the third second.