Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
623e57a30e | ||
|
91235fb6d3 |
@@ -45,7 +45,7 @@ void setVolume(int volume) {
|
|||||||
|
|
||||||
struct ToneCmd {
|
struct ToneCmd {
|
||||||
uint8_t cmd;
|
uint8_t cmd;
|
||||||
uint8_t vol;
|
uint8_t lvl;
|
||||||
uint16_t freq;
|
uint16_t freq;
|
||||||
uint16_t duration;
|
uint16_t duration;
|
||||||
};
|
};
|
||||||
@@ -55,10 +55,26 @@ static void _stopSound() {
|
|||||||
writeDev(&cmd, sizeof(cmd));
|
writeDev(&cmd, sizeof(cmd));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static uint8_t _getVolumeLevel(uint8_t volume, uint8_t levels) {
|
||||||
|
uint8_t level;
|
||||||
|
uint8_t step = (uint8_t) (100 / (levels - 1));
|
||||||
|
if (volume < step) {
|
||||||
|
level = 0;
|
||||||
|
} else if (volume > step * (levels - 1)) {
|
||||||
|
level = levels;
|
||||||
|
} else {
|
||||||
|
level = (uint8_t) (volume / step);
|
||||||
|
}
|
||||||
|
return level;
|
||||||
|
}
|
||||||
|
|
||||||
static void _playTone(uint16_t frequency, uint16_t duration, uint8_t volume) {
|
static void _playTone(uint16_t frequency, uint16_t duration, uint8_t volume) {
|
||||||
|
// https://github.com/mindboards/ev3sources/blob/78ebaf5b6f8fe31cc17aa5dce0f8e4916a4fc072/lms2012/c_sound/source/c_sound.c#L471
|
||||||
|
uint8_t level = _getVolumeLevel(volume, 13);
|
||||||
|
|
||||||
ToneCmd cmd;
|
ToneCmd cmd;
|
||||||
cmd.cmd = SOUND_CMD_TONE;
|
cmd.cmd = SOUND_CMD_TONE;
|
||||||
cmd.vol = volume;
|
cmd.lvl = level;
|
||||||
cmd.freq = frequency;
|
cmd.freq = frequency;
|
||||||
cmd.duration = duration;
|
cmd.duration = duration;
|
||||||
// (*SoundInstance.pSound).Busy = TRUE;
|
// (*SoundInstance.pSound).Busy = TRUE;
|
||||||
@@ -122,7 +138,8 @@ void playSample(Buffer buf) {
|
|||||||
stopUser();
|
stopUser();
|
||||||
pthread_mutex_lock(&pumpMutex);
|
pthread_mutex_lock(&pumpMutex);
|
||||||
*lmsSoundMMap = 1; // BUSY
|
*lmsSoundMMap = 1; // BUSY
|
||||||
uint8_t cmd[] = {SOUND_CMD_PLAY, (uint8_t)((currVolume / 33) + 1)};
|
// https://github.com/mindboards/ev3sources/blob/78ebaf5b6f8fe31cc17aa5dce0f8e4916a4fc072/lms2012/c_sound/source/c_sound.c#L605
|
||||||
|
uint8_t cmd[] = {SOUND_CMD_PLAY, _getVolumeLevel(currVolume, 8)};
|
||||||
writeDev(cmd, 2);
|
writeDev(cmd, 2);
|
||||||
decrRC(currentSample);
|
decrRC(currentSample);
|
||||||
currentSample = buf;
|
currentSample = buf;
|
||||||
|
5105
package-lock.json
generated
Normal file
5105
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "pxt-ev3",
|
"name": "pxt-ev3",
|
||||||
"version": "1.2.28",
|
"version": "1.2.29",
|
||||||
"description": "LEGO MINDSTORMS EV3 for Microsoft MakeCode",
|
"description": "LEGO MINDSTORMS EV3 for Microsoft MakeCode",
|
||||||
"private": false,
|
"private": false,
|
||||||
"keywords": [
|
"keywords": [
|
||||||
|
Reference in New Issue
Block a user