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

Audio writer output is garbled and much smaller than it should be #126

Open
nsdrozario opened this issue Mar 12, 2021 · 1 comment
Open
Milestone

Comments

@nsdrozario
Copy link

nsdrozario commented Mar 12, 2021

Platform: MSYS2 / Clang 11.0.0 on KFR 4.2.0
One of my projects seemed to have odd behavior with audio IO, so I made a test of audio input and output.

#define KFR_ENABLE_WAV 1
#include <kfr/all.hpp>
#include <iostream>
using std::cout;
using namespace kfr;

int main() {

    univector<float> audio;
    univector2d<float> audio_channels;
    audio_reader_wav<float> reader (open_file_for_reading("input.wav"));

    audio_channels = reader.read_channels();

    audio_writer_wav<float> writer(open_file_for_writing("output.wav"), reader.format());
    univector<float> interleaved_audio = interleave(audio_channels);

    if (interleaved_audio.size() == reader.format().length * reader.format().channels) {
        cout << "yes\n";
    }

    writer.write(interleaved_audio.data(), reader.format().length * reader.format().channels);

    return 0;

}

This should just create a file identical output.wav that is identical to input.wav. I included a check to see if the audio that audio_reader_wav read in was correct, and it was since it outputs yes in the if statement, so I know that audio_reader_wav read in the correct amount of data.

My input.wav file was in stereo 44.1khz containing 443161 samples and it is a bit below 4 mb, at about while the size of the audio output I get is only 4 kb, also at stereo 44.1khz but only 506 samples . I don't get why this is happening because I specified the correct size to write in my call to write(), while the output I get is several orders of magnitude below the intended output. What should I do to solve this?

Edit: On closer inspection it seems like the 506 samples of output.wav are the first 506 samples of input.wav.

@nsdrozario
Copy link
Author

I also had similar results with directly putting the univector2d output of read_channels into write_channels as well.

@dancazarin dancazarin added this to the KFR 5 milestone Oct 20, 2022
@dancazarin dancazarin mentioned this issue Oct 13, 2023
@dancazarin dancazarin modified the milestones: KFR 5, KFR 6 Oct 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants