mirror of
https://github.com/Lime3DS/Lime3DS.git
synced 2024-11-23 18:19:21 +01:00
Support signed 8bit pcm in cubeb input. Address review
This commit is contained in:
parent
f5b86cff52
commit
9739e2b6fd
@ -49,16 +49,12 @@ void CubebInput::StartSampling(const Frontend::Mic::Parameters& params) {
|
||||
LOG_ERROR(Audio,
|
||||
"Application requested unsupported unsigned pcm format. Falling back to signed");
|
||||
}
|
||||
if (params.sample_size != 16) {
|
||||
LOG_ERROR(Audio,
|
||||
"Application requested unsupported 8 bit pcm format. Falling back to 16 bits");
|
||||
}
|
||||
|
||||
impl->sample_size_in_bytes = params.sample_size / 8;
|
||||
|
||||
parameters = params;
|
||||
is_sampling = true;
|
||||
|
||||
impl->sample_size_in_bytes = 2;
|
||||
|
||||
cubeb_devid input_device = nullptr;
|
||||
cubeb_stream_params input_params;
|
||||
input_params.channels = 1;
|
||||
@ -76,12 +72,14 @@ void CubebInput::StartSampling(const Frontend::Mic::Parameters& params) {
|
||||
nullptr, nullptr, latency_frames, Impl::DataCallback, Impl::StateCallback,
|
||||
impl.get()) != CUBEB_OK) {
|
||||
LOG_CRITICAL(Audio, "Error creating cubeb input stream");
|
||||
is_sampling = false;
|
||||
return;
|
||||
}
|
||||
|
||||
cubeb_stream_start(impl->stream);
|
||||
int ret = cubeb_stream_set_volume(impl->stream, 1.0);
|
||||
if (ret == CUBEB_ERROR_NOT_SUPPORTED) {
|
||||
LOG_WARNING(Audio, "Unabled to set volume for cubeb input");
|
||||
if (cubeb_stream_start(impl->stream) != CUBEB_OK) {
|
||||
LOG_CRITICAL(Audio, "Error starting cubeb input stream");
|
||||
is_sampling = false;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@ -113,8 +111,18 @@ long CubebInput::Impl::DataCallback(cubeb_stream* stream, void* user_data, const
|
||||
return 0;
|
||||
}
|
||||
|
||||
const u8* data = reinterpret_cast<const u8*>(input_buffer);
|
||||
std::vector<u8> samples{data, data + num_frames * impl->sample_size_in_bytes};
|
||||
std::vector<u8> samples{};
|
||||
samples.reserve(num_frames * impl->sample_size_in_bytes);
|
||||
if (impl->sample_size_in_bytes == 1) {
|
||||
// If the sample format is 8bit, then resample back to 8bit before passing back to core
|
||||
const s16* data = reinterpret_cast<const s16*>(input_buffer);
|
||||
std::transform(data, data + num_frames, std::back_inserter(samples),
|
||||
[](s16 sample) { return static_cast<u8>(static_cast<u16>(sample) >> 8); });
|
||||
} else {
|
||||
// Otherwise copy all of the samples to the buffer (which will be treated as s16 by core)
|
||||
const u8* data = reinterpret_cast<const u8*>(input_buffer);
|
||||
samples.insert(samples.begin(), data, data + num_frames * impl->sample_size_in_bytes);
|
||||
}
|
||||
impl->sample_queue->Push(samples);
|
||||
|
||||
// returning less than num_frames here signals cubeb to stop sampling
|
||||
|
@ -4,7 +4,6 @@
|
||||
|
||||
#include <array>
|
||||
#include "core/frontend/mic.h"
|
||||
#include "core/hle/service/mic_u.h"
|
||||
|
||||
namespace Frontend::Mic {
|
||||
|
||||
|
@ -121,7 +121,7 @@ struct MIC_U::Impl {
|
||||
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
|
||||
rb.Push(RESULT_SUCCESS);
|
||||
|
||||
LOG_TRACE(Service_MIC, "MapSharedMem called, size=0x{:X}", size);
|
||||
LOG_TRACE(Service_MIC, "called, size=0x{:X}", size);
|
||||
}
|
||||
|
||||
void UnmapSharedMem(Kernel::HLERequestContext& ctx) {
|
||||
@ -129,7 +129,7 @@ struct MIC_U::Impl {
|
||||
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
|
||||
shared_memory = nullptr;
|
||||
rb.Push(RESULT_SUCCESS);
|
||||
LOG_TRACE(Service_MIC, "UnmapSharedMem called");
|
||||
LOG_TRACE(Service_MIC, "called");
|
||||
}
|
||||
|
||||
void UpdateSharedMemBuffer(u64 userdata, s64 cycles_late) {
|
||||
@ -237,7 +237,7 @@ struct MIC_U::Impl {
|
||||
|
||||
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
|
||||
rb.Push(RESULT_SUCCESS);
|
||||
LOG_TRACE(Service_MIC, "SetGain gain={}", gain);
|
||||
LOG_TRACE(Service_MIC, "gain={}", gain);
|
||||
}
|
||||
|
||||
void GetGain(Kernel::HLERequestContext& ctx) {
|
||||
@ -247,7 +247,7 @@ struct MIC_U::Impl {
|
||||
rb.Push(RESULT_SUCCESS);
|
||||
u8 gain = mic->GetGain();
|
||||
rb.Push<u8>(gain);
|
||||
LOG_TRACE(Service_MIC, "GetGain gain={}", gain);
|
||||
LOG_TRACE(Service_MIC, "gain={}", gain);
|
||||
}
|
||||
|
||||
void SetPower(Kernel::HLERequestContext& ctx) {
|
||||
@ -257,7 +257,7 @@ struct MIC_U::Impl {
|
||||
|
||||
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
|
||||
rb.Push(RESULT_SUCCESS);
|
||||
LOG_TRACE(Service_MIC, "SetPower mic_power={}", power);
|
||||
LOG_TRACE(Service_MIC, "mic_power={}", power);
|
||||
}
|
||||
|
||||
void GetPower(Kernel::HLERequestContext& ctx) {
|
||||
|
@ -5,7 +5,6 @@
|
||||
#include <utility>
|
||||
#include "audio_core/dsp_interface.h"
|
||||
#include "core/core.h"
|
||||
#include "core/frontend/emu_window.h"
|
||||
#include "core/gdbstub/gdbstub.h"
|
||||
#include "core/hle/service/hid/hid.h"
|
||||
#include "core/hle/service/ir/ir_rst.h"
|
||||
|
Loading…
Reference in New Issue
Block a user