How to make speaker render silence output for 2 sec in ALSA ( Advanced Linux Sound Architecture)
I want make the audio speaker on a computer silence for 2 sec by writing 0's data to "default" device using ALSA (Advanced Linux Sound Architecture). Below is code snippet.
int val
int size = 24000;
u_char *tmp_buffer = (u_char *)malloc(size);
memset(tmp_buffer,0,size);
if ((val = snd_pcm_writei(pcm_handle, tmp_buffer, size)) == -EPIPE)
{
snd_pcm_prepare(pcm_handle);
}
else if (val < 0)
{
qDebug()<<"ERROR. Can't write to PCM device " << snd_strerror(val);
}
free(tmp_buffer);
With the above code, it render as "chuck chuck .." noise not silence .
How to render silence output to speaker for 2 sec?
linux alsa
add a comment |
I want make the audio speaker on a computer silence for 2 sec by writing 0's data to "default" device using ALSA (Advanced Linux Sound Architecture). Below is code snippet.
int val
int size = 24000;
u_char *tmp_buffer = (u_char *)malloc(size);
memset(tmp_buffer,0,size);
if ((val = snd_pcm_writei(pcm_handle, tmp_buffer, size)) == -EPIPE)
{
snd_pcm_prepare(pcm_handle);
}
else if (val < 0)
{
qDebug()<<"ERROR. Can't write to PCM device " << snd_strerror(val);
}
free(tmp_buffer);
With the above code, it render as "chuck chuck .." noise not silence .
How to render silence output to speaker for 2 sec?
linux alsa
Wouldn't leaving the speaker off and playing nothing be quieter than trying to play what ends up being "white noise"? PS. If you're asking about programming specifically, stackoverflow.com is great
– Xen2050
Feb 15 at 3:22
What are the sample format, rate, and channels?
– CL.
Feb 15 at 7:54
@CL,Sample rate 48000, channel is 2 and format is S16_LE.
– Chakravarthi Pradeep
Feb 15 at 8:47
add a comment |
I want make the audio speaker on a computer silence for 2 sec by writing 0's data to "default" device using ALSA (Advanced Linux Sound Architecture). Below is code snippet.
int val
int size = 24000;
u_char *tmp_buffer = (u_char *)malloc(size);
memset(tmp_buffer,0,size);
if ((val = snd_pcm_writei(pcm_handle, tmp_buffer, size)) == -EPIPE)
{
snd_pcm_prepare(pcm_handle);
}
else if (val < 0)
{
qDebug()<<"ERROR. Can't write to PCM device " << snd_strerror(val);
}
free(tmp_buffer);
With the above code, it render as "chuck chuck .." noise not silence .
How to render silence output to speaker for 2 sec?
linux alsa
I want make the audio speaker on a computer silence for 2 sec by writing 0's data to "default" device using ALSA (Advanced Linux Sound Architecture). Below is code snippet.
int val
int size = 24000;
u_char *tmp_buffer = (u_char *)malloc(size);
memset(tmp_buffer,0,size);
if ((val = snd_pcm_writei(pcm_handle, tmp_buffer, size)) == -EPIPE)
{
snd_pcm_prepare(pcm_handle);
}
else if (val < 0)
{
qDebug()<<"ERROR. Can't write to PCM device " << snd_strerror(val);
}
free(tmp_buffer);
With the above code, it render as "chuck chuck .." noise not silence .
How to render silence output to speaker for 2 sec?
linux alsa
linux alsa
edited Feb 15 at 1:09
JakeGould
32.2k1098141
32.2k1098141
asked Feb 15 at 1:04
Chakravarthi PradeepChakravarthi Pradeep
215
215
Wouldn't leaving the speaker off and playing nothing be quieter than trying to play what ends up being "white noise"? PS. If you're asking about programming specifically, stackoverflow.com is great
– Xen2050
Feb 15 at 3:22
What are the sample format, rate, and channels?
– CL.
Feb 15 at 7:54
@CL,Sample rate 48000, channel is 2 and format is S16_LE.
– Chakravarthi Pradeep
Feb 15 at 8:47
add a comment |
Wouldn't leaving the speaker off and playing nothing be quieter than trying to play what ends up being "white noise"? PS. If you're asking about programming specifically, stackoverflow.com is great
– Xen2050
Feb 15 at 3:22
What are the sample format, rate, and channels?
– CL.
Feb 15 at 7:54
@CL,Sample rate 48000, channel is 2 and format is S16_LE.
– Chakravarthi Pradeep
Feb 15 at 8:47
Wouldn't leaving the speaker off and playing nothing be quieter than trying to play what ends up being "white noise"? PS. If you're asking about programming specifically, stackoverflow.com is great
– Xen2050
Feb 15 at 3:22
Wouldn't leaving the speaker off and playing nothing be quieter than trying to play what ends up being "white noise"? PS. If you're asking about programming specifically, stackoverflow.com is great
– Xen2050
Feb 15 at 3:22
What are the sample format, rate, and channels?
– CL.
Feb 15 at 7:54
What are the sample format, rate, and channels?
– CL.
Feb 15 at 7:54
@CL,Sample rate 48000, channel is 2 and format is S16_LE.
– Chakravarthi Pradeep
Feb 15 at 8:47
@CL,Sample rate 48000, channel is 2 and format is S16_LE.
– Chakravarthi Pradeep
Feb 15 at 8:47
add a comment |
1 Answer
1
active
oldest
votes
With a sample rate of 48000 Hz, two seconds need 96000 frames, so that is the number you need to give to snd_pcm_writei()
.
With four bytes per frame, the size of the temporary buffer must be 384000.
snd_pcm_writei(pcm_handle, tmp_buffer, 384000) for 2 sec this will render silence or noise to speaker...?
– Chakravarthi Pradeep
Feb 16 at 3:00
384000 frames would be wrong.
– CL.
Feb 16 at 9:47
I understand that temp buffer size should be 384000 (48000*2*2*2) but what should be number of frames for snd_pcm_writei?
– Chakravarthi Pradeep
Feb 16 at 10:54
The size of one frame is four bytes.
– CL.
Feb 16 at 16:33
thanks I understood (384000 /4) is number of frames.(pcm_handle, tmp_buffer, 96000)
– Chakravarthi Pradeep
Feb 17 at 9:43
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "3"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1405912%2fhow-to-make-speaker-render-silence-output-for-2-sec-in-alsa-advanced-linux-sou%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
With a sample rate of 48000 Hz, two seconds need 96000 frames, so that is the number you need to give to snd_pcm_writei()
.
With four bytes per frame, the size of the temporary buffer must be 384000.
snd_pcm_writei(pcm_handle, tmp_buffer, 384000) for 2 sec this will render silence or noise to speaker...?
– Chakravarthi Pradeep
Feb 16 at 3:00
384000 frames would be wrong.
– CL.
Feb 16 at 9:47
I understand that temp buffer size should be 384000 (48000*2*2*2) but what should be number of frames for snd_pcm_writei?
– Chakravarthi Pradeep
Feb 16 at 10:54
The size of one frame is four bytes.
– CL.
Feb 16 at 16:33
thanks I understood (384000 /4) is number of frames.(pcm_handle, tmp_buffer, 96000)
– Chakravarthi Pradeep
Feb 17 at 9:43
add a comment |
With a sample rate of 48000 Hz, two seconds need 96000 frames, so that is the number you need to give to snd_pcm_writei()
.
With four bytes per frame, the size of the temporary buffer must be 384000.
snd_pcm_writei(pcm_handle, tmp_buffer, 384000) for 2 sec this will render silence or noise to speaker...?
– Chakravarthi Pradeep
Feb 16 at 3:00
384000 frames would be wrong.
– CL.
Feb 16 at 9:47
I understand that temp buffer size should be 384000 (48000*2*2*2) but what should be number of frames for snd_pcm_writei?
– Chakravarthi Pradeep
Feb 16 at 10:54
The size of one frame is four bytes.
– CL.
Feb 16 at 16:33
thanks I understood (384000 /4) is number of frames.(pcm_handle, tmp_buffer, 96000)
– Chakravarthi Pradeep
Feb 17 at 9:43
add a comment |
With a sample rate of 48000 Hz, two seconds need 96000 frames, so that is the number you need to give to snd_pcm_writei()
.
With four bytes per frame, the size of the temporary buffer must be 384000.
With a sample rate of 48000 Hz, two seconds need 96000 frames, so that is the number you need to give to snd_pcm_writei()
.
With four bytes per frame, the size of the temporary buffer must be 384000.
answered Feb 15 at 10:25
CL.CL.
1,321910
1,321910
snd_pcm_writei(pcm_handle, tmp_buffer, 384000) for 2 sec this will render silence or noise to speaker...?
– Chakravarthi Pradeep
Feb 16 at 3:00
384000 frames would be wrong.
– CL.
Feb 16 at 9:47
I understand that temp buffer size should be 384000 (48000*2*2*2) but what should be number of frames for snd_pcm_writei?
– Chakravarthi Pradeep
Feb 16 at 10:54
The size of one frame is four bytes.
– CL.
Feb 16 at 16:33
thanks I understood (384000 /4) is number of frames.(pcm_handle, tmp_buffer, 96000)
– Chakravarthi Pradeep
Feb 17 at 9:43
add a comment |
snd_pcm_writei(pcm_handle, tmp_buffer, 384000) for 2 sec this will render silence or noise to speaker...?
– Chakravarthi Pradeep
Feb 16 at 3:00
384000 frames would be wrong.
– CL.
Feb 16 at 9:47
I understand that temp buffer size should be 384000 (48000*2*2*2) but what should be number of frames for snd_pcm_writei?
– Chakravarthi Pradeep
Feb 16 at 10:54
The size of one frame is four bytes.
– CL.
Feb 16 at 16:33
thanks I understood (384000 /4) is number of frames.(pcm_handle, tmp_buffer, 96000)
– Chakravarthi Pradeep
Feb 17 at 9:43
snd_pcm_writei(pcm_handle, tmp_buffer, 384000) for 2 sec this will render silence or noise to speaker...?
– Chakravarthi Pradeep
Feb 16 at 3:00
snd_pcm_writei(pcm_handle, tmp_buffer, 384000) for 2 sec this will render silence or noise to speaker...?
– Chakravarthi Pradeep
Feb 16 at 3:00
384000 frames would be wrong.
– CL.
Feb 16 at 9:47
384000 frames would be wrong.
– CL.
Feb 16 at 9:47
I understand that temp buffer size should be 384000 (48000*2*2*2) but what should be number of frames for snd_pcm_writei?
– Chakravarthi Pradeep
Feb 16 at 10:54
I understand that temp buffer size should be 384000 (48000*2*2*2) but what should be number of frames for snd_pcm_writei?
– Chakravarthi Pradeep
Feb 16 at 10:54
The size of one frame is four bytes.
– CL.
Feb 16 at 16:33
The size of one frame is four bytes.
– CL.
Feb 16 at 16:33
thanks I understood (384000 /4) is number of frames.(pcm_handle, tmp_buffer, 96000)
– Chakravarthi Pradeep
Feb 17 at 9:43
thanks I understood (384000 /4) is number of frames.(pcm_handle, tmp_buffer, 96000)
– Chakravarthi Pradeep
Feb 17 at 9:43
add a comment |
Thanks for contributing an answer to Super User!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1405912%2fhow-to-make-speaker-render-silence-output-for-2-sec-in-alsa-advanced-linux-sou%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Wouldn't leaving the speaker off and playing nothing be quieter than trying to play what ends up being "white noise"? PS. If you're asking about programming specifically, stackoverflow.com is great
– Xen2050
Feb 15 at 3:22
What are the sample format, rate, and channels?
– CL.
Feb 15 at 7:54
@CL,Sample rate 48000, channel is 2 and format is S16_LE.
– Chakravarthi Pradeep
Feb 15 at 8:47