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

How to concatenate several wav files? #6

Closed
olebedev opened this issue Apr 26, 2016 · 3 comments
Closed

How to concatenate several wav files? #6

olebedev opened this issue Apr 26, 2016 · 3 comments

Comments

@olebedev
Copy link

I do it in this way:

func concat(files [][]byte) ([]byte, error) {
    if len(files) == 1 {
        return files[0], nil
    }

    r, err := wav.NewReader(bytes.NewReader(files[0]), int64(len(files[0])))
    if err != nil {
        return nil, err
    }

    // create virtual fs
    fs := memfs.Create()
    tmp, err := fs.OpenFile("/tmp.wav", os.O_RDWR|os.O_CREATE, 0777)
    n, err := tmp.Write(files[0]) // hack to expand the capacity, needs for memfs
    if err != nil {
        return nil, err
    }
    if n != len(files[0]) {
        return nil, errors.New("writing failure")
    }

    if err != nil {
        return nil, err
    }
    defer tmp.Close()

    file := r.GetFile()
    w, err := file.NewWriter(tmp)
    if err != nil {
        return nil, err
    }

    writer, _, err := w.GetDumbWriter()
    if err != nil {
        return nil, err
    }

    // copy first file
    firstReader, err := r.GetDumbReader()
    if err != nil {
        return nil, err
    }

    io.Copy(writer, firstReader)
    // only first file, for debugging
    // for _, chunk := range files[1:] {
    // copy others chunks
    // }

    w.Close()
    tmp.Seek(0, os.SEEK_SET)
    b, err := ioutil.ReadAll(tmp)
    return b, err
}

But the headers of files are different. What I am doing wrong? Thanks.


Input file: - https://yadi.sk/d/PJE8hfxRrHnVB
Output file: - https://yadi.sk/d/B8q1PBrTrHnVK

@cryptix
Copy link
Owner

cryptix commented May 7, 2016

Sorry.. I somehow didn't get an email notification for this issue.

I'll look into it and reply once I have an idea.

@cryptix
Copy link
Owner

cryptix commented Jan 4, 2017

Sorry about this falling into oblivion.. Do you still need my insight here or did you solve it already?

@olebedev
Copy link
Author

olebedev commented Jan 5, 2017

Oh, I solved the problem via operating over mp3 files instead. No need more. Thank you.

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