mirror of https://github.com/arendst/Tasmota.git
Merge pull request #14672 from s-hadinger/berry_audio_fixes
Small fixes to Berry audio
This commit is contained in:
commit
405d1e6eb9
|
@ -41,12 +41,15 @@ extern const bcstring be_const_str_EVENT_DELETE;
|
|||
extern const bcstring be_const_str_EVENT_DRAW_MAIN;
|
||||
extern const bcstring be_const_str_EVENT_DRAW_PART_BEGIN;
|
||||
extern const bcstring be_const_str_EVENT_DRAW_PART_END;
|
||||
extern const bcstring be_const_str_EXTERNAL_I2S;
|
||||
extern const bcstring be_const_str_False;
|
||||
extern const bcstring be_const_str_GET;
|
||||
extern const bcstring be_const_str_HTTP_GET;
|
||||
extern const bcstring be_const_str_HTTP_POST;
|
||||
extern const bcstring be_const_str_I2C_Driver;
|
||||
extern const bcstring be_const_str_I2C_X3A;
|
||||
extern const bcstring be_const_str_INTERNAL_DAC;
|
||||
extern const bcstring be_const_str_INTERNAL_PDM;
|
||||
extern const bcstring be_const_str_LVG_X3A_X20call_X20to_X20unsupported_X20callback;
|
||||
extern const bcstring be_const_str_LVG_X3A_X20object_X3A;
|
||||
extern const bcstring be_const_str_Leds;
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,14 +1,17 @@
|
|||
#include "be_constobj.h"
|
||||
|
||||
static be_define_const_map_slots(be_class_audio_output_i2s_map) {
|
||||
{ be_const_key(INTERNAL_PDM, -1), be_const_int(AudioOutputI2S::INTERNAL_PDM) },
|
||||
{ be_const_key(INTERNAL_DAC, 2), be_const_int(AudioOutputI2S::INTERNAL_DAC) },
|
||||
{ be_const_key(init, -1), be_const_func(i2s_output_i2s_init) },
|
||||
{ be_const_key(EXTERNAL_I2S, 1), be_const_int(AudioOutputI2S::EXTERNAL_I2S) },
|
||||
{ be_const_key(deinit, -1), be_const_func(i2s_output_i2s_deinit) },
|
||||
{ be_const_key(stop, -1), be_const_func(i2s_output_i2s_stop) },
|
||||
};
|
||||
|
||||
static be_define_const_map(
|
||||
be_class_audio_output_i2s_map,
|
||||
3
|
||||
6
|
||||
);
|
||||
|
||||
BE_EXPORT_VARIABLE be_define_const_class(
|
||||
|
|
|
@ -46,19 +46,29 @@ int32_t be_audio_opus_decoder_deinit(struct bvm *vm) {
|
|||
// decode(payload:bytes) -> pcm:bytes()
|
||||
int32_t be_audio_opus_decoder_decode(struct bvm *vm) {
|
||||
int32_t argc = be_top(vm);
|
||||
be_call_c_func(vm, NULL, NULL, ".(bytes)");
|
||||
be_call_c_func(vm, NULL, NULL, ".(bytes)[ii]");
|
||||
|
||||
OpusDecoder* st = (OpusDecoder*) be_convert_single_elt(vm, 1, NULL, NULL); // get value of '.p'
|
||||
size_t frames_len;
|
||||
const uint8_t * opus_frame = be_tobytes(vm, 2, &frames_len);
|
||||
size_t bytes_len;
|
||||
const uint8_t * opus_frame = be_tobytes(vm, 2, &bytes_len);
|
||||
int32_t frame_start = 0;
|
||||
int32_t frame_len = bytes_len;
|
||||
if (argc >= 3) { frame_start = be_toint(vm, 3); if (frame_start < 0) frame_start = 0; }
|
||||
if (argc >= 4) { frame_len = be_toint(vm, 4); }
|
||||
|
||||
int samples = opus_decoder_get_nb_samples(st, opus_frame, frames_len);
|
||||
if (frame_start >= bytes_len) { frame_len = 0; } // send empty packet
|
||||
else if (frame_len < 0) { frame_len = bytes_len - frame_start; } // send all packet, adjust len
|
||||
else if (frame_start + frame_len > bytes_len) { frame_len = bytes_len - frame_start; } // len is too long, adjust
|
||||
// adjust start
|
||||
opus_frame = opus_frame + frame_start;
|
||||
|
||||
int samples = opus_decoder_get_nb_samples(st, opus_frame, frame_len);
|
||||
// tasmota_log_C(LOG_LEVEL_DEBUG, "AUD: frame contains %i samples", samples);
|
||||
|
||||
// allocate a buffer for the content
|
||||
void * pcm = be_pushbytes(vm, NULL, samples * 2);
|
||||
|
||||
int ret = opus_decode(st, opus_frame, frames_len, pcm, samples, 0);
|
||||
int ret = opus_decode(st, opus_frame, frame_len, pcm, samples, 0);
|
||||
if (ret != samples) { be_raisef(vm, "internal_error", "wrong number of frames %i (supposed to be %i", ret, samples); }
|
||||
|
||||
be_return(vm);
|
||||
|
|
|
@ -147,6 +147,8 @@ int32_t be_audio_output_consume_silence(struct bvm *vm) {
|
|||
return be_call_c_func(vm, (void*) &be_audio_output_consume_silence_ntv, "i", ".");
|
||||
}
|
||||
|
||||
#include "AudioOutputI2S.h"
|
||||
|
||||
extern "C" {
|
||||
|
||||
#include "be_fixed_be_class_audio_output.h"
|
||||
|
@ -211,6 +213,10 @@ class be_class_audio_file_source (scope: global, name: AudioFileSource) {
|
|||
}
|
||||
|
||||
class be_class_audio_output_i2s (scope: global, name: AudioOutputI2S, super: be_class_audio_output) {
|
||||
EXTERNAL_I2S, int(AudioOutputI2S::EXTERNAL_I2S)
|
||||
INTERNAL_DAC, int(AudioOutputI2S::INTERNAL_DAC)
|
||||
INTERNAL_PDM, int(AudioOutputI2S::INTERNAL_PDM)
|
||||
|
||||
init, func(i2s_output_i2s_init)
|
||||
deinit, func(i2s_output_i2s_deinit)
|
||||
stop, func(i2s_output_i2s_stop)
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
|
||||
uuid = module("uuid")
|
||||
uuid.uuid4 = def ()
|
||||
import string
|
||||
import math
|
||||
return string.format("%08x-%04x-%04x-%04x-%04x%08x",
|
||||
math.rand(),
|
||||
math.rand() & 0xFFFF,
|
||||
math.rand() & 0x0FFF | 0x4000,
|
||||
math.rand() & 0x3FFF | 0x8000,
|
||||
math.rand() & 0xFFFF,
|
||||
math.rand() )
|
||||
end
|
||||
|
||||
return uuid
|
Loading…
Reference in New Issue