Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable 32-bit floating point format support #38

Open
wants to merge 1 commit into
base: v1
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ endif
DEP_FLAGS += -I$(DEP_PATH)/include
DEP_LDFLAGS += -L$(DEP_PATH)/lib

FFMPEG_FORMATS += --enable-muxer=wav --enable-encoder=pcm_s16le --enable-encoder=pcm_s24le
FFMPEG_FORMATS += --enable-muxer=aiff --enable-encoder=pcm_s16be --enable-encoder=pcm_s24be
FFMPEG_FORMATS += --enable-muxer=wav --enable-encoder=pcm_s16le --enable-encoder=pcm_s24le --enable-encoder=pcm_f32le
FFMPEG_FORMATS += --enable-muxer=aiff --enable-encoder=pcm_s16be --enable-encoder=pcm_s24be --enable-encoder=pcm_f32be
FFMPEG_FORMATS += --enable-libmp3lame --enable-muxer=mp3 --enable-encoder=libmp3lame
# FFMPEG_FORMATS += --enable-libopus --enable-muxer=opus --enable-encoder=libopus
FFMPEG_FORMATS += --enable-muxer=flac --enable-encoder=flac
Expand Down
13 changes: 12 additions & 1 deletion src/Recorder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,11 +178,13 @@ struct Encoder {
if (format == "wav") {
if (depth == 16) audioEncoderName = "pcm_s16le";
else if (depth == 24) audioEncoderName = "pcm_s24le";
else if (depth == 32) audioEncoderName = "pcm_f32le";
else assert(0);
}
else if (format == "aiff") {
if (depth == 16) audioEncoderName = "pcm_s16be";
else if (depth == 24) audioEncoderName = "pcm_s24be";
else if (depth == 32) audioEncoderName = "pcm_f32be";
else assert(0);
}
else if (format == "flac") audioEncoderName = "flac";
Expand Down Expand Up @@ -225,11 +227,13 @@ struct Encoder {
if (format == "wav" || format == "aiff" || format == "flac") {
if (depth == 16) audioCtx->sample_fmt = AV_SAMPLE_FMT_S16;
else if (depth == 24) audioCtx->sample_fmt = AV_SAMPLE_FMT_S32;
else if (depth == 32) audioCtx->sample_fmt = AV_SAMPLE_FMT_FLT;
else assert(0);
}
else if (format == "alac") {
if (depth == 16) audioCtx->sample_fmt = AV_SAMPLE_FMT_S16P;
else if (depth == 24) audioCtx->sample_fmt = AV_SAMPLE_FMT_S32P;
else if (depth == 32) audioCtx->sample_fmt = AV_SAMPLE_FMT_FLTP;
else assert(0);
}
else if (format == "mp3") audioCtx->sample_fmt = AV_SAMPLE_FMT_FLTP;
Expand Down Expand Up @@ -499,6 +503,13 @@ struct Encoder {
output[c][audioFrameSampleIndex] = v;
}
}
else if (audioCtx->sample_fmt == AV_SAMPLE_FMT_FLT) {
float** output = (float**) audioFrame->data;
for (int c = 0; c < audioCtx->channels; c++) {
float v = clamp(input[c], -1.f, 1.f);
output[c][audioFrameSampleIndex * audioCtx->channels + c] = v;
}
}
else if (audioCtx->sample_fmt == AV_SAMPLE_FMT_S16) {
int16_t** output = (int16_t**) audioFrame->data;
for (int c = 0; c < audioCtx->channels; c++) {
Expand Down Expand Up @@ -975,7 +986,7 @@ struct Recorder : Module {
}

std::vector<int> getDepths() {
return {16, 24};
return {16, 24, 32};
}

bool isDepthShown() {
Expand Down