114 lines
No EOL
3.4 KiB
C++
114 lines
No EOL
3.4 KiB
C++
#include "playback_backend.hpp"
|
|
void PlaybackBackend::init(const char *filename, int idx) {
|
|
load(filename);
|
|
switch_stream(idx);
|
|
}
|
|
void PlaybackBackend::load(const char *filename) {}
|
|
void PlaybackBackend::switch_stream(int idx) {}
|
|
void PlaybackBackend::cleanup() { }
|
|
size_t PlaybackBackend::render(void *buf, size_t maxlen) {
|
|
return 0;
|
|
}
|
|
PlaybackBackend::map PlaybackBackend::backends = PlaybackBackend::map();
|
|
std::map<int, audio_data_t> data;
|
|
void init_audio_data() {
|
|
audio_data_t tmp;
|
|
tmp.size = sizeof(float);
|
|
tmp.endian = false;
|
|
tmp.is_float = true;
|
|
tmp.is_signed = true;
|
|
data[AUDIO_F32LSB] = tmp;
|
|
tmp.endian = true;
|
|
data[AUDIO_F32MSB] = tmp;
|
|
tmp.size = sizeof(int32_t);
|
|
tmp.is_float = false;
|
|
data[AUDIO_S32MSB] = tmp;
|
|
tmp.endian = false;
|
|
data[AUDIO_S32LSB] = tmp;
|
|
tmp.size = sizeof(int16_t);
|
|
data[AUDIO_S16LSB] = tmp;
|
|
tmp.endian = true;
|
|
data[AUDIO_S16MSB] = tmp;
|
|
tmp.is_signed = false;
|
|
data[AUDIO_U16MSB] = tmp;
|
|
tmp.endian = false;
|
|
data[AUDIO_U16LSB] = tmp;
|
|
tmp.size = sizeof(uint8_t);
|
|
data[AUDIO_U8] = tmp;
|
|
tmp.is_signed = true;
|
|
data[AUDIO_S8] = tmp;
|
|
}
|
|
size_t size_of_sample_type(int type) {
|
|
return data[type].size;
|
|
}
|
|
#define SAMPLE_TYPE_HAS_ENDIAN(type) (data[type].size > 1)
|
|
bool sample_type_has_endian(int type) {
|
|
return SAMPLE_TYPE_HAS_ENDIAN(type);
|
|
}
|
|
bool sample_type_endian_msb(int type) {
|
|
return SAMPLE_TYPE_HAS_ENDIAN(type) && data[type].endian;
|
|
}
|
|
bool sample_type_endian_lsb(int type) {
|
|
return SAMPLE_TYPE_HAS_ENDIAN(type) && (!data[type].endian);
|
|
}
|
|
bool sample_type_is_float(int type) {
|
|
return data[type].is_float;
|
|
}
|
|
bool sample_type_is_integer(int type) {
|
|
return !data[type].is_float;
|
|
}
|
|
bool sample_type_is_signed(int type) {
|
|
return data[type].is_signed;
|
|
}
|
|
bool sample_type_is_unsigned(int type) {
|
|
return !data[type].is_signed;
|
|
}
|
|
int sample_spec_to_sdl(audio_data_t spec) {
|
|
if (spec.is_float) {
|
|
return spec.endian ? AUDIO_F32MSB : AUDIO_F32LSB;
|
|
} else {
|
|
switch (spec.size) {
|
|
case 1:
|
|
return spec.is_signed ? AUDIO_S8 : AUDIO_U8;
|
|
case 2:
|
|
if (spec.is_signed) {
|
|
return spec.endian ? AUDIO_S16MSB : AUDIO_S16LSB;
|
|
} else {
|
|
return spec.endian ? AUDIO_U16MSB : AUDIO_U16LSB;
|
|
}
|
|
case 4:
|
|
return spec.endian ? AUDIO_S32MSB : AUDIO_S32LSB;
|
|
}
|
|
}
|
|
return 0;
|
|
}
|
|
audio_data_t sdl_to_sample_spec(int type) {
|
|
return data[type];
|
|
}
|
|
std::string sdl_to_str(int type) {
|
|
audio_data_t data = sdl_to_sample_spec(type);
|
|
std::string signed_text[3] = {"Unsigned", "Signed", "Float"};
|
|
char *bit_text_buf = (char*)calloc(8, 1);
|
|
snprintf(bit_text_buf, 8, " %d-bit", (int)(data.size * 8));
|
|
std::string bit_text = bit_text_buf;
|
|
free(bit_text_buf);
|
|
std::string endian_text[2] = {" (Little Endian", " (Big Endian"};
|
|
if (AUDIO_U16SYS == AUDIO_U16LSB) {
|
|
endian_text[0] += ", System";
|
|
} else {
|
|
endian_text[1] += ", System";
|
|
}
|
|
endian_text[0] += ")";
|
|
endian_text[1] += ")";
|
|
if (data.size == 1) {
|
|
return signed_text[data.is_signed ? 1 : 0] + bit_text;
|
|
} else {
|
|
return signed_text[data.is_float ? 2 : data.is_signed ? 1 : 0] + bit_text + endian_text[data.endian ? 1 : 0];
|
|
}
|
|
}
|
|
void PlaybackBackend::deinit_backends() {
|
|
for (auto backend : backends) {
|
|
delete backend.second;
|
|
}
|
|
backends.clear();
|
|
} |