Post discussions on projects you are working on
- Site Admin
- Posts: 4246
- Joined: Fri Jun 10, 2011 8:15 am
- Location: St. Neots
Not sure if this is a clue but
and with this pattern repeating are you walking through the buffer at 8 bits but reading 16 bits each time.
Technical Support Manager
- Advanced User
- Posts: 153
- Joined: Mon Nov 26, 2012 9:16 am
- Location: Netherlands
Nice find I did nog look at it in hex values, it looks like you are right, although I would expect garbage on the 2nd wave checked about 40 of the sin wave values and they all have this pattren.
The OP can this probably confir.
- Posts: 0
- Joined: Wed Jun 01, 2022 5:40 pm
Thank you! Your clue was, in fact, exactly where I went wrong. This is actually my first time using JNA, so I had overlooked the part in the documentation that specified how many bits the offset for the memory pointer is when reading an array (as I incremented the index by 1, the offset would be incremented by 8 bits, not 16 bits).
Now that I know why that is happening and what to do to fix it (increment index by 2 every time instead), I realize that this was exactly what I did in the beginning as a "workaround". Little did I know that it was an actual fix.
Also, I originally had thought that deleting those "wrong values" meant I was essentially cutting the sampling rate in half (getting out 5000 samples instead of 10000 samples), but I simply needed to increment through the buffer array differently than how I increment through the output array. So I am now getting 10000 samples as desired, all of which are values that match the inputted waveform.
Much thanks to you two, Martyn and Benno, for helping me out with this.