Files
snapclient/components/lightsnapcast/include/player.h
CarlosDerSeher fae271186c Sync with sample stuffing (#69)
* upgrade to IDF v5.1.1
* add new synchronization implementation, use sample stuffing / removal to keep up sync
* use big DMA buffer for I2S and improve sync
* Add DAC TAS5805M as custom board
* add wifi credential reset
  o press reset button (nRESET pin) 3 times
    but wait about 1s between button presses
    the button press counter is reset 5s after boot
* Add support for PT8211 DAC (#78)
* upgrade ethernet interface to IDF v5 (#84)
* port official example of ethernet for IDF v5.x
* Fix cmake if guard for ethernet

Signed-off-by: Karl Osterseher <karli_o@gmx.at>
Co-authored-by: DerPicknicker <64746593+DerPicknicker@users.noreply.github.com>
Co-authored-by: whc2001 <ianwang0122@outlook.com>
2024-05-31 20:38:09 +02:00

82 lines
2.1 KiB
C

#ifndef __PLAYER_H__
#define __PLAYER_H__
#include "driver/i2s.h"
#include "esp_types.h"
#include "freertos/FreeRTOS.h"
#include "sdkconfig.h"
#include "snapcast.h"
#define I2S_PORT I2S_NUM_0
// TODO: maybe calculate this dynamically based on chunk duration and buffer
// size?!
#define CHNK_CTRL_CNT 2
#define LATENCY_MEDIAN_FILTER_LEN 199
#define LATENCY_MEDIAN_FILTER_FULL 19
// set to 0 if you do not wish to be the median an average around actual
// median average will be (LATENCY_MEDIAN_FILTER_LEN /
// LATENCY_MEDIAN_AVG_DIVISOR) + 1 samples around median. e.g. if n=4 then
// 2 samples above and below will be added plus the actual median. So in
// reality n+1 samples will be averaged
#define LATENCY_MEDIAN_AVG_DIVISOR 0
#define SHORT_BUFFER_LEN 99
#define MINI_BUFFER_LEN 19
typedef struct pcm_chunk_fragment pcm_chunk_fragment_t;
struct pcm_chunk_fragment {
size_t size;
char *payload;
pcm_chunk_fragment_t *nextFragment;
};
typedef struct pcmData {
tv_t timestamp;
uint32_t totalSize;
pcm_chunk_fragment_t *fragment;
} pcm_chunk_message_t;
typedef enum codec_type_e { NONE = 0, PCM, FLAC, OGG, OPUS } codec_type_t;
typedef struct snapcastSetting_s {
uint32_t buf_ms;
uint32_t chkInFrames;
int32_t cDacLat_ms;
codec_type_t codec;
int32_t sr;
uint8_t ch;
i2s_data_bit_width_t bits;
bool muted;
uint32_t volume;
char *pcmBuf;
uint32_t pcmBufSize;
} snapcastSetting_t;
int init_player(void);
int deinit_player(void);
int32_t allocate_pcm_chunk_memory(pcm_chunk_message_t **pcmChunk, size_t bytes);
int32_t insert_pcm_chunk(pcm_chunk_message_t *pcmChunk);
// int8_t insert_pcm_chunk (wire_chunk_message_t *decodedWireChunk);
int8_t free_pcm_chunk(pcm_chunk_message_t *pcmChunk);
int32_t player_latency_insert(int64_t newValue);
int32_t player_send_snapcast_setting(snapcastSetting_t *setting);
int8_t player_get_snapcast_settings(snapcastSetting_t *setting);
int32_t reset_latency_buffer(void);
int32_t latency_buffer_full(bool *is_full, TickType_t wait);
int32_t get_diff_to_server(int64_t *tDiff);
int32_t server_now(int64_t *sNow, int64_t *diff2Server);
int32_t pcm_chunk_queue_msg_waiting(void);
#endif // __PLAYER_H__