Berry fix audio MP3 (#19578)

This commit is contained in:
s-hadinger 2023-09-23 12:23:51 +02:00 committed by GitHub
parent 375c825d32
commit 81d287a3b0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 57 additions and 65 deletions

View File

@ -208,7 +208,6 @@ be_extern_native_class(OneWire);
be_extern_native_class(Leds_ntv); be_extern_native_class(Leds_ntv);
be_extern_native_class(Leds); be_extern_native_class(Leds);
be_extern_native_class(Leds_animator); be_extern_native_class(Leds_animator);
be_extern_native_class(AudioOutput);
be_extern_native_class(AudioGenerator); be_extern_native_class(AudioGenerator);
be_extern_native_class(AudioFileSource); be_extern_native_class(AudioFileSource);
be_extern_native_class(AudioOutputI2S); be_extern_native_class(AudioOutputI2S);
@ -296,7 +295,6 @@ BERRY_LOCAL bclass_array be_class_table = {
#endif // USE_LVGL #endif // USE_LVGL
#ifdef USE_I2S_AUDIO_BERRY #ifdef USE_I2S_AUDIO_BERRY
&be_native_class(AudioOutput),
&be_native_class(AudioGenerator), &be_native_class(AudioGenerator),
&be_native_class(AudioFileSource), &be_native_class(AudioFileSource),
&be_native_class(AudioOutputI2S), &be_native_class(AudioOutputI2S),

View File

@ -10,8 +10,6 @@
#include "be_mapping.h" #include "be_mapping.h"
extern int i2s_output_i2s_init(bvm *vm);
extern int i2s_output_i2s_deinit(bvm *vm);
extern int i2s_output_i2s_stop(bvm *vm); extern int i2s_output_i2s_stop(bvm *vm);
extern int i2s_generator_wav_init(bvm *vm); extern int i2s_generator_wav_init(bvm *vm);
@ -34,9 +32,25 @@ extern int i2s_file_source_fs_deinit(bvm *vm);
#endif // USE_UFILESYS #endif // USE_UFILESYS
// AudioOutput.set_rate(rate_hz:int) -> bool // AudioOutputI2S.init() -> instance
extern void* be_audio_output_init(void); extern void* be_audio_output_i2s_init(void);
BE_FUNC_CTYPE_DECLARE(be_audio_output_init, "+.p", ""); BE_FUNC_CTYPE_DECLARE(be_audio_output_i2s_init, "+.p", "");
// AudioOutputI2S.deinit()-> void
extern void* be_audio_output_i2s_deinit(void* instance);
BE_FUNC_CTYPE_DECLARE(be_audio_output_i2s_deinit, "", ".");
// AudioOutput.begin() -> bool
extern int be_audio_output_i2s_begin(void* out);
BE_FUNC_CTYPE_DECLARE(be_audio_output_i2s_begin, "b", ".");
// AudioOutput.stop() -> bool
extern int be_audio_output_i2s_stop(void* out);
BE_FUNC_CTYPE_DECLARE(be_audio_output_i2s_stop, "b", ".");
// AudioOutput.flush() -> bool
extern void be_audio_output_i2s_flush(void* out);
BE_FUNC_CTYPE_DECLARE(be_audio_output_i2s_flush, "", ".");
// AudioOutput.set_rate(rate_hz:int) -> bool // AudioOutput.set_rate(rate_hz:int) -> bool
extern int be_audio_output_set_rate(void* out, int hz); extern int be_audio_output_set_rate(void* out, int hz);
@ -54,17 +68,7 @@ BE_FUNC_CTYPE_DECLARE(be_audio_output_set_channels, "b", ".i");
extern int be_audio_output_set_gain(void* out, float gain); extern int be_audio_output_set_gain(void* out, float gain);
BE_FUNC_CTYPE_DECLARE(be_audio_output_set_gain, "b", ".f"); BE_FUNC_CTYPE_DECLARE(be_audio_output_set_gain, "b", ".f");
// AudioOutput.begin() -> bool
extern int be_audio_output_begin(void* out);
BE_FUNC_CTYPE_DECLARE(be_audio_output_begin, "b", ".");
// AudioOutput.stop() -> bool
extern int be_audio_output_stop(void* out);
BE_FUNC_CTYPE_DECLARE(be_audio_output_stop, "b", ".");
// AudioOutput.flush() -> bool
extern void be_audio_output_flush(void* out);
BE_FUNC_CTYPE_DECLARE(be_audio_output_flush, "", ".");
// AudioOutput.consume_mono(bytes) -> int // AudioOutput.consume_mono(bytes) -> int
extern int be_audio_output_consume_mono(void* out, uint16_t *pcm, int bytes_len, int index); extern int be_audio_output_consume_mono(void* out, uint16_t *pcm, int bytes_len, int index);
@ -83,7 +87,6 @@ extern int i2s_output_i2s_set_lsb_justified(void* out, bbool lsbJustified);
BE_FUNC_CTYPE_DECLARE(i2s_output_i2s_set_lsb_justified, "b", ".b"); BE_FUNC_CTYPE_DECLARE(i2s_output_i2s_set_lsb_justified, "b", ".b");
#include "be_fixed_be_class_AudioOutput.h"
#include "be_fixed_be_class_AudioOutputI2S.h" #include "be_fixed_be_class_AudioOutputI2S.h"
#include "be_fixed_be_class_AudioGenerator.h" #include "be_fixed_be_class_AudioGenerator.h"
#include "be_fixed_be_class_AudioGeneratorWAV.h" #include "be_fixed_be_class_AudioGeneratorWAV.h"
@ -93,13 +96,22 @@ BE_FUNC_CTYPE_DECLARE(i2s_output_i2s_set_lsb_justified, "b", ".b");
/* @const_object_info_begin /* @const_object_info_begin
class be_class_AudioOutput (scope: global, name: AudioOutput, strings: weak) { class be_class_AudioGenerator (scope: global, name: AudioGenerator, strings: weak) {
.p, var .p, var
init, ctype_func(be_audio_output_init) }
begin, ctype_func(be_audio_output_begin) class be_class_AudioFileSource (scope: global, name: AudioFileSource, strings: weak) {
stop, ctype_func(be_audio_output_stop) .p, var
flush, ctype_func(be_audio_output_flush) }
class be_class_AudioOutputI2S (scope: global, name: AudioOutputI2S, strings: weak) {
.p, var
init, ctype_func(be_audio_output_i2s_init)
deinit, ctype_func(be_audio_output_i2s_deinit)
begin, ctype_func(be_audio_output_i2s_begin)
stop, ctype_func(be_audio_output_i2s_stop)
flush, ctype_func(be_audio_output_i2s_flush)
consume_mono, ctype_func(be_audio_output_consume_mono) consume_mono, ctype_func(be_audio_output_consume_mono)
consume_stereo, ctype_func(be_audio_output_consume_stereo) consume_stereo, ctype_func(be_audio_output_consume_stereo)
@ -111,20 +123,6 @@ class be_class_AudioOutput (scope: global, name: AudioOutput, strings: weak) {
set_gain, ctype_func(be_audio_output_set_gain) set_gain, ctype_func(be_audio_output_set_gain)
} }
class be_class_AudioGenerator (scope: global, name: AudioGenerator, strings: weak) {
.p, var
}
class be_class_AudioFileSource (scope: global, name: AudioFileSource, strings: weak) {
.p, var
}
class be_class_AudioOutputI2S (scope: global, name: AudioOutputI2S, super: be_class_AudioOutput, strings: weak) {
init, func(i2s_output_i2s_init)
deinit, func(i2s_output_i2s_deinit)
stop, func(i2s_output_i2s_stop)
}
class be_class_AudioGeneratorWAV (scope: global, name: AudioGeneratorWAV, super: be_class_AudioGenerator, strings: weak) { class be_class_AudioGeneratorWAV (scope: global, name: AudioGeneratorWAV, super: be_class_AudioGenerator, strings: weak) {
init, func(i2s_generator_wav_init) init, func(i2s_generator_wav_init)
deinit, func(i2s_generator_wav_deinit) deinit, func(i2s_generator_wav_deinit)

View File

@ -38,10 +38,31 @@
\*********************************************************************************************/ \*********************************************************************************************/
extern "C" { extern "C" {
// AudioOutput.set_rate(rate_hz:int) -> bool // AudioOutputI2S.init() -> instance
void* be_audio_output_init(void) { void* be_audio_output_i2s_init(void) {
return new AudioOutput(); return audio_i2s.out; // return the singleton of TasmotaAudioOutputI2S which is already initialized
} }
// AudioOutputI2S.deinit()-> void
void be_audio_output_i2s_deinit(TasmotaAudioOutputI2S * out) {
out->stop();
}
// AudioOutputI2S.begin() -> bool
int be_audio_output_i2s_begin(TasmotaAudioOutputI2S* out) {
return out->begin();
}
// AudioOutputI2S.stop() -> bool
int be_audio_output_i2s_stop(TasmotaAudioOutputI2S* out) {
return out->stop();
}
// AudioOutputI2S.flush() -> bool
void be_audio_output_i2s_flush(AudioOutput* out) {
out->flush();
}
// AudioOutput.set_rate(rate_hz:int) -> bool // AudioOutput.set_rate(rate_hz:int) -> bool
int be_audio_output_set_rate(AudioOutput* out, int hz) { int be_audio_output_set_rate(AudioOutput* out, int hz) {
return out->SetRate(hz); return out->SetRate(hz);
@ -62,21 +83,6 @@ extern "C" {
return out->SetGain(gain); return out->SetGain(gain);
} }
// AudioOutput.begin() -> bool
int be_audio_output_begin(AudioOutput* out) {
return out->begin();
}
// AudioOutput.stop() -> bool
int be_audio_output_stop(AudioOutput* out) {
return out->stop();
}
// AudioOutput.flush() -> bool
void be_audio_output_flush(AudioOutput* out) {
out->flush();
}
// AudioOutput.consume_mono(bytes) -> int // AudioOutput.consume_mono(bytes) -> int
int be_audio_output_consume_mono(AudioOutput* out, uint16_t *pcm, int bytes_len, int index) { int be_audio_output_consume_mono(AudioOutput* out, uint16_t *pcm, int bytes_len, int index) {
int pcm_len = bytes_len / 2; int pcm_len = bytes_len / 2;
@ -139,16 +145,6 @@ extern "C" {
be_return_nil(vm); be_return_nil(vm);
} }
int i2s_output_i2s_stop(bvm *vm) {
int argc = be_top(vm);
be_getmember(vm, 1, ".p");
TasmotaAudioOutputI2S * audio = (TasmotaAudioOutputI2S *) be_tocomptr(vm, -1);
if (audio) {
audio->stop();
}
be_return_nil(vm);
}
// //
// AudioGeneratorWAV() // AudioGeneratorWAV()
// //