-
Notifications
You must be signed in to change notification settings - Fork 196
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #339 from TenghuiZhang/vuMeterLibrary
VU-meter library design 2
- Loading branch information
Showing
6 changed files
with
210 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
{"version":"3.1.0","revision":"600d7f6","lastUpdated":"2023-06-29","copyrightYear":2023} | ||
{"version":"3.1.0","revision":"b55ddb9","lastUpdated":"2023-07-05","copyrightYear":2023} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/** | ||
* @classdesc A FIFO (First-In-First-Out) class that is specifically | ||
* designed for the VUMeter class in the library directory. This class | ||
* does not have a method to get or drop a head value, but it includes | ||
* one for getting a minimum value form the queue. | ||
*/ | ||
class FIFO { | ||
|
||
/** | ||
* @constructor | ||
* @param {Number} size The size of the FIFO. | ||
*/ | ||
constructor(size) { | ||
/** @private @const {!size} The maximum number of elements that | ||
* can be stored in the FIFO */ | ||
this.size_ = size; | ||
/** @private @const {!data} The actual data array for the FIFO. */ | ||
this.data_ = new Float32Array(size); | ||
/** @private {!head} The index of the first element in the FIFO */ | ||
this.head_ = 0; | ||
/** @private {!tail} The index of the last element in the FIFO */ | ||
this.tail_ = 0; | ||
/** @private {!count} The actual number of elements in the FIFO */ | ||
this.count_ = 0; | ||
} | ||
|
||
/** | ||
* Push a new value to the tail index of the queue. If the FIFO is | ||
* full, it removes the element at the head index (the oldest) and | ||
* insert the new element at the tail index (the newest). | ||
* @param {Number} value The new value to be added to the FIFO. | ||
*/ | ||
push(value) { | ||
if (this.count_ === this.size_) { | ||
this.head_ = (this.head_ + 1) % this.size_; | ||
this.count_--; | ||
} | ||
this.data_[this.tail_] = value; | ||
this.tail_ = (this.tail_ + 1) % this.size_; | ||
this.count_++; | ||
} | ||
|
||
/** | ||
* Helper function for debugging. | ||
* @returns {Array} A newly created array contains the elements of | ||
* the FIFO in the order in which they were added. | ||
*/ | ||
toArray() { | ||
const result = []; | ||
let index = this.head_; | ||
for (let i = 0; i < this.count_; i++) { | ||
result.push(this.data_[index]); | ||
index = (index + 1) % this.size_; | ||
} | ||
return result; | ||
} | ||
|
||
/** | ||
* Find and return the minimum element in the FIFO. | ||
* @returns {Number} | ||
*/ | ||
getMinValue() { | ||
return Math.min(...this.data_); | ||
} | ||
} | ||
|
||
export default FIFO; |
Oops, something went wrong.