I've made a few further changes to my oscillator project.
First off, it's now on github. check it out here: https://github.com/mabersold/kotlin-oscillator-demo
I made some changes to how it's organized. To run it, just run main.kt. The primary logic for playing audio lives in AudioPlayer.kt. The oscillator logic is under the oscillator package. There are four: sine, triangle, square, and sawtooth, all using a base abstract oscillator class. This class could just be an interface at this point, which maybe I'll change later.
More Oscillators
The main change is the aforementioned new oscillators. The good news is, they all produce the waveform I'm expecting. The bad news is that none of them sound quite right, aside from the sine wave. So I'll need to do some further investigation to find out why they sound off. Maybe the sawtooth wave just needs to have a frequency adjustment. I even made a little spreadsheet with my math functions to plot the graphs, which ended up looking like this:
Those look right to me. Not sure why the sound isn't right.
Stereo Panning
It also now accepts a stereo position. I created a method called "putSignal" which accepts a ByteBuffer, a Short (representing the sample) and a panning position value. It uses the panning position value to compute the left and right samples, and puts those into the byte buffer.
My next step is to see if I can improve the sound of the triangle, sawtooth and square waves.
Comments
Post a Comment