mirror of
https://github.com/TwilitRealm/dusklight
synced 2026-07-08 20:24:47 -04:00
Audio processing in f32
This commit is contained in:
@@ -67,8 +67,9 @@ void SDLCALL GetNewAudio(
|
||||
}
|
||||
}
|
||||
|
||||
#if 0
|
||||
static std::ofstream outRaw("guh.raw", std::ios_base::out | std::ios_base::binary);
|
||||
static std::ofstream outRawF32("guh.f32.raw", std::ios_base::out | std::ios_base::binary);
|
||||
#endif
|
||||
|
||||
int RenderNewAudioFrame() {
|
||||
JASCriticalSection section;
|
||||
@@ -82,7 +83,9 @@ int RenderNewAudioFrame() {
|
||||
JASAudioThread::snIntCount -= 1;
|
||||
}
|
||||
|
||||
#if 0
|
||||
outRaw.flush();
|
||||
#endif
|
||||
|
||||
return static_cast<u16>(countSubframes) * DSP_SUBFRAME_SIZE;
|
||||
}
|
||||
@@ -93,14 +96,9 @@ void RenderAudioSubframe() {
|
||||
JASDriver::updateDSP();
|
||||
DspRender(subFrame);
|
||||
|
||||
std::array<f32, DSP_SUBFRAME_SIZE> guh = {};
|
||||
for (int i = 0; i < DSP_SUBFRAME_SIZE; i++) {
|
||||
guh[i] = (f32)subFrame[i] / (f32)0x7FFF;
|
||||
}
|
||||
|
||||
#if 0
|
||||
outRaw.write((const char*)subFrame.data(), sizeof(subFrame));
|
||||
outRawF32.write((const char*)guh.data(), sizeof(guh));
|
||||
#endif
|
||||
|
||||
SDL_PutAudioStreamData(PlaybackStream, guh.data(), sizeof(guh));
|
||||
// SDL_PutAudioStreamData(PlaybackStream, subFrame.data(), sizeof(subFrame));
|
||||
SDL_PutAudioStreamData(PlaybackStream, subFrame.data(), sizeof(subFrame));
|
||||
}
|
||||
|
||||
+17
-11
@@ -80,7 +80,7 @@ static void ResetChannel(JASDsp::TChannel& channel, ChannelAuxData& aux) {
|
||||
|
||||
static void MixSubframe(DspSubframe& dst, const DspSubframe& src) {
|
||||
for (int i = 0; i < dst.size(); i++) {
|
||||
dst[i] = static_cast<s16>(dst[i] + src[i]);
|
||||
dst[i] += src[i];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -197,7 +197,7 @@ static void RenderChannel(
|
||||
ResetChannel(channel, channelAux);
|
||||
}
|
||||
|
||||
int wantRead = static_cast<int>(subframe.size() * sizeof(s16));
|
||||
int wantRead = static_cast<int>(subframe.size() * sizeof(subframe[0]));
|
||||
auto read = SDL_GetAudioStreamData(
|
||||
channelAux.resampleStream,
|
||||
subframe.data(),
|
||||
@@ -207,27 +207,33 @@ static void RenderChannel(
|
||||
channel.mIsFinished = true;
|
||||
}
|
||||
|
||||
u16 volume;
|
||||
if (channel.mAutoMixerBeenSet) {
|
||||
volume = channel.mAutoMixerVolume;
|
||||
} else {
|
||||
volume = channel.mOutputChannels[0].mTargetVolume;
|
||||
}
|
||||
f32 ratio = static_cast<f32>(volume) / static_cast<f32>(JASDriver::getChannelLevel_dsp());
|
||||
for (auto& sample : subframe) {
|
||||
u16 volume;
|
||||
if (channel.mAutoMixerBeenSet) {
|
||||
volume = channel.mAutoMixerVolume;
|
||||
} else {
|
||||
volume = channel.mOutputChannels[0].mTargetVolume;
|
||||
}
|
||||
sample = (s16)((s64)sample * volume / JASDriver::getChannelLevel_dsp());
|
||||
sample *= ratio;
|
||||
}
|
||||
}
|
||||
|
||||
void dusk::audio::DspInit() {
|
||||
constexpr SDL_AudioSpec spec = {
|
||||
constexpr SDL_AudioSpec srcSpec = {
|
||||
SDL_AUDIO_S16,
|
||||
1,
|
||||
SampleRate
|
||||
};
|
||||
constexpr SDL_AudioSpec dstSpec = {
|
||||
SDL_AUDIO_F32,
|
||||
1,
|
||||
SampleRate
|
||||
};
|
||||
|
||||
for (int i = 0; i < DSP_CHANNELS; i++) {
|
||||
auto& aux = ChannelAux[i];
|
||||
aux.resampleStream = SDL_CreateAudioStream(&spec, &spec);
|
||||
aux.resampleStream = SDL_CreateAudioStream(&srcSpec, &dstSpec);
|
||||
|
||||
SDL_SetAudioStreamGetCallback(
|
||||
aux.resampleStream,
|
||||
|
||||
@@ -17,7 +17,7 @@ namespace dusk::audio {
|
||||
|
||||
extern ChannelAuxData ChannelAux[DSP_CHANNELS];
|
||||
|
||||
using DspSubframe = std::array<s16, DSP_SUBFRAME_SIZE>;
|
||||
using DspSubframe = std::array<f32, DSP_SUBFRAME_SIZE>;
|
||||
|
||||
void DspInit();
|
||||
void DspRender(DspSubframe& subframe);
|
||||
|
||||
Reference in New Issue
Block a user