* Problem with setting period time and buffer time.
@ 2008-02-18 23:57 Ignacy Kasperowicz
2008-02-19 8:17 ` Clemens Ladisch
0 siblings, 1 reply; 8+ messages in thread
From: Ignacy Kasperowicz @ 2008-02-18 23:57 UTC (permalink / raw)
To: alsa-devel
Hello.
I need to set proper period time for my application. What I need my
code to do is to play sine wave with set frequency and for exact time
of 1/1200 s (something about 834 us). When I try to set period time
for 834 us I've got this error:
Unable to set period time 834 for playback: Invalid argument .
Honestly speaking I've got this error message no matter what value I
try to set).
The same situation take place when I try to set buffer time for
something about 1000us (so one period could fit in my buffer).
The purpose of this program is to generate sine wave for AFSK (audio
frequency-shift keying). I want to play wave for period_time (834us)
then if needed change frequency and play changed wave again for
period_time with phase shifting.
Wave generation with phase shifting for variable frequencies works,
but not with period_time I need.
Could anyone look at source and tell me why I can't set this values?
I placed code with syntax highlighting at: http://pygments.org/demo/606/ .
(Don't look at prepare_message function, it isn't used right now).
Thanks from advice.
Ignacy.
--
################################################
gry świetlicowe drogą do wyższej fazy przemian.
gg:681548 jid: fik@jabbim.pl usecide.net
################################################
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Problem with setting period time and buffer time.
2008-02-18 23:57 Problem with setting period time and buffer time Ignacy Kasperowicz
@ 2008-02-19 8:17 ` Clemens Ladisch
[not found] ` <9673d3ac0802190320gab8bb7ara92a27b7f602d28b@mail.gmail.com>
0 siblings, 1 reply; 8+ messages in thread
From: Clemens Ladisch @ 2008-02-19 8:17 UTC (permalink / raw)
To: Ignacy Kasperowicz; +Cc: alsa-devel
Ignacy Kasperowicz wrote:
> I need to set proper period time for my application. What I need my
> code to do is to play sine wave with set frequency and for exact time
> of 1/1200 s (something about 834 us).
The period time specifies after which interval the sound hardware issues
an interrupt, i.e., after which time your application gets waken up when
it is waiting for the sound buffer to become non-empty. This has
nothing to do with the actual sounds that are being played.
You are not required to write data in period-sized chunks, so you don't
actually need to care about the period time.
> When I try to set period time for 834 us I've got this error:
> Unable to set period time 834 for playback: Invalid argument .
> Honestly speaking I've got this error message no matter what value I
> try to set).
Period (and buffer) times are hardware dependent; you cannot be sure
that any specific value is supported by the sound card.
(And you're calling snd_pcm_hw_params_set_period_time_max() which would
allow the driver to choose any lower value.)
HTH
Clemens
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Problem with setting period time and buffer time.
[not found] ` <9673d3ac0802190320gab8bb7ara92a27b7f602d28b@mail.gmail.com>
@ 2008-02-19 12:41 ` Ignacy Kasperowicz
2008-02-19 12:42 ` Clemens Ladisch
1 sibling, 0 replies; 8+ messages in thread
From: Ignacy Kasperowicz @ 2008-02-19 12:41 UTC (permalink / raw)
To: alsa-devel
Ok, so I misunderstood the idea of a period variable, many thanks for
explanation Clemens.
I've just read that buffer_time also isn't what I think it was ;) It's
a size of the ring buffer of sound card and it's length depends on
hardware, am I right?
So the best way is to depend on default values of hardware?
Anyway is there a method to play my wave for a specified short time?
As I can see using timer interface is the only solution but still
can't google anything useful :( Small example how to apply
timers will be appreciated (I saw example timer.c from alsa-lib, but
I'd prefer to read some explanation how the code works).
Thanks from advance for any replays.
--
################################################
gry świetlicowe drogą do wyższej fazy przemian.
gg:681548 jid: fik@jabbim.pl usecide.net
################################################
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Problem with setting period time and buffer time.
[not found] ` <9673d3ac0802190320gab8bb7ara92a27b7f602d28b@mail.gmail.com>
2008-02-19 12:41 ` Ignacy Kasperowicz
@ 2008-02-19 12:42 ` Clemens Ladisch
2008-02-19 12:49 ` Ignacy Kasperowicz
1 sibling, 1 reply; 8+ messages in thread
From: Clemens Ladisch @ 2008-02-19 12:42 UTC (permalink / raw)
To: Ignacy Kasperowicz; +Cc: alsa-devel
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
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Problem with setting period time and buffer time.
2008-02-19 12:42 ` Clemens Ladisch
@ 2008-02-19 12:49 ` Ignacy Kasperowicz
2008-02-19 14:45 ` Clemens Ladisch
0 siblings, 1 reply; 8+ messages in thread
From: Ignacy Kasperowicz @ 2008-02-19 12:49 UTC (permalink / raw)
To: Clemens Ladisch; +Cc: alsa-devel
> 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.
--
################################################
gry świetlicowe drogą do wyższej fazy przemian.
gg:681548 jid: fik@jabbim.pl usecide.net
################################################
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Problem with setting period time and buffer time.
2008-02-19 12:49 ` Ignacy Kasperowicz
@ 2008-02-19 14:45 ` Clemens Ladisch
2008-02-19 20:19 ` Ignacy Kasperowicz
0 siblings, 1 reply; 8+ messages in thread
From: Clemens Ladisch @ 2008-02-19 14:45 UTC (permalink / raw)
To: Ignacy Kasperowicz; +Cc: alsa-devel
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
_______________________________________________
Alsa-devel mailing list
Alsa-devel@alsa-project.org
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Problem with setting period time and buffer time.
2008-02-19 14:45 ` Clemens Ladisch
@ 2008-02-19 20:19 ` Ignacy Kasperowicz
2008-02-20 0:35 ` Ignacy Kasperowicz
0 siblings, 1 reply; 8+ messages in thread
From: Ignacy Kasperowicz @ 2008-02-19 20:19 UTC (permalink / raw)
To: Clemens Ladisch; +Cc: alsa-devel
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 ;)
--
################################################
gry świetlicowe drogą do wyższej fazy przemian.
gg:681548 jid: fik@jabbim.pl usecide.net
################################################
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Problem with setting period time and buffer time.
2008-02-19 20:19 ` Ignacy Kasperowicz
@ 2008-02-20 0:35 ` Ignacy Kasperowicz
0 siblings, 0 replies; 8+ messages in thread
From: Ignacy Kasperowicz @ 2008-02-20 0:35 UTC (permalink / raw)
To: Clemens Ladisch; +Cc: alsa-devel
Everything works, just ignore post above :)
Thanks for help :)
Best regards.
Ignacy
--
################################################
gry świetlicowe drogą do wyższej fazy przemian.
gg:681548 jid: fik@jabbim.pl usecide.net
################################################
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2008-02-20 0:36 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-02-18 23:57 Problem with setting period time and buffer time Ignacy Kasperowicz
2008-02-19 8:17 ` Clemens Ladisch
[not found] ` <9673d3ac0802190320gab8bb7ara92a27b7f602d28b@mail.gmail.com>
2008-02-19 12:41 ` Ignacy Kasperowicz
2008-02-19 12:42 ` Clemens Ladisch
2008-02-19 12:49 ` Ignacy Kasperowicz
2008-02-19 14:45 ` Clemens Ladisch
2008-02-19 20:19 ` Ignacy Kasperowicz
2008-02-20 0:35 ` Ignacy Kasperowicz
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.