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

Add support for compressed samples #2

Closed
wants to merge 2 commits into from

Conversation

NoobTracker
Copy link
Contributor

@NoobTracker NoobTracker commented Jun 17, 2023

I've implemented sample decompression because I hate my life or something. Sorry for the code quality, I've never really used rust before. Hopefully refactoring this is easier than writing everything from scratch :P
I've also modified how sample values are converted to f32s - previously the i8s and i16s just got divided by their respective MAX constants, but that meant that they were not always within the -1 to 1 range, -128 divided by 127 is < -1. So now they get divided by the MIN constants, *-1. Oh, and it gets rid of the floating point inaccuracies. I think it makes more sense that way, but feel free to disagree.
I've tested the code by loading a module with compressed samples and rendering it using the example code, hope I didn't miss anything.

also changes the conversion from ints to floats slightly
@pr2502
Copy link
Owner

pr2502 commented Jun 20, 2023

Hi, thanks for the contribution!

Would it be possible to add a test for it? If I understand it correctly the compression scheme should be lossless, so in theory it should be possible to add a test that compares an original .wav file to one produced from a compressed .is file created in something like OpenMPT?

@NoobTracker
Copy link
Contributor Author

NoobTracker commented Jun 20, 2023

That sounds like a good idea, considering how messy everything is ^^
And yes, the compression is lossless. I guess I'll just generate some noise and let OpenMPT compress it. The parser doesn't support impulse tracker instrument files, does it?

@pr2502
Copy link
Owner

pr2502 commented Jun 20, 2023

It does! https://docs.rs/ittech/latest/ittech/parser/fn.instrument_file.html will parse an InstumentFile from &[u8], which you can just include_bytes! in the test.

@NoobTracker
Copy link
Contributor Author

NoobTracker commented Jun 20, 2023

Good to know! Test has been added, it decompresses a few KB of noise, both 16 bit and 8 bit, hopefully that catches everything I could've messed up. Not sure if I wrote the test "the proper way", I just copypasta'd your pattern effect test :D
Oh, and there's not really a way to check if a sample was compressed or not without changing the API, right?

@NoobTracker
Copy link
Contributor Author

So yeah I am very bad at using git ... I have just fixed song messages but I have no idea how to create a new PR with just those changes so I guess I'll add them to this PR?

@NoobTracker
Copy link
Contributor Author

NoobTracker commented Jun 22, 2023

Continued in #3 . I'm really sorry. sigh
(in my defense, the pain in my foot caused by a medical operation really doesn't improve my concentration)

@pr2502 pr2502 mentioned this pull request Sep 29, 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

Successfully merging this pull request may close these issues.

None yet

2 participants