Skip to content

Android Visualizer.OnDataCaptureListener #3

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

Open
gsus24 opened this issue Jan 14, 2021 · 2 comments
Open

Android Visualizer.OnDataCaptureListener #3

gsus24 opened this issue Jan 14, 2021 · 2 comments
Labels

Comments

@gsus24
Copy link

gsus24 commented Jan 14, 2021

I try to change audio capture instead with microphone with Visualizer.OnDataCaptureListener
https://developer.android.com/reference/android/media/audiofx/Visualizer.OnDataCaptureListener
The output format is an 8-bit unsigned mono PCM

But how to pass it to addPCM8( unsigned char PCMdata[2][1024])?
https://github.com/projectM-visualizer/projectm/blob/d789acbd3414a3c3b431455f0bc40f287928f4c4/src/libprojectM/PCM.cpp#L222

First: Why need addPCM8() an two dimensional array? Android outputs is one dimensional byte [1024]!

Second: My idea was to wait for next capture byte[] and then call addPCM8() and pass the last two.
Any idea to pass the multi array it to JNIEXPORT and finally call addPCM8()?

@gsus24
Copy link
Author

gsus24 commented Jan 23, 2021

Nobody out there? I get it work by convert to 16bit and pass it to addPCM() like in the example. Its moving to the beat.
It was more try and error, than exactly knowing what i did.

public void jniCalladdPCM(byte bytes[]){

            short[] audioBuffer = new short[512];
            short bufferSize = 512;
            short multi = 2;

            for(int i=0, j=0; i<audioBuffer.length; i++,j+=2){

               audioBuffer[i] = ((short) ((bytes[j] -0x80 & 0xff) | (bytes[j+1] -0x80 << 8)));

            }

            libprojectMJNIWrapper.addPCM(audioBuffer, bufferSize);
        }

I convert the out coming byte[1024] from onWaveFormDataCapture(Visualizer visualizer, byte[] bytes, int i) by putting two bytes together and removing the 8th bit of each of them.

Suggestions for improvement are welcome.

@revmischa
Copy link

If I recall, the 2 dimensions are left/right channels. If your source is mono, I suggest putting the same byte in both channels.

            for(int i=0; i<audioBuffer.length; i+=2){
               audioBuffer[i] = audioBuffer[i+1] = bytes[i];
            }

Something like that perhaps

@kblaschke kblaschke transferred this issue from projectM-visualizer/projectm Feb 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants