M5Unified
|
#include <Speaker_Class.hpp>
Classes | |
struct | channel_info_t |
struct | wav_info_t |
Public Member Functions | |
virtual | ~Speaker_Class (void) |
speaker_config_t | config (void) const |
void | config (const speaker_config_t &cfg) |
bool | begin (void) |
void | end (void) |
bool | isRunning (void) const |
bool | isEnabled (void) const |
bool | isPlaying (void) const volatile |
size_t | isPlaying (uint8_t channel) const volatile |
size_t | getPlayingChannels (void) const volatile |
void | setVolume (uint8_t master_volume) |
uint8_t | getVolume (void) const |
void | setAllChannelVolume (uint8_t volume) |
void | setChannelVolume (uint8_t channel, uint8_t volume) |
uint8_t | getChannelVolume (uint8_t channel) const |
void | stop (void) |
stop sound output. More... | |
void | stop (uint8_t channel) |
bool | tone (float frequency, uint32_t duration, int channel, bool stop_current_sound, const uint8_t *raw_data, size_t array_len, bool stereo=false) |
bool | tone (float frequency, uint32_t duration=UINT32_MAX, int channel=-1, bool stop_current_sound=true) |
bool | playRaw (const int8_t *raw_data, size_t array_len, uint32_t sample_rate=44100, bool stereo=false, uint32_t repeat=1, int channel=-1, bool stop_current_sound=false) |
bool | playRAW (const int8_t *raw_data, size_t array_len, uint32_t sample_rate=44100, bool stereo=false, uint32_t repeat=1, int channel=-1, bool stop_current_sound=false) |
bool | playRaw (const uint8_t *raw_data, size_t array_len, uint32_t sample_rate=44100, bool stereo=false, uint32_t repeat=1, int channel=-1, bool stop_current_sound=false) |
bool | playRAW (const uint8_t *raw_data, size_t array_len, uint32_t sample_rate=44100, bool stereo=false, uint32_t repeat=1, int channel=-1, bool stop_current_sound=false) |
bool | playRaw (const int16_t *raw_data, size_t array_len, uint32_t sample_rate=44100, bool stereo=false, uint32_t repeat=1, int channel=-1, bool stop_current_sound=false) |
bool | playRAW (const int16_t *raw_data, size_t array_len, uint32_t sample_rate=44100, bool stereo=false, uint32_t repeat=1, int channel=-1, bool stop_current_sound=false) |
bool | playWav (const uint8_t *wav_data, size_t data_len=~0u, uint32_t repeat=1, int channel=-1, bool stop_current_sound=false) |
Protected Member Functions | |
void | setCallback (void *args, bool(*func)(void *, bool)) |
esp_err_t | _setup_i2s (void) |
bool | _play_raw (const void *wav, size_t array_len, bool flg_16bit, bool flg_signed, float sample_rate, bool flg_stereo, uint32_t repeat_count, int channel, bool stop_current_sound, bool no_clear_index) |
bool | _set_next_wav (size_t ch, const wav_info_t &wav) |
Static Protected Member Functions | |
static void | spk_task (void *args) |
Protected Attributes | |
channel_info_t | _ch_info [sound_channel_max] |
speaker_config_t | _cfg |
volatile uint8_t | _master_volume = 64 |
bool(* | _cb_set_enabled )(void *args, bool enabled) = nullptr |
void * | _cb_set_enabled_args = nullptr |
volatile bool | _task_running = false |
std::atomic< uint16_t > | _play_channel_bits = { 0 } |
TaskHandle_t | _task_handle = nullptr |
volatile SemaphoreHandle_t | _task_semaphore = nullptr |
Static Protected Attributes | |
static constexpr const size_t | sound_channel_max = 8 |
static const uint8_t | _default_tone_wav [16] = { 177, 219, 246, 255, 246, 219, 177, 128, 79, 37, 10, 1, 10, 37, 79, 128 } |
Definition at line 73 of file Speaker_Class.hpp.
|
inlinevirtual |
Definition at line 77 of file Speaker_Class.hpp.
|
protected |
Definition at line 798 of file Speaker_Class.cpp.
|
protected |
|
protected |
DACが使用できるのはI2Sポート0のみ。;
all pin set to I2S_PIN_NO_CHANGE
レジスタを操作してDACモードの設定を有効にする(I2S0のみ。I2S1はDAC,ADC非対応) ;
Definition at line 63 of file Speaker_Class.cpp.
bool m5::Speaker_Class::begin | ( | void | ) |
Definition at line 683 of file Speaker_Class.cpp.
|
inline |
Definition at line 80 of file Speaker_Class.hpp.
|
inline |
Definition at line 79 of file Speaker_Class.hpp.
void m5::Speaker_Class::end | ( | void | ) |
|
inline |
gets the output volume of the sound for the specified virtual channel.
channel | virtual channel number. (0~7) |
Definition at line 130 of file Speaker_Class.hpp.
|
inline |
Get the number of channels that are playing.
Definition at line 108 of file Speaker_Class.hpp.
|
inline |
gets the output master volume of the sound.
Definition at line 116 of file Speaker_Class.hpp.
|
inline |
Definition at line 88 of file Speaker_Class.hpp.
|
inline |
now in playing or not.
channel | virtual channel number. (0~7), (default = automatically selected) |
Definition at line 104 of file Speaker_Class.hpp.
|
inline |
now in playing or not.
Definition at line 99 of file Speaker_Class.hpp.
|
inline |
Definition at line 86 of file Speaker_Class.hpp.
|
inline |
play raw sound wave data. (for signed 16bit wav data)
raw_data | wave data. |
array_len | Number of data array elements. |
sample_rate | the sampling rate (Hz) (default = 44100) |
stereo | true=data is stereo / false=data is monaural. |
repeat | number of times played repeatedly. (default = 1) |
channel | virtual channel number (If omitted, use an available channel.) |
stop_current_sound | true=start a new output without waiting for the current one to finish. |
Definition at line 208 of file Speaker_Class.hpp.
|
inline |
Definition at line 215 of file Speaker_Class.hpp.
|
inline |
play raw sound wave data. (for signed 8bit wav data)
raw_data | wave data. |
array_len | Number of data array elements. |
sample_rate | the sampling rate (Hz) (default = 44100) |
stereo | true=data is stereo / false=data is monaural. |
repeat | number of times played repeatedly. (default = 1) |
channel | virtual channel number (If omitted, use an available channel.) |
stop_current_sound | true=start a new output without waiting for the current one to finish. |
Definition at line 168 of file Speaker_Class.hpp.
|
inline |
|
inline |
play raw sound wave data. (for unsigned 8bit wav data)
raw_data | wave data. |
array_len | Number of data array elements. |
sample_rate | the sampling rate (Hz) (default = 44100) |
stereo | true=data is stereo / false=data is monaural. |
repeat | number of times played repeatedly. (default = 1) |
channel | virtual channel number (If omitted, use an available channel.) |
stop_current_sound | true=start a new output without waiting for the current one to finish. |
Definition at line 188 of file Speaker_Class.hpp.
|
inline |
bool m5::Speaker_Class::playWav | ( | const uint8_t * | wav_data, |
size_t | data_len = ~0u , |
||
uint32_t | repeat = 1 , |
||
int | channel = -1 , |
||
bool | stop_current_sound = false |
||
) |
play WAV format sound data.
wav_data | wave data. (WAV header included) |
repeat | number of times played repeatedly. (default = 1) |
channel | virtual channel number (If omitted, use an available channel.) |
stop_current_sound | true=start a new output without waiting for the current one to finish. |
Definition at line 826 of file Speaker_Class.cpp.
|
inline |
sets the output volume of the sound for the all virtual channel.
volume | channel volume (0~255) |
Definition at line 120 of file Speaker_Class.hpp.
|
inlineprotected |
Definition at line 233 of file Speaker_Class.hpp.
|
inline |
sets the output volume of the sound for the specified virtual channel.
channel | virtual channel number. (0~7) |
volume | channel volume (0~255) |
Definition at line 125 of file Speaker_Class.hpp.
|
inline |
sets the output master volume of the sound.
master_volume | master volume (0~255) |
Definition at line 112 of file Speaker_Class.hpp.
|
staticprotected |
1サンプリング当たりの出力ビット数;
MCLKを使用しない場合、サンプリングレート誤差が少なくなるようにdiv_mを調整する;
実際に設定されたサンプリングレートの算出を行う;
liner_prevからliner_baseへの2サンプル間の線形補間;
DAC出力は cfg.dac_zero_levelが0に設定されている場合、振幅のオフセットを動的に変更する。; DAC出力が低いほどノイズ音が減るため、なるべくDAC出力を下げてノイズを低減することを目的とする。;
ブザー出力は 1bit ΔΣ方式。 I2Sデータ出力をブザーの駆動信号として利用する; 出力はモノラル限定だが、I2Sへはステレオ扱いで出力する。; (I2Sをモノラル設定にした場合は同じデータが2チャンネル分送信されてしまうため、敢えてステレオ扱いとしている);
Definition at line 188 of file Speaker_Class.cpp.
void m5::Speaker_Class::stop | ( | uint8_t | channel | ) |
stop sound output for the specified virtual channel.
channel | virtual channel number. (0~7) |
Definition at line 749 of file Speaker_Class.cpp.
void m5::Speaker_Class::stop | ( | void | ) |
stop sound output.
Definition at line 738 of file Speaker_Class.cpp.
|
inline |
play simple tone sound.
frequency | tone frequency (Hz) |
duration | tone duration (msec) |
channel | virtual channel number. (0~7), (default = automatically selected) |
stop_current_sound | true=start a new output without waiting for the current one to finish. |
raw_data | Single amplitude audio data. 8bit unsigned wav. |
array_len | size of raw_data. |
stereo | true=data is stereo / false=data is mono. |
Definition at line 147 of file Speaker_Class.hpp.
|
inline |
play simple tone sound.
frequency | tone frequency (Hz) |
duration | tone duration (msec) |
channel | virtual channel number. (0~7), (default = automatically selected) |
Definition at line 156 of file Speaker_Class.hpp.
|
protected |
Definition at line 278 of file Speaker_Class.hpp.
|
protected |
Definition at line 279 of file Speaker_Class.hpp.
|
protected |
Definition at line 275 of file Speaker_Class.hpp.
|
protected |
Definition at line 267 of file Speaker_Class.hpp.
|
staticprotected |
Definition at line 231 of file Speaker_Class.hpp.
|
protected |
Definition at line 276 of file Speaker_Class.hpp.
|
protected |
Definition at line 282 of file Speaker_Class.hpp.
|
protected |
Definition at line 286 of file Speaker_Class.hpp.
|
protected |
Definition at line 281 of file Speaker_Class.hpp.
|
protected |
Definition at line 287 of file Speaker_Class.hpp.
|
staticconstexprprotected |
Definition at line 229 of file Speaker_Class.hpp.