mirror of
https://github.com/sle118/squeezelite-esp32.git
synced 2026-01-30 06:10:54 +03:00
catching up (trying to) wiht CSpot
This commit is contained in:
21
components/spotify/cspot/bell/include/AudioSink.h
Normal file
21
components/spotify/cspot/bell/include/AudioSink.h
Normal file
@@ -0,0 +1,21 @@
|
||||
#ifndef AUDIOSINK_H
|
||||
#define AUDIOSINK_H
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstdlib>
|
||||
#include <vector>
|
||||
|
||||
class AudioSink
|
||||
{
|
||||
public:
|
||||
AudioSink() {}
|
||||
virtual ~AudioSink() {}
|
||||
virtual void feedPCMFrames(const uint8_t *buffer, size_t bytes) = 0;
|
||||
virtual void volumeChanged(uint16_t volume) {}
|
||||
// return true if the sink supports rate changing
|
||||
virtual bool setRate(uint16_t sampleRate) { return false; }
|
||||
bool softwareVolumeControl = true;
|
||||
bool usign = false;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -83,8 +83,6 @@ namespace bell
|
||||
{
|
||||
std::string basenameStr(filename.substr(filename.rfind("/") + 1));
|
||||
unsigned long hash = 5381;
|
||||
int c;
|
||||
|
||||
for (char const &c : basenameStr)
|
||||
{
|
||||
hash = ((hash << 5) + hash) + c; /* hash * 33 + c */
|
||||
|
||||
@@ -15,13 +15,13 @@ std::string generateRandomUUID();
|
||||
#include <freertos/FreeRTOS.h>
|
||||
|
||||
#define BELL_SLEEP_MS(ms) vTaskDelay(ms / portTICK_PERIOD_MS)
|
||||
#define BELL_YIELD() vTaskYield()
|
||||
#define BELL_YIELD() taskYIELD()
|
||||
|
||||
#else
|
||||
#include <unistd.h>
|
||||
|
||||
#define BELL_SLEEP_MS(ms) usleep(ms * 1000)
|
||||
#define BELL_YIELD() ()
|
||||
#define BELL_YIELD() ;
|
||||
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
#ifndef BELL_BYTE_READER_H
|
||||
#define BELL_BYTE_READER_H
|
||||
|
||||
#include "stdlib.h"
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
|
||||
/**
|
||||
* A class for reading bytes from a stream. Further implemented in HTTPStream.h
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#define BELL_HTTP_CLIENT
|
||||
|
||||
#include "BellSocket.h"
|
||||
#include "ByteStream.h"
|
||||
#include "TCPSocket.h"
|
||||
#include "platform/TLSSocket.h"
|
||||
#include <map>
|
||||
@@ -21,13 +22,15 @@ class HTTPClient {
|
||||
struct HTTPRequest {
|
||||
HTTPMethod method = HTTPMethod::GET;
|
||||
std::string url;
|
||||
std::string body;
|
||||
const char *body = nullptr;
|
||||
const char *contentType = nullptr;
|
||||
std::map<std::string, std::string> headers;
|
||||
std::string contentType;
|
||||
int maxRedirects = -1;
|
||||
std::ostream *dumpFs = nullptr;
|
||||
std::ostream *dumpRawFs = nullptr;
|
||||
};
|
||||
|
||||
struct HTTPResponse {
|
||||
struct HTTPResponse : public ByteStream {
|
||||
std::shared_ptr<bell::Socket> socket;
|
||||
|
||||
std::map<std::string, std::string> headers;
|
||||
@@ -41,18 +44,32 @@ class HTTPClient {
|
||||
bool isComplete = false;
|
||||
bool isRedirect = false;
|
||||
size_t redirectCount = 0;
|
||||
std::ostream *dumpFs = nullptr;
|
||||
std::ostream *dumpRawFs = nullptr;
|
||||
|
||||
void close() {
|
||||
socket->close();
|
||||
free(buf);
|
||||
buf = nullptr;
|
||||
bufPtr = nullptr;
|
||||
}
|
||||
~HTTPResponse();
|
||||
void close() override;
|
||||
|
||||
void readHeaders();
|
||||
size_t read(char *dst, size_t len);
|
||||
size_t read(char *dst, size_t len, bool wait = false);
|
||||
std::string readToString();
|
||||
|
||||
inline size_t skip(size_t len) override {
|
||||
return read((char *)nullptr, len);
|
||||
}
|
||||
inline size_t read(uint8_t *dst, size_t len) override {
|
||||
return read((char *)dst, len);
|
||||
}
|
||||
inline size_t read(uint8_t *dst, size_t len, bool wait) {
|
||||
return read((char *)dst, len, wait);
|
||||
}
|
||||
inline size_t size() override {
|
||||
return contentLength;
|
||||
}
|
||||
inline size_t position() override {
|
||||
return bodyRead;
|
||||
}
|
||||
|
||||
private:
|
||||
char *buf = nullptr; // allocated buffer
|
||||
char *bufPtr = nullptr; // reading pointer within buf
|
||||
@@ -61,16 +78,19 @@ class HTTPClient {
|
||||
size_t chunkRemaining = 0;
|
||||
bool isStreaming = false;
|
||||
size_t readRaw(char *dst);
|
||||
bool skip(size_t len, bool dontRead = false);
|
||||
bool skipRaw(size_t len, bool dontRead = false);
|
||||
};
|
||||
|
||||
typedef std::unique_ptr<struct HTTPClient::HTTPResponse> HTTPResponse_t;
|
||||
|
||||
private:
|
||||
static void executeImpl(const struct HTTPRequest &request, const char *url, struct HTTPResponse *&response);
|
||||
static HTTPResponse_t executeImpl(const struct HTTPRequest &request, HTTPResponse_t response);
|
||||
static bool readHeader(const char *&header, const char *name);
|
||||
|
||||
public:
|
||||
static struct HTTPResponse *execute(const struct HTTPRequest &request);
|
||||
static HTTPResponse_t execute(const struct HTTPRequest &request);
|
||||
};
|
||||
typedef std::unique_ptr<struct HTTPClient::HTTPResponse> HTTPResponse_t;
|
||||
} // namespace bell
|
||||
|
||||
#endif
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <vector>
|
||||
#include "pb_encode.h"
|
||||
#include "pb_decode.h"
|
||||
#include "HTTPClient.h"
|
||||
#include <string>
|
||||
|
||||
std::vector<uint8_t> pbEncode(const pb_msgdesc_t *fields, const void *src_struct);
|
||||
@@ -41,6 +42,7 @@ void pbDecode(T &result, const pb_msgdesc_t *fields, std::vector<uint8_t> &data)
|
||||
}
|
||||
}
|
||||
|
||||
void pbFree(const pb_msgdesc_t *fields, void *src_struct);
|
||||
const char* pb_encode_to_string(const pb_msgdesc_t *fields, const void *data);
|
||||
pb_istream_t pb_istream_from_http(bell::HTTPClient::HTTPResponse *response, size_t length = 0);
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -15,7 +15,7 @@ namespace bell
|
||||
/// Queue
|
||||
std::queue<dataType> m_queue;
|
||||
/// Mutex to controll multiple access
|
||||
std::mutex m_mutex;
|
||||
mutable std::mutex m_mutex;
|
||||
/// Conditional variable used to fire event
|
||||
std::condition_variable m_cv;
|
||||
/// Atomic variable used to terminate immediately wpop and wtpop functions
|
||||
|
||||
@@ -46,7 +46,7 @@ namespace bell
|
||||
hints.ai_protocol = IPPROTO_IP; // no enum : possible value can be read in /etc/protocols
|
||||
hints.ai_flags = AI_CANONNAME | AI_ALL | AI_ADDRCONFIG;
|
||||
|
||||
BELL_LOG(info, "http", "%s %d", host.c_str(), port);
|
||||
// BELL_LOG(info, "http", "%s %d", host.c_str(), port);
|
||||
|
||||
char portStr[6];
|
||||
sprintf(portStr, "%u", port);
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#endif
|
||||
|
||||
#include <pthread.h>
|
||||
#include <string>
|
||||
|
||||
namespace bell
|
||||
{
|
||||
@@ -51,6 +52,7 @@ namespace bell
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("task on internal %s", this->taskName.c_str());
|
||||
esp_pthread_cfg_t cfg = esp_pthread_get_default_config();
|
||||
cfg.stack_size = stackSize;
|
||||
cfg.inherit_cfg = true;
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
#ifndef AC101AUDIOSINK_H
|
||||
#define AC101AUDIOSINK_H
|
||||
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
#include "BufferedAudioSink.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sys/unistd.h>
|
||||
#include <sys/stat.h>
|
||||
#include "esp_err.h"
|
||||
#include "esp_log.h"
|
||||
#include "ac101.h"
|
||||
#include "adac.h"
|
||||
|
||||
class AC101AudioSink : public BufferedAudioSink
|
||||
{
|
||||
public:
|
||||
AC101AudioSink();
|
||||
~AC101AudioSink();
|
||||
void volumeChanged(uint16_t volume);
|
||||
private:
|
||||
adac_s *dac;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,25 @@
|
||||
#ifndef BUFFEREDAUDIOSINK_H
|
||||
#define BUFFEREDAUDIOSINK_H
|
||||
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
#include "AudioSink.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sys/unistd.h>
|
||||
#include <sys/stat.h>
|
||||
#include "esp_err.h"
|
||||
#include "esp_log.h"
|
||||
|
||||
class BufferedAudioSink : public AudioSink
|
||||
{
|
||||
public:
|
||||
void feedPCMFrames(const uint8_t *buffer, size_t bytes);
|
||||
bool setRate(uint16_t sampleRate) override;
|
||||
protected:
|
||||
void startI2sFeed(size_t buf_size = 4096 * 8);
|
||||
void feedPCMFramesInternal(const void *pvItem, size_t xItemSize);
|
||||
private:
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,105 @@
|
||||
#ifndef ES8388AUDIOSINK_H
|
||||
#define ES8388AUDIOSINK_H
|
||||
|
||||
#include "driver/i2s.h"
|
||||
#include <driver/i2c.h>
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
#include "BufferedAudioSink.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
#include <sys/unistd.h>
|
||||
#include <sys/stat.h>
|
||||
#include "esp_err.h"
|
||||
#include "esp_log.h"
|
||||
|
||||
|
||||
#define ES8388_ADDR 0x20
|
||||
|
||||
#define ACK_CHECK_EN 0x1
|
||||
|
||||
/* ES8388 register */
|
||||
#define ES8388_CONTROL1 0x00
|
||||
#define ES8388_CONTROL2 0x01
|
||||
#define ES8388_CHIPPOWER 0x02
|
||||
#define ES8388_ADCPOWER 0x03
|
||||
#define ES8388_DACPOWER 0x04
|
||||
#define ES8388_CHIPLOPOW1 0x05
|
||||
#define ES8388_CHIPLOPOW2 0x06
|
||||
#define ES8388_ANAVOLMANAG 0x07
|
||||
#define ES8388_MASTERMODE 0x08
|
||||
|
||||
/* ADC */
|
||||
#define ES8388_ADCCONTROL1 0x09
|
||||
#define ES8388_ADCCONTROL2 0x0a
|
||||
#define ES8388_ADCCONTROL3 0x0b
|
||||
#define ES8388_ADCCONTROL4 0x0c
|
||||
#define ES8388_ADCCONTROL5 0x0d
|
||||
#define ES8388_ADCCONTROL6 0x0e
|
||||
#define ES8388_ADCCONTROL7 0x0f
|
||||
#define ES8388_ADCCONTROL8 0x10
|
||||
#define ES8388_ADCCONTROL9 0x11
|
||||
#define ES8388_ADCCONTROL10 0x12
|
||||
#define ES8388_ADCCONTROL11 0x13
|
||||
#define ES8388_ADCCONTROL12 0x14
|
||||
#define ES8388_ADCCONTROL13 0x15
|
||||
#define ES8388_ADCCONTROL14 0x16
|
||||
|
||||
/* DAC */
|
||||
#define ES8388_DACCONTROL1 0x17
|
||||
#define ES8388_DACCONTROL2 0x18
|
||||
#define ES8388_DACCONTROL3 0x19
|
||||
#define ES8388_DACCONTROL4 0x1a
|
||||
#define ES8388_DACCONTROL5 0x1b
|
||||
#define ES8388_DACCONTROL6 0x1c
|
||||
#define ES8388_DACCONTROL7 0x1d
|
||||
#define ES8388_DACCONTROL8 0x1e
|
||||
#define ES8388_DACCONTROL9 0x1f
|
||||
#define ES8388_DACCONTROL10 0x20
|
||||
#define ES8388_DACCONTROL11 0x21
|
||||
#define ES8388_DACCONTROL12 0x22
|
||||
#define ES8388_DACCONTROL13 0x23
|
||||
#define ES8388_DACCONTROL14 0x24
|
||||
#define ES8388_DACCONTROL15 0x25
|
||||
#define ES8388_DACCONTROL16 0x26
|
||||
#define ES8388_DACCONTROL17 0x27
|
||||
#define ES8388_DACCONTROL18 0x28
|
||||
#define ES8388_DACCONTROL19 0x29
|
||||
#define ES8388_DACCONTROL20 0x2a
|
||||
#define ES8388_DACCONTROL21 0x2b
|
||||
#define ES8388_DACCONTROL22 0x2c
|
||||
#define ES8388_DACCONTROL23 0x2d
|
||||
#define ES8388_DACCONTROL24 0x2e
|
||||
#define ES8388_DACCONTROL25 0x2f
|
||||
#define ES8388_DACCONTROL26 0x30
|
||||
#define ES8388_DACCONTROL27 0x31
|
||||
#define ES8388_DACCONTROL28 0x32
|
||||
#define ES8388_DACCONTROL29 0x33
|
||||
#define ES8388_DACCONTROL30 0x34
|
||||
|
||||
class ES8388AudioSink : public BufferedAudioSink
|
||||
{
|
||||
public:
|
||||
ES8388AudioSink();
|
||||
~ES8388AudioSink();
|
||||
|
||||
bool begin(int sda = -1, int scl = -1, uint32_t frequency = 400000U);
|
||||
|
||||
enum ES8388_OUT
|
||||
{
|
||||
ES_MAIN, // this is the DAC output volume (both outputs)
|
||||
ES_OUT1, // this is the additional gain for OUT1
|
||||
ES_OUT2 // this is the additional gain for OUT2
|
||||
};
|
||||
|
||||
void mute(const ES8388_OUT out, const bool muted);
|
||||
void volume(const ES8388_OUT out, const uint8_t vol);
|
||||
|
||||
void writeReg(uint8_t reg_add, uint8_t data);
|
||||
private:
|
||||
i2c_config_t i2c_config;
|
||||
i2c_port_t i2c_port = 0;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,22 @@
|
||||
#ifndef ES9018AUDIOSINK_H
|
||||
#define ES9018AUDIOSINK_H
|
||||
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
#include "BufferedAudioSink.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sys/unistd.h>
|
||||
#include <sys/stat.h>
|
||||
#include "esp_err.h"
|
||||
#include "esp_log.h"
|
||||
|
||||
class ES9018AudioSink : public BufferedAudioSink
|
||||
{
|
||||
public:
|
||||
ES9018AudioSink();
|
||||
~ES9018AudioSink();
|
||||
private:
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,22 @@
|
||||
#ifndef INTERNALAUDIOSINK_H
|
||||
#define INTERNALAUDIOSINK_H
|
||||
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
#include "BufferedAudioSink.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sys/unistd.h>
|
||||
#include <sys/stat.h>
|
||||
#include "esp_err.h"
|
||||
#include "esp_log.h"
|
||||
|
||||
class InternalAudioSink : public BufferedAudioSink
|
||||
{
|
||||
public:
|
||||
InternalAudioSink();
|
||||
~InternalAudioSink();
|
||||
private:
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,22 @@
|
||||
#ifndef PCM5102AUDIOSINK_H
|
||||
#define PCM5102AUDIOSINK_H
|
||||
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
#include "BufferedAudioSink.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sys/unistd.h>
|
||||
#include <sys/stat.h>
|
||||
#include "esp_err.h"
|
||||
#include "esp_log.h"
|
||||
|
||||
class PCM5102AudioSink : public BufferedAudioSink
|
||||
{
|
||||
public:
|
||||
PCM5102AudioSink();
|
||||
~PCM5102AudioSink();
|
||||
private:
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,27 @@
|
||||
#ifndef SPDIFAUDIOSINK_H
|
||||
#define SPDIFAUDIOSINK_H
|
||||
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
#include "BufferedAudioSink.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sys/unistd.h>
|
||||
#include <sys/stat.h>
|
||||
#include "esp_err.h"
|
||||
#include "esp_log.h"
|
||||
|
||||
class SPDIFAudioSink : public BufferedAudioSink
|
||||
{
|
||||
private:
|
||||
uint8_t spdifPin;
|
||||
public:
|
||||
explicit SPDIFAudioSink(uint8_t spdifPin);
|
||||
~SPDIFAudioSink() override;
|
||||
void feedPCMFrames(const uint8_t *buffer, size_t bytes) override;
|
||||
void initialize(uint16_t sampleRate);
|
||||
bool setRate(uint16_t sampleRate) override;
|
||||
private:
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,30 @@
|
||||
#ifndef TAS5711AUDIOSINK_H
|
||||
#define TAS5711AUDIOSINK_H
|
||||
|
||||
|
||||
#include "driver/i2s.h"
|
||||
#include <driver/i2c.h>
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
#include "BufferedAudioSink.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sys/unistd.h>
|
||||
#include <sys/stat.h>
|
||||
#include "esp_err.h"
|
||||
#include "esp_log.h"
|
||||
|
||||
class TAS5711AudioSink : public BufferedAudioSink
|
||||
{
|
||||
public:
|
||||
TAS5711AudioSink();
|
||||
~TAS5711AudioSink();
|
||||
|
||||
|
||||
void writeReg(uint8_t reg, uint8_t value);
|
||||
private:
|
||||
i2c_config_t i2c_config;
|
||||
i2c_port_t i2c_port = 0;
|
||||
};
|
||||
|
||||
#endif
|
||||
176
components/spotify/cspot/bell/include/sinks/esp/ac101.h
Normal file
176
components/spotify/cspot/bell/include/sinks/esp/ac101.h
Normal file
@@ -0,0 +1,176 @@
|
||||
/*
|
||||
* ESPRESSIF MIT License
|
||||
*
|
||||
* Copyright (c) 2018 <ESPRESSIF SYSTEMS (SHANGHAI) PTE LTD>
|
||||
*
|
||||
* Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case,
|
||||
* it is free of charge, to any person obtaining a copy of this software and associated
|
||||
* documentation files (the "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished
|
||||
* to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all copies or
|
||||
* substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef __AC101_H__
|
||||
#define __AC101_H__
|
||||
|
||||
#include "esp_types.h"
|
||||
|
||||
#define AC101_ADDR 0x1a /*!< Device address*/
|
||||
|
||||
#define WRITE_BIT I2C_MASTER_WRITE /*!< I2C master write */
|
||||
#define READ_BIT I2C_MASTER_READ /*!< I2C master read */
|
||||
#define ACK_CHECK_EN 0x1 /*!< I2C master will check ack from slave*/
|
||||
#define ACK_CHECK_DIS 0x0 /*!< I2C master will not check ack from slave */
|
||||
#define ACK_VAL 0x0 /*!< I2C ack value */
|
||||
#define NACK_VAL 0x1 /*!< I2C nack value */
|
||||
|
||||
#define CHIP_AUDIO_RS 0x00
|
||||
#define PLL_CTRL1 0x01
|
||||
#define PLL_CTRL2 0x02
|
||||
#define SYSCLK_CTRL 0x03
|
||||
#define MOD_CLK_ENA 0x04
|
||||
#define MOD_RST_CTRL 0x05
|
||||
#define I2S_SR_CTRL 0x06
|
||||
#define I2S1LCK_CTRL 0x10
|
||||
#define I2S1_SDOUT_CTRL 0x11
|
||||
#define I2S1_SDIN_CTRL 0x12
|
||||
#define I2S1_MXR_SRC 0x13
|
||||
#define I2S1_VOL_CTRL1 0x14
|
||||
#define I2S1_VOL_CTRL2 0x15
|
||||
#define I2S1_VOL_CTRL3 0x16
|
||||
#define I2S1_VOL_CTRL4 0x17
|
||||
#define I2S1_MXR_GAIN 0x18
|
||||
#define ADC_DIG_CTRL 0x40
|
||||
#define ADC_VOL_CTRL 0x41
|
||||
#define HMIC_CTRL1 0x44
|
||||
#define HMIC_CTRL2 0x45
|
||||
#define HMIC_STATUS 0x46
|
||||
#define DAC_DIG_CTRL 0x48
|
||||
#define DAC_VOL_CTRL 0x49
|
||||
#define DAC_MXR_SRC 0x4c
|
||||
#define DAC_MXR_GAIN 0x4d
|
||||
#define ADC_ANA_CTRL 0x50
|
||||
#define ADC_SRC 0x51
|
||||
#define ADC_SRCBST_CTRL 0x52
|
||||
#define OMIXER_DACA_CTRL 0x53
|
||||
#define OMIXER_SR 0x54
|
||||
#define OMIXER_BST1_CTRL 0x55
|
||||
#define HPOUT_CTRL 0x56
|
||||
#define SPKOUT_CTRL 0x58
|
||||
#define AC_DAC_DAPCTRL 0xa0
|
||||
#define AC_DAC_DAPHHPFC 0xa1
|
||||
#define AC_DAC_DAPLHPFC 0xa2
|
||||
#define AC_DAC_DAPLHAVC 0xa3
|
||||
#define AC_DAC_DAPLLAVC 0xa4
|
||||
#define AC_DAC_DAPRHAVC 0xa5
|
||||
#define AC_DAC_DAPRLAVC 0xa6
|
||||
#define AC_DAC_DAPHGDEC 0xa7
|
||||
#define AC_DAC_DAPLGDEC 0xa8
|
||||
#define AC_DAC_DAPHGATC 0xa9
|
||||
#define AC_DAC_DAPLGATC 0xaa
|
||||
#define AC_DAC_DAPHETHD 0xab
|
||||
#define AC_DAC_DAPLETHD 0xac
|
||||
#define AC_DAC_DAPHGKPA 0xad
|
||||
#define AC_DAC_DAPLGKPA 0xae
|
||||
#define AC_DAC_DAPHGOPA 0xaf
|
||||
#define AC_DAC_DAPLGOPA 0xb0
|
||||
#define AC_DAC_DAPOPT 0xb1
|
||||
#define DAC_DAP_ENA 0xb5
|
||||
|
||||
typedef enum{
|
||||
SAMPLE_RATE_8000 = 0x0000,
|
||||
SAMPLE_RATE_11052 = 0x1000,
|
||||
SAMPLE_RATE_12000 = 0x2000,
|
||||
SAMPLE_RATE_16000 = 0x3000,
|
||||
SAMPLE_RATE_22050 = 0x4000,
|
||||
SAMPLE_RATE_24000 = 0x5000,
|
||||
SAMPLE_RATE_32000 = 0x6000,
|
||||
SAMPLE_RATE_44100 = 0x7000,
|
||||
SAMPLE_RATE_48000 = 0x8000,
|
||||
SAMPLE_RATE_96000 = 0x9000,
|
||||
SAMPLE_RATE_192000 = 0xa000,
|
||||
} ac_adda_fs_i2s1_t;
|
||||
|
||||
typedef enum{
|
||||
BCLK_DIV_1 = 0x0,
|
||||
BCLK_DIV_2 = 0x1,
|
||||
BCLK_DIV_4 = 0x2,
|
||||
BCLK_DIV_6 = 0x3,
|
||||
BCLK_DIV_8 = 0x4,
|
||||
BCLK_DIV_12 = 0x5,
|
||||
BCLK_DIV_16 = 0x6,
|
||||
BCLK_DIV_24 = 0x7,
|
||||
BCLK_DIV_32 = 0x8,
|
||||
BCLK_DIV_48 = 0x9,
|
||||
BCLK_DIV_64 = 0xa,
|
||||
BCLK_DIV_96 = 0xb,
|
||||
BCLK_DIV_128 = 0xc,
|
||||
BCLK_DIV_192 = 0xd,
|
||||
} ac_i2s1_bclk_div_t;
|
||||
|
||||
typedef enum{
|
||||
LRCK_DIV_16 =0x0,
|
||||
LRCK_DIV_32 =0x1,
|
||||
LRCK_DIV_64 =0x2,
|
||||
LRCK_DIV_128 =0x3,
|
||||
LRCK_DIV_256 =0x4,
|
||||
} ac_i2s1_lrck_div_t;
|
||||
|
||||
typedef enum {
|
||||
BIT_LENGTH_8_BITS = 0x00,
|
||||
BIT_LENGTH_16_BITS = 0x01,
|
||||
BIT_LENGTH_20_BITS = 0x02,
|
||||
BIT_LENGTH_24_BITS = 0x03,
|
||||
} ac_bits_length_t;
|
||||
|
||||
typedef enum {
|
||||
AC_MODE_MIN = -1,
|
||||
AC_MODE_SLAVE = 0x00,
|
||||
AC_MODE_MASTER = 0x01,
|
||||
AC_MODE_MAX,
|
||||
} ac_mode_sm_t;
|
||||
|
||||
typedef enum {
|
||||
AC_MODULE_MIN = -1,
|
||||
AC_MODULE_ADC = 0x01,
|
||||
AC_MODULE_DAC = 0x02,
|
||||
AC_MODULE_ADC_DAC = 0x03,
|
||||
AC_MODULE_LINE = 0x04,
|
||||
AC_MODULE_MAX
|
||||
} ac_module_t;
|
||||
|
||||
typedef enum{
|
||||
SRC_MIC1 = 1,
|
||||
SRC_MIC2 = 2,
|
||||
SRC_LINEIN = 3,
|
||||
}ac_output_mixer_source_t;
|
||||
|
||||
typedef enum {
|
||||
GAIN_N45DB = 0,
|
||||
GAIN_N30DB = 1,
|
||||
GAIN_N15DB = 2,
|
||||
GAIN_0DB = 3,
|
||||
GAIN_15DB = 4,
|
||||
GAIN_30DB = 5,
|
||||
GAIN_45DB = 6,
|
||||
GAIN_60DB = 7,
|
||||
} ac_output_mixer_gain_t;
|
||||
|
||||
typedef struct {
|
||||
ac_i2s1_bclk_div_t bclk_div; /*!< bits clock divide */
|
||||
ac_i2s1_lrck_div_t lclk_div; /*!< WS clock divide */
|
||||
} ac_i2s_clock_t;
|
||||
|
||||
#endif
|
||||
28
components/spotify/cspot/bell/include/sinks/esp/adac.h
Normal file
28
components/spotify/cspot/bell/include/sinks/esp/adac.h
Normal file
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Squeezelite for esp32
|
||||
*
|
||||
* (c) Sebastien 2019
|
||||
* Philippe G. 2019, philippe_44@outlook.com
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "driver/i2s.h"
|
||||
|
||||
typedef enum { ADAC_ON = 0, ADAC_STANDBY, ADAC_OFF } adac_power_e;
|
||||
|
||||
struct adac_s {
|
||||
bool (*init)(int i2c_port_num, int i2s_num, i2s_config_t *config);
|
||||
void (*deinit)(void);
|
||||
void (*power)(adac_power_e mode);
|
||||
void (*speaker)(bool active);
|
||||
void (*headset)(bool active);
|
||||
void (*volume)(unsigned left, unsigned right);
|
||||
};
|
||||
|
||||
extern struct adac_s dac_tas57xx;
|
||||
extern struct adac_s dac_a1s;
|
||||
extern struct adac_s dac_external;
|
||||
124
components/spotify/cspot/bell/include/sinks/unix/ALSAAudioSink.h
Normal file
124
components/spotify/cspot/bell/include/sinks/unix/ALSAAudioSink.h
Normal file
@@ -0,0 +1,124 @@
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
#include <fstream>
|
||||
#include "AudioSink.h"
|
||||
#include <alsa/asoundlib.h>
|
||||
#include <stdio.h>
|
||||
#include <Task.h>
|
||||
#include <unistd.h>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
|
||||
#define PCM_DEVICE "default"
|
||||
|
||||
template <typename T, int SIZE>
|
||||
class RingbufferPointer
|
||||
{
|
||||
typedef std::unique_ptr<T> TPointer;
|
||||
|
||||
public:
|
||||
explicit RingbufferPointer()
|
||||
{
|
||||
// create objects
|
||||
for (int i = 0; i < SIZE; i++)
|
||||
{
|
||||
buf_[i] = std::make_unique<T>();
|
||||
}
|
||||
}
|
||||
|
||||
bool push(TPointer &item)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
if (full())
|
||||
return false;
|
||||
|
||||
std::swap(buf_[head_], item);
|
||||
|
||||
if (full_)
|
||||
tail_ = (tail_ + 1) % max_size_;
|
||||
|
||||
head_ = (head_ + 1) % max_size_;
|
||||
full_ = head_ == tail_;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool pop(TPointer &item)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
if (empty())
|
||||
return false;
|
||||
|
||||
std::swap(buf_[tail_], item);
|
||||
|
||||
full_ = false;
|
||||
tail_ = (tail_ + 1) % max_size_;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void reset()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
head_ = tail_;
|
||||
full_ = false;
|
||||
}
|
||||
|
||||
bool empty() const
|
||||
{
|
||||
return (!full_ && (head_ == tail_));
|
||||
}
|
||||
|
||||
bool full() const
|
||||
{
|
||||
return full_;
|
||||
}
|
||||
|
||||
int capacity() const
|
||||
{
|
||||
return max_size_;
|
||||
}
|
||||
|
||||
int size() const
|
||||
{
|
||||
int size = max_size_;
|
||||
|
||||
if (!full_)
|
||||
{
|
||||
if (head_ >= tail_)
|
||||
size = head_ - tail_;
|
||||
else
|
||||
size = max_size_ + head_ - tail_;
|
||||
}
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
private:
|
||||
TPointer buf_[SIZE];
|
||||
|
||||
std::mutex mutex_;
|
||||
int head_ = 0;
|
||||
int tail_ = 0;
|
||||
const int max_size_ = SIZE;
|
||||
bool full_ = 0;
|
||||
};
|
||||
|
||||
class ALSAAudioSink : public AudioSink, public bell::Task
|
||||
{
|
||||
public:
|
||||
ALSAAudioSink();
|
||||
~ALSAAudioSink();
|
||||
void feedPCMFrames(const uint8_t *buffer, size_t bytes);
|
||||
void runTask();
|
||||
|
||||
private:
|
||||
RingbufferPointer<std::vector<uint8_t>, 3> ringbuffer;
|
||||
unsigned int pcm;
|
||||
snd_pcm_t *pcm_handle;
|
||||
snd_pcm_hw_params_t *params;
|
||||
snd_pcm_uframes_t frames;
|
||||
int buff_size;
|
||||
std::vector<uint8_t> buff;
|
||||
};
|
||||
@@ -0,0 +1,16 @@
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
#include <fstream>
|
||||
#include "AudioSink.h"
|
||||
|
||||
class NamedPipeAudioSink : public AudioSink
|
||||
{
|
||||
public:
|
||||
NamedPipeAudioSink();
|
||||
~NamedPipeAudioSink();
|
||||
void feedPCMFrames(const uint8_t *buffer, size_t bytes);
|
||||
|
||||
private:
|
||||
std::ofstream namedPipeFile;
|
||||
};
|
||||
@@ -0,0 +1,20 @@
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
#include "portaudio.h"
|
||||
#include <stdint.h>
|
||||
#include <iostream>
|
||||
#include "AudioSink.h"
|
||||
|
||||
class PortAudioSink : public AudioSink
|
||||
{
|
||||
public:
|
||||
PortAudioSink();
|
||||
~PortAudioSink();
|
||||
void feedPCMFrames(const uint8_t *buffer, size_t bytes);
|
||||
void initialize(uint16_t sampleRate);
|
||||
bool setRate(uint16_t sampleRate) override;
|
||||
|
||||
private:
|
||||
PaStream *stream;
|
||||
};
|
||||
Reference in New Issue
Block a user