2008/2/19, Clemens Ladisch clemens@ladisch.de:
Ignacy Kasperowicz wrote:
Just write the data to the device.
Ok, but when I just write data to the device I don't really know how long it'll be playing.
But you know how many sample you are writing, and you know the sample rate.
There is no problem when I've infinite loop with writei inside. but I need to change freq of my sound signal with exact 843 us period time.
Assuming a sample rate of 48 kHz, 1/1200 s corresponds to exactly 40 samples. At 44.1 kHz, this would be 36.75 samples, so you'd have to use groups of 37+37+37+36 samples with appropriate phase shifting.
BTW: 1 / 1200 Hz = 833.33... µs
HTH Clemens
Thanks for correction, I was trying to make this too complicated :P I dunno why I even thought about just setting how many samples to write in writei() :P
Although, when from calculations indeed I should set 40 samples to get sine played for 1/1200Hz, in my code I need to set frames size value for 400. Do You know why? I have 48kHz rate, one channel and 16 bit PCM. From what I've read there: https://bugtrack.alsa-project.org/wiki/wikka.php?wakka=FramesPeriods , "A frame is equivalent of one sample being played" so why I need multiply calculation result by 10 ? I think this is a last rookie question :)
Thanks for answers :) ignacy
PS. Yeah I know its 833.33...us, I've just rounded it up for experimenting ;)