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

Reverse Playback #31

Open
salvf opened this issue Jun 8, 2018 · 1 comment
Open

Reverse Playback #31

salvf opened this issue Jun 8, 2018 · 1 comment

Comments

@salvf
Copy link

salvf commented Jun 8, 2018

Hi I would like to know the way to play sound backwards, I tryed to reverse audioBuffer array before to read or write (in UpdateRunner) but it didn´t work, maybe I edited the wrong class

@finnkuusisto
Copy link
Owner

Hi,
Just reversing the byte array will likely produce garbled noise. This is because each sample for each channel is 16 bits, stored as two bytes. Each two bytes are considered together when determining the value of that sample, and just reversing the array thus swaps the order of each pair of bytes, giving a different 16 bit value when combined. Effectively, reversing the array switches the endianness of the data.

For example, consider an array with only one sample in it, consisting of bytes A and B in order. Read in that order they might be (in binary) something like:
A[01010101]B[00001111] -> Sample[0101010100001111]
If you reverse the array though, you get them in order B then A:
B[00001111]A[01010101] -> Sample[0000111101010101]
A completely different value for the same sample.

If you want to reverse the audio then, you'll need to either reverse by pairs of bytes, or modify the order in which bytes are merged when read off of the array.

Does that make sense?

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