Skip to content

Commit

Permalink
Renamed variable for consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisn committed Jan 22, 2024
1 parent 30bec8d commit 567082d
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 81 deletions.
12 changes: 6 additions & 6 deletions src/Options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ Options::Options() :
auto_amplitude_scale_(false),
amplitude_scale_(1.0),
png_compression_level_(-1), // default
raw_samplerate_(0),
raw_sample_rate_(0),
raw_channels_(0)
{
}
Expand Down Expand Up @@ -253,7 +253,7 @@ bool Options::parseCommandLine(int argc, const char* const* argv)
"PNG compression level: 0 (none) to 9 (best), or -1 (default)"
)(
"raw-samplerate",
po::value<int>(&raw_samplerate_),
po::value<int>(&raw_sample_rate_),
"sample rate for raw audio input (Hz)"
)(
"raw-channels",
Expand Down Expand Up @@ -311,9 +311,9 @@ bool Options::parseCommandLine(int argc, const char* const* argv)
has_input_format_ = hasOptionValue(variables_map, "input-format");
has_output_format_ = hasOptionValue(variables_map, "output-format");

bool has_raw_samplerate = hasOptionValue(variables_map, "raw-samplerate");
bool has_raw_channels = hasOptionValue(variables_map, "raw-channels");
bool has_raw_format = hasOptionValue(variables_map, "raw-format");
bool has_raw_sample_rate = hasOptionValue(variables_map, "raw-samplerate");
bool has_raw_channels = hasOptionValue(variables_map, "raw-channels");
bool has_raw_format = hasOptionValue(variables_map, "raw-format");

if (input_filename_.empty() && !has_input_format_) {
reportError("Must specify either input filename or input format");
Expand Down Expand Up @@ -347,7 +347,7 @@ bool Options::parseCommandLine(int argc, const char* const* argv)
}

if (input_format_ == FileFormat::Raw) {
if (!has_raw_samplerate) {
if (!has_raw_sample_rate) {
reportError("Missing --raw-samplerate option");
return false;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Options.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ class Options
int getBarGap() const { return bar_gap_; }
const std::string& getBarStyle() const { return bar_style_; }

int getRawAudioSampleRate() const { return raw_samplerate_; }
int getRawAudioSampleRate() const { return raw_sample_rate_; }
int getRawAudioChannels() const { return raw_channels_; }
const std::string& getRawAudioFormat() const { return raw_format_; }

Expand Down Expand Up @@ -195,7 +195,7 @@ class Options

int png_compression_level_;

int raw_samplerate_;
int raw_sample_rate_;
int raw_channels_;
std::string raw_format_;
};
Expand Down
142 changes: 71 additions & 71 deletions src/SndFileAudioFileReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,77 @@ SndFileAudioFileReader::~SndFileAudioFileReader()

//------------------------------------------------------------------------------

void SndFileAudioFileReader::configure(int channels, int sample_rate, const std::string& format)
{
if (channels <= 0) {
throwError("Invalid number of input channels: must be greater than zero");
}

if (sample_rate <= 0) {
throwError("Invalid input sample rate: must be greater than zero");
}

info_.seekable = 0;
info_.frames = 0;
info_.sections = 0;

info_.channels = channels;
info_.format = SF_FORMAT_RAW;
info_.samplerate = sample_rate;

if (format == "s8") {
info_.format |= SF_FORMAT_PCM_S8;
}
else if (format == "u8") {
info_.format |= SF_FORMAT_PCM_U8;
}
else if (format == "s16le") {
info_.format |= SF_FORMAT_PCM_16;
info_.format |= SF_ENDIAN_LITTLE;
}
else if (format == "s16be") {
info_.format |= SF_FORMAT_PCM_16;
info_.format |= SF_ENDIAN_BIG;
}
else if (format == "s24le") {
info_.format |= SF_FORMAT_PCM_24;
info_.format |= SF_ENDIAN_LITTLE;
}
else if (format == "s24be") {
info_.format |= SF_FORMAT_PCM_24;
info_.format |= SF_ENDIAN_BIG;
}
else if (format == "s32le") {
info_.format |= SF_FORMAT_PCM_32;
info_.format |= SF_ENDIAN_LITTLE;
}
else if (format == "s32be") {
info_.format |= SF_FORMAT_PCM_32;
info_.format |= SF_ENDIAN_BIG;
}
else if (format == "f32le") {
info_.format |= SF_FORMAT_FLOAT;
info_.format |= SF_ENDIAN_LITTLE;
}
else if (format == "f32be") {
info_.format |= SF_FORMAT_FLOAT;
info_.format |= SF_ENDIAN_BIG;
}
else if (format == "f64le") {
info_.format |= SF_FORMAT_DOUBLE;
info_.format |= SF_ENDIAN_LITTLE;
}
else if (format == "f64be") {
info_.format |= SF_FORMAT_DOUBLE;
info_.format |= SF_ENDIAN_BIG;
}
else {
throwError("Unsupported format: %1%", format);
}
}

//------------------------------------------------------------------------------

bool SndFileAudioFileReader::open(const char* input_filename, bool show_info)
{
assert(input_file_ == nullptr);
Expand Down Expand Up @@ -188,74 +259,3 @@ bool SndFileAudioFileReader::run(AudioProcessor& processor)

return success;
}

//------------------------------------------------------------------------------

void SndFileAudioFileReader::configure(int channels, int samplerate, const std::string& format)
{
if (channels <= 0) {
throwError("Invalid number of input channels: must be greater than zero");
}

if (samplerate <= 0) {
throwError("Invalid input sample rate: must be greater than zero");
}

info_.seekable = 0;
info_.frames = 0;
info_.sections = 0;

info_.channels = channels;
info_.format = SF_FORMAT_RAW;
info_.samplerate = samplerate;

if (format == "s8") {
info_.format |= SF_FORMAT_PCM_S8;
}
else if (format == "u8") {
info_.format |= SF_FORMAT_PCM_U8;
}
else if (format == "s16le") {
info_.format |= SF_FORMAT_PCM_16;
info_.format |= SF_ENDIAN_LITTLE;
}
else if (format == "s16be") {
info_.format |= SF_FORMAT_PCM_16;
info_.format |= SF_ENDIAN_BIG;
}
else if (format == "s24le") {
info_.format |= SF_FORMAT_PCM_24;
info_.format |= SF_ENDIAN_LITTLE;
}
else if (format == "s24be") {
info_.format |= SF_FORMAT_PCM_24;
info_.format |= SF_ENDIAN_BIG;
}
else if (format == "s32le") {
info_.format |= SF_FORMAT_PCM_32;
info_.format |= SF_ENDIAN_LITTLE;
}
else if (format == "s32be") {
info_.format |= SF_FORMAT_PCM_32;
info_.format |= SF_ENDIAN_BIG;
}
else if (format == "f32le") {
info_.format |= SF_FORMAT_FLOAT;
info_.format |= SF_ENDIAN_LITTLE;
}
else if (format == "f32be") {
info_.format |= SF_FORMAT_FLOAT;
info_.format |= SF_ENDIAN_BIG;
}
else if (format == "f64le") {
info_.format |= SF_FORMAT_DOUBLE;
info_.format |= SF_ENDIAN_LITTLE;
}
else if (format == "f64be") {
info_.format |= SF_FORMAT_DOUBLE;
info_.format |= SF_ENDIAN_BIG;
}
else {
throwError("Unsupported format: %1%", format);
}
}
4 changes: 2 additions & 2 deletions src/SndFileAudioFileReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ class SndFileAudioFileReader : public AudioFileReader
SndFileAudioFileReader& operator=(const SndFileAudioFileReader&) = delete;

public:
void configure(int channels, int sample_rate, const std::string& format);

virtual bool open(const char* input_filename, bool show_info = true);

virtual bool run(AudioProcessor& processor);

void configure(int channels, int samplerate, const std::string& format);

private:
void close();

Expand Down

0 comments on commit 567082d

Please sign in to comment.