Re: [alsa-devel] Problem with setting period time and buffer time.
Ignacy Kasperowicz wrote:
But what about buffer_time, why can't I set this time ?
The allowed range of values is hardware dependent, like the period time. Use snd_pcm_hw_params_set_buffer_time_near().
Anyway is there a method to play my wave for a specified short time?
Just write the data to the device.
What is the problem?
Regards, Clemens
Just write the data to the device.
What is the problem?
Regards, Clemens
Ok, but when I just write data to the device I don't really know how long it'll be playing. 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.
Thanks for answering Clemens.
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
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 ;)
Everything works, just ignore post above :)
Thanks for help :)
Best regards. Ignacy
participants (2)
-
Clemens Ladisch
-
Ignacy Kasperowicz