Skip to content

Commit

Permalink
Merge pull request #14 from OpenEarable/1.3.0
Browse files Browse the repository at this point in the history
1.3.0
  • Loading branch information
TobiasRoeddiger authored Oct 3, 2023
2 parents 2c987b8 + 10a4abd commit 59afee5
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
5 changes: 3 additions & 2 deletions assets/js/AudioManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,16 +79,17 @@ $(document).ready(function() {
// Frequency controls
$("#buttonPlayFrequency").click(function() {
var frequencyValue = parseFloat($("#frequencyNumberSelector").val());
var loudnessValue = parseFloat($("#loudnessInput").val());
var waveType = parseInt($('#waveTypeSelect').val());

if (!frequencyValue) {
log("Frequency value is not valid.", "ERROR");
return;
}

log("Sending 'Play' with frequency value '" + frequencyValue + "' Hz and wave type '" + waveType + "'.", "MESSAGE");
log("Sending 'Play' with frequency value '" + frequencyValue + "' Hz, wave type '" + waveType + "', and loudness '" + loudnessValue + "'.", "MESSAGE");
try {
openEarable.audioPlayer.frequency(AUDIO_STATE.PLAY, waveType, frequencyValue);
openEarable.audioPlayer.frequency(AUDIO_STATE.PLAY, waveType, frequencyValue, loudnessValue);
} catch (error) {
log("Error occurred while trying to play frequency: " + error, "ERROR");
}
Expand Down
5 changes: 4 additions & 1 deletion assets/js/OpenEarable.js
Original file line number Diff line number Diff line change
Expand Up @@ -615,9 +615,10 @@ class AudioPlayer {
* @param {number} state - Current state of the audio.
* @param {number} waveType - Type of wave (0 for sine, 1 for triangle, etc.).
* @param {number} frequency - Frequency value.
* @param {number} loudness - Controls the loudness of the sound.
* @returns {Promise} Resolves when data is written, rejects otherwise.
*/
async frequency(state, waveType, frequency) {
async frequency(state, waveType, frequency, loudness) {
try {
let type = 2; // 2 indicates it's a frequency
let data = new Uint8Array(8);
Expand All @@ -626,7 +627,9 @@ class AudioPlayer {
data[2] = waveType;

let freqBytes = new Float32Array([frequency]);
let loudnessBytes = new Float32Array([loudness]);
data.set(new Uint8Array(freqBytes.buffer), 3);
data.set(new Uint8Array(loudnessBytes.buffer), 4);

await this.bleManager.writeCharacteristic(
SERVICES.AUDIO_SERVICE.UUID,
Expand Down
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@ <h5 class="card-title">Audio Control </h5>
<option value="3">square (3)</option>
<option value="4">saw (4)</option>
</select>
<input id="loudnessInput" class="ms-4 is-connect-enabled" type="number" step="0.01" min="0" max="1" value="0.5">
</div>

<button id="buttonPauseFrequency" disabled class="btn btn-audio-controls btn-pause ms-3 is-connect-enabled">
Expand Down

0 comments on commit 59afee5

Please sign in to comment.