I am trying to create some basic sound output (sine frequency modulation basic on an analog input), and in need of some greater understanding of how audio works.
I have a function that fills an array with sine values for a supplied frequency, then I use a FOR loop to write this array to the audio buffer X times.
SOME DETAILS (I can post full/more code if desired)
Sample rate: 48000
Array size: 9600
Frag size: 9600
Frags max: 4
Frags min: 1
Format: SND_PCM_SFMT_S16_LE (16 bit, signed, little endian)
I have looked at the audio output on a scope, and I am getting the desired frequency, so I think I am generating my sine array properly and sending it to audio buffer fine. But, I am not getting the expected duration. For example, if I write the array to the buffer 20 times, I was expecting to hear ~4sec of mono audio (20 * 9600 [samples] / 48000 [samples/sec] = 4 sec), but I am only getting about 1.4sec of sound.
I am having other problems with the sound (eg. ‘beating’ that seems related to buffer writes), but I think understanding this timing issue may help clear up some other things.
Any help, tips, links, knowledge on this timing confusion would be greatly appreciated.