Git Product home page Git Product logo

wave's Introduction

Build Status Build status

Libwave

A simple cross platform C++ interface for reading and writing WAVE files.

The WAVE file structure taken for reference is:

alt text

see this for more information

Example

#include <iostream>
#include <system_error>

#include "wave/file.h"

int main() {
  // read file's content
  wave::File read_file;
  wave::Error err = read_file.Open("/home/gvne/test.wav", wave::kIn);
  if (err) {
    std::cout << "Something went wrong in in open" << std::endl;
    return 1;
  }
  std::vector<float> content;
  err = read_file.Read(&content);
  if (err) {
    std::cout << "Something went wrong in read" << std::endl;
    return 2;
  }

  // write that same content to another file
  wave::File write_file;
  err = write_file.Open("/home/gvne/test_write.wav", wave::kOut);
  if (err) {
    std::cout << "Something went wrong in out open" << std::endl;
    return 3;
  }
  write_file.set_sample_rate(read_file.sample_rate());
  write_file.set_bits_per_sample(read_file.bits_per_sample());
  write_file.set_channel_number(read_file.channel_number());

  err = write_file.Write(content);
  if (err) {
    std::cout << "Something went wrong in write" << std::endl;
    return 4;
  }

  return 0;
}

wave's People

Contributors

bx5a avatar gvne avatar herveung avatar m4saka avatar maxmarsc avatar ncatta avatar russell-taylor avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

wave's Issues

wave::File does not support std::move

Using std::move on a wave::File object results in an undefined behavior when calling Read or Write method.

On read the Error Read(uint64_t frame_number, std::vector<float>* output); does not fill the output parameter but returns a kNoError code

Possibly wrong sample rate and bits per sample on Android?

On Android, I recorded a 32 bits 48000hz and stereo wav file with this lib. When I open with the same lib, I get:

V/MultiChannelDiskPlaybackWav.cpp(10681): gonna try to open file path: /storage/emulated/0/Android/data/com.X.flutter_app/files/c677eff2-30cf-4aff-95b9-5d8ed87c8efc.wav
V/MultiChannelDiskPlaybackWav.cpp(10681): file opened successfully
V/MultiChannelDiskPlaybackWav.cpp(10681): sampleRate: 44100
V/MultiChannelDiskPlaybackWav.cpp(10681): mChannelCount: 1
V/MultiChannelDiskPlaybackWav.cpp(10681): bitsPerSample: 16

I saved the file and opened on Linux, I get

48000 Hz
stereo
32bits

File:

c677eff2-30cf-4aff-95b9-5d8ed87c8efc.zip

        std::unique_lock<std::mutex> lk{recordingFileMutex};
        wave::Error error = recordingFile.Open(filePath, wave::kIn);
        if (error==wave::Error::kFailedToOpen) {
            ALOGE(TAG, "failed to open recording");
        } else if (error==wave::Error::kNotOpen) {
            ALOGE(TAG, "not open");
        } else if (error==wave::Error::kReadError) {
            ALOGE(TAG, "kReadError");
        } else if (error==wave::Error::kInvalidFormat) {
            ALOGE(TAG, "kInvalidFormat");
        } else if (error==wave::Error::kInvalidSeek) {
            ALOGE(TAG, "kInvalidSeek");
        } else if (error==wave::Error::kNoError) {
            ALOGV(TAG, "file opened successfully");
        } else {
            ALOGE(TAG, "unknown file open error");
        }

        sampleRate = recordingFile.sample_rate();
        mChannelCount = recordingFile.channel_number();
        bitsPerSample = recordingFile.bits_per_sample();

Missing "close file function"

Hi,

First of all greate work.
Second of all, I found that you are missing fundamental function in case of working with file and it is a "close file" function or maybe I'm missing some point. In that case please correct me. Otherwise, if you could add it that would be greate.

Best Regards.

problem reading utf8 filenames on windows

I'm facing an issue reading waves from filenames containing chinese or other language specific characters. I'm using Visual Studio 2019 on Windows 10.
I made a local branch where I added std::wstring support, which at least solved the issue on my side.
I will now try to make a pull request (never did it before) so that you can review and hopefully merge it to main branch, so that others don't need to invest as much time as I did to find the cause of the issue.

Thanks a lot for the library so far, saved me some time, well done.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.