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

The result is differrent compare to FFmpeg swr_convert #1

Open
cocotyty opened this issue Dec 11, 2022 · 2 comments
Open

The result is differrent compare to FFmpeg swr_convert #1

cocotyty opened this issue Dec 11, 2022 · 2 comments

Comments

@cocotyty
Copy link

For example,if the input sample rate is 16000 and the output sample rate is 48000, the output data size should be 3X input data size.

But the result seems like much less than the expectation.

@cocotyty
Copy link
Author

I'm trying to make gomplerate works with the https://github.com/hajimehoshi/oto and https://github.com/hajimehoshi/go-mp3.

I wrote two helper functions below to convert data between float64 slice and byte slice.

func fromFloat64(data []float64) (buf []byte) {
	n := len(data) * 2
	buf = make([]byte, n)
	for i := 0; i < len(data); i++ {
		v16 := int16(data[i] * (1 << 15))
		v1 := uint8(v16)
		v2 := uint8(v16 >> 8)
		buf[i*2] = v1
		buf[i*2+1] = v2
	}
	return buf
}

func getFloat64(data []byte) []float64 {
	n := len(data) / 2
	buf := make([]float64, n)
	for i := 0; i < n; i++ {
		var v float64
		v16 := int16(data[2*i]) | (int16(data[2*i+1]) << 8)
		v = float64(v16) / (1 << 15)
		buf[i] = v
	}
	return buf
}

@zeozeozeo
Copy link
Owner

zeozeozeo commented Dec 12, 2022

Resampling does not affect speed whatsoever. You should be changing the playback rate of it.
For example, if you want to slow down an audio file by 2 times (but keep the playback sample rate), you should resample it to double the sample rate and then play it back at the original sample rate.

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