Skip to content

Commit

Permalink
overflow fix i guess
Browse files Browse the repository at this point in the history
  • Loading branch information
clrnd committed Mar 18, 2024
1 parent f5cfb78 commit bee61df
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,12 @@ int main(int argc, char* argv[]){

audioFile.printSummary();

int numSamples = audioFile.getNumSamplesPerChannel();
if (!opts.half and numSamples != 64*128) {
int fileSamples = audioFile.getNumSamplesPerChannel();
if (!opts.half and fileSamples != 64*128) {
std::cerr << "File's first channel must have 64*128 = "
<< 64*128 << " samples!" << std::endl;
exit(EXIT_FAILURE);
} else if (opts.half and numSamples != 64*128*2) {
} else if (opts.half and fileSamples != 64*128*2) {
std::cerr << "File's first channel must have 64*256 = "
<< 64*128*2 << " samples!" << std::endl;
exit(EXIT_FAILURE);
Expand All @@ -98,15 +98,9 @@ int main(int argc, char* argv[]){
int max = 1048575;
std::array<int, 64*128> samples;

for (int i = 0; i < numSamples; i++) {
double currentSample;

// if the file has the double amount of samples, skip every other one
if (opts.half) {
currentSample = audioFile.samples[0][i*2];
} else {
currentSample = audioFile.samples[0][i];
}
for (int i = 0; i < 64*128; i++) {
int s = opts.half ? i*2 : i;
double currentSample = audioFile.samples[0][s];

// currentSample is between -1 and 1, normalizing
samples[i] = currentSample*max;
Expand Down

0 comments on commit bee61df

Please sign in to comment.