mirror of
https://github.com/sle118/squeezelite-esp32.git
synced 2025-12-06 11:36:59 +03:00
124 lines
3.6 KiB
C
124 lines
3.6 KiB
C
/*
|
|
* Squeezelite for esp32
|
|
*
|
|
* (c) Sebastien 2019
|
|
* Philippe G. 2019, philippe_44@outlook.com
|
|
*
|
|
* This program is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
*
|
|
*/
|
|
#include "squeezelite.h"
|
|
|
|
extern struct outputstate output;
|
|
extern struct buffer *outputbuf;
|
|
|
|
#define FRAME_BLOCK MAX_SILENCE_FRAMES
|
|
|
|
#define LOCK mutex_lock(outputbuf->mutex)
|
|
#define UNLOCK mutex_unlock(outputbuf->mutex)
|
|
|
|
extern void output_init_bt(log_level level, char *device, unsigned output_buf_size, char *params,
|
|
unsigned rates[], unsigned rate_delay, unsigned idle);
|
|
extern void output_close_bt(void);
|
|
|
|
extern void output_init_i2s(log_level level, char *device, unsigned output_buf_size, char *params,
|
|
unsigned rates[], unsigned rate_delay, unsigned idle);
|
|
extern bool output_volume_i2s(unsigned left, unsigned right);
|
|
extern void output_close_i2s(void);
|
|
|
|
static log_level loglevel;
|
|
|
|
static bool (*volume_cb)(unsigned left, unsigned right);
|
|
static void (*close_cb)(void);
|
|
|
|
void output_init_embedded(log_level level, char *device, unsigned output_buf_size, char *params,
|
|
unsigned rates[], unsigned rate_delay, unsigned idle) {
|
|
loglevel = level;
|
|
LOG_INFO("init device: %s", device);
|
|
|
|
memset(&output, 0, sizeof(output));
|
|
output_init_common(level, device, output_buf_size, rates, idle);
|
|
output.start_frames = FRAME_BLOCK;
|
|
output.rate_delay = rate_delay;
|
|
|
|
if (strstr(device, "BT ")) {
|
|
LOG_INFO("init Bluetooth");
|
|
close_cb = &output_close_bt;
|
|
output_init_bt(level, device, output_buf_size, params, rates, rate_delay, idle);
|
|
} else {
|
|
LOG_INFO("init I2S");
|
|
close_cb = &output_close_i2s;
|
|
volume_cb = &output_volume_i2s;
|
|
output_init_i2s(level, device, output_buf_size, params, rates, rate_delay, idle);
|
|
}
|
|
|
|
LOG_INFO("init completed.");
|
|
}
|
|
|
|
void output_close_embedded(void) {
|
|
LOG_INFO("close output");
|
|
if (close_cb) (*close_cb)();
|
|
output_close_common();
|
|
}
|
|
|
|
void set_volume(unsigned left, unsigned right) {
|
|
LOG_DEBUG("setting internal gain left: %u right: %u", left, right);
|
|
if (!volume_cb || !(*volume_cb)(left, right)) {
|
|
LOCK;
|
|
output.gainL = left;
|
|
output.gainR = right;
|
|
UNLOCK;
|
|
}
|
|
}
|
|
|
|
bool test_open(const char *device, unsigned rates[], bool userdef_rates) {
|
|
memset(rates, 0, MAX_SUPPORTED_SAMPLERATES * sizeof(unsigned));
|
|
if (!strcmp(device, "BT")) {
|
|
rates[0] = 44100;
|
|
} else {
|
|
unsigned _rates[] = { 96000, 88200, 48000, 44100, 32000, 0 };
|
|
memcpy(rates, _rates, sizeof(_rates));
|
|
}
|
|
return true;
|
|
}
|
|
|
|
char* output_state_str(void){
|
|
output_state state;
|
|
LOCK;
|
|
state = output.state;
|
|
UNLOCK;
|
|
switch (state) {
|
|
case OUTPUT_OFF: return STR(OUTPUT_OFF);
|
|
case OUTPUT_STOPPED: return STR(OUTPUT_STOPPED);
|
|
case OUTPUT_BUFFER: return STR(OUTPUT_BUFFER);
|
|
case OUTPUT_RUNNING: return STR(OUTPUT_RUNNING);
|
|
case OUTPUT_PAUSE_FRAMES: return STR(OUTPUT_PAUSE_FRAMES);
|
|
case OUTPUT_SKIP_FRAMES: return STR(OUTPUT_SKIP_FRAMES);
|
|
case OUTPUT_START_AT: return STR(OUTPUT_START_AT);
|
|
default: return "OUTPUT_UNKNOWN_STATE";
|
|
}
|
|
}
|
|
|
|
bool output_stopped(void) {
|
|
output_state state;
|
|
LOCK;
|
|
state = output.state;
|
|
UNLOCK;
|
|
return state <= OUTPUT_STOPPED;
|
|
}
|
|
|
|
|
|
|
|
|