Noise in beginning of alsa application
I have ALSA driver for capture device which works fine with VLC. when I try to capture and render using own application having some issues. Issue is:When I start play, it has some noise in beginning and audio is discontinuous in between. Discontinuous means, some audio frame are getting dropped in between. It looks like cut cut sound for sine wave and it continuous to play. I have tried snd_pcm_drop and snd_pcm_drain but no use.
For rendering audio I'm using aplay.c file as a reference. However, using play.c code I'm getting noise in beginning, to cross check this I have dumped application buffer and then played using aplay utility. Content in application buffer is fine. I have also confirmed with FFPlay application. FFPlay also plays with out noise. aplay reference link , and my audio render is similar to reference link.
Question:
Can you please let me know why there is noise while playing
audio in beginning
audio ubuntu-16.04 alsa pulse-audio
|
show 6 more comments
I have ALSA driver for capture device which works fine with VLC. when I try to capture and render using own application having some issues. Issue is:When I start play, it has some noise in beginning and audio is discontinuous in between. Discontinuous means, some audio frame are getting dropped in between. It looks like cut cut sound for sine wave and it continuous to play. I have tried snd_pcm_drop and snd_pcm_drain but no use.
For rendering audio I'm using aplay.c file as a reference. However, using play.c code I'm getting noise in beginning, to cross check this I have dumped application buffer and then played using aplay utility. Content in application buffer is fine. I have also confirmed with FFPlay application. FFPlay also plays with out noise. aplay reference link , and my audio render is similar to reference link.
Question:
Can you please let me know why there is noise while playing
audio in beginning
audio ubuntu-16.04 alsa pulse-audio
Doesaplay
itself work?
– CL.
Jan 17 at 7:45
@CL, I have dumped audio data to file and then played using aplay with dumped file. aplay is working fine with dumped data in application.
– Chakravarthi Pradeep
Jan 17 at 8:30
So your code is not identical with aplay's. The problem is somewhere in whatever you have coded differently.
– CL.
Jan 17 at 9:04
@CL, i'm sharing my audio render code , which is similar to aplay. github.com/chakripradeep/audiorender/blob/master/…
– Chakravarthi Pradeep
Jan 17 at 9:45
@CL, any ALSA API i'm missing in my code or any ALSA API needs to added to remove the noise in beginning ?
– Chakravarthi Pradeep
Jan 21 at 17:50
|
show 6 more comments
I have ALSA driver for capture device which works fine with VLC. when I try to capture and render using own application having some issues. Issue is:When I start play, it has some noise in beginning and audio is discontinuous in between. Discontinuous means, some audio frame are getting dropped in between. It looks like cut cut sound for sine wave and it continuous to play. I have tried snd_pcm_drop and snd_pcm_drain but no use.
For rendering audio I'm using aplay.c file as a reference. However, using play.c code I'm getting noise in beginning, to cross check this I have dumped application buffer and then played using aplay utility. Content in application buffer is fine. I have also confirmed with FFPlay application. FFPlay also plays with out noise. aplay reference link , and my audio render is similar to reference link.
Question:
Can you please let me know why there is noise while playing
audio in beginning
audio ubuntu-16.04 alsa pulse-audio
I have ALSA driver for capture device which works fine with VLC. when I try to capture and render using own application having some issues. Issue is:When I start play, it has some noise in beginning and audio is discontinuous in between. Discontinuous means, some audio frame are getting dropped in between. It looks like cut cut sound for sine wave and it continuous to play. I have tried snd_pcm_drop and snd_pcm_drain but no use.
For rendering audio I'm using aplay.c file as a reference. However, using play.c code I'm getting noise in beginning, to cross check this I have dumped application buffer and then played using aplay utility. Content in application buffer is fine. I have also confirmed with FFPlay application. FFPlay also plays with out noise. aplay reference link , and my audio render is similar to reference link.
Question:
Can you please let me know why there is noise while playing
audio in beginning
audio ubuntu-16.04 alsa pulse-audio
audio ubuntu-16.04 alsa pulse-audio
asked Jan 17 at 4:34
Chakravarthi PradeepChakravarthi Pradeep
215
215
Doesaplay
itself work?
– CL.
Jan 17 at 7:45
@CL, I have dumped audio data to file and then played using aplay with dumped file. aplay is working fine with dumped data in application.
– Chakravarthi Pradeep
Jan 17 at 8:30
So your code is not identical with aplay's. The problem is somewhere in whatever you have coded differently.
– CL.
Jan 17 at 9:04
@CL, i'm sharing my audio render code , which is similar to aplay. github.com/chakripradeep/audiorender/blob/master/…
– Chakravarthi Pradeep
Jan 17 at 9:45
@CL, any ALSA API i'm missing in my code or any ALSA API needs to added to remove the noise in beginning ?
– Chakravarthi Pradeep
Jan 21 at 17:50
|
show 6 more comments
Doesaplay
itself work?
– CL.
Jan 17 at 7:45
@CL, I have dumped audio data to file and then played using aplay with dumped file. aplay is working fine with dumped data in application.
– Chakravarthi Pradeep
Jan 17 at 8:30
So your code is not identical with aplay's. The problem is somewhere in whatever you have coded differently.
– CL.
Jan 17 at 9:04
@CL, i'm sharing my audio render code , which is similar to aplay. github.com/chakripradeep/audiorender/blob/master/…
– Chakravarthi Pradeep
Jan 17 at 9:45
@CL, any ALSA API i'm missing in my code or any ALSA API needs to added to remove the noise in beginning ?
– Chakravarthi Pradeep
Jan 21 at 17:50
Does
aplay
itself work?– CL.
Jan 17 at 7:45
Does
aplay
itself work?– CL.
Jan 17 at 7:45
@CL, I have dumped audio data to file and then played using aplay with dumped file. aplay is working fine with dumped data in application.
– Chakravarthi Pradeep
Jan 17 at 8:30
@CL, I have dumped audio data to file and then played using aplay with dumped file. aplay is working fine with dumped data in application.
– Chakravarthi Pradeep
Jan 17 at 8:30
So your code is not identical with aplay's. The problem is somewhere in whatever you have coded differently.
– CL.
Jan 17 at 9:04
So your code is not identical with aplay's. The problem is somewhere in whatever you have coded differently.
– CL.
Jan 17 at 9:04
@CL, i'm sharing my audio render code , which is similar to aplay. github.com/chakripradeep/audiorender/blob/master/…
– Chakravarthi Pradeep
Jan 17 at 9:45
@CL, i'm sharing my audio render code , which is similar to aplay. github.com/chakripradeep/audiorender/blob/master/…
– Chakravarthi Pradeep
Jan 17 at 9:45
@CL, any ALSA API i'm missing in my code or any ALSA API needs to added to remove the noise in beginning ?
– Chakravarthi Pradeep
Jan 21 at 17:50
@CL, any ALSA API i'm missing in my code or any ALSA API needs to added to remove the noise in beginning ?
– Chakravarthi Pradeep
Jan 21 at 17:50
|
show 6 more comments
1 Answer
1
active
oldest
votes
Your code attempts to read from a PCM capture device, (then probably process the data,) and then write the data to a PCM playback device.
At the beginning, when you have read, e.g., 100 samples, and then write 100 samples and start the playback, and then wait for the next 100 samples to be captured, the playback buffer will be completely empty when those next samples are available. And because your code is not infinitely fast, the playback device will then try to play a sample that is not there. This will result in an underrun, or in wrong data (depending on how you have configured the stop threshold).
To ensure that there are enough samples available for playback even while your code is executing, you should capture as much data as possible, and write it to the playback buffer, before you start the playback device. In other words, set the playback device's start threshold to the buffer size.
And there is no reason to change the stop threshold from its default value.
thank you for sharing above information. Information is really good for understanding. I had looked into some of your reference link . I had modified the my reference code to according into want you suggested me "set the playback device's start threshold to the buffer size." for this snd_pcm_sw_params_set_start_threshold(handle, swparams, buffer_size); . There is no sound at output after modifying start threshold to buffer size. Please share your valuable inputs.
– Chakravarthi Pradeep
Jan 22 at 17:38
Does your code actually fill the buffer completely?
– CL.
Jan 22 at 17:49
When I debugged my alsa application, chunk_size is 75 , buffer_size is 19200, count is 75. So when I do snd_pcm_readi and writei count is 75. Perhaps,reason for noise also includes circular buffer handling in application..?
– Chakravarthi Pradeep
Jan 22 at 17:58
So is your loop executed 256 times?
– CL.
Jan 22 at 18:05
Yes. After modifying start threshold there was no sound.
– Chakravarthi Pradeep
Jan 22 at 18:10
|
show 3 more comments
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%2f1395216%2fnoise-in-beginning-of-alsa-application%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
Your code attempts to read from a PCM capture device, (then probably process the data,) and then write the data to a PCM playback device.
At the beginning, when you have read, e.g., 100 samples, and then write 100 samples and start the playback, and then wait for the next 100 samples to be captured, the playback buffer will be completely empty when those next samples are available. And because your code is not infinitely fast, the playback device will then try to play a sample that is not there. This will result in an underrun, or in wrong data (depending on how you have configured the stop threshold).
To ensure that there are enough samples available for playback even while your code is executing, you should capture as much data as possible, and write it to the playback buffer, before you start the playback device. In other words, set the playback device's start threshold to the buffer size.
And there is no reason to change the stop threshold from its default value.
thank you for sharing above information. Information is really good for understanding. I had looked into some of your reference link . I had modified the my reference code to according into want you suggested me "set the playback device's start threshold to the buffer size." for this snd_pcm_sw_params_set_start_threshold(handle, swparams, buffer_size); . There is no sound at output after modifying start threshold to buffer size. Please share your valuable inputs.
– Chakravarthi Pradeep
Jan 22 at 17:38
Does your code actually fill the buffer completely?
– CL.
Jan 22 at 17:49
When I debugged my alsa application, chunk_size is 75 , buffer_size is 19200, count is 75. So when I do snd_pcm_readi and writei count is 75. Perhaps,reason for noise also includes circular buffer handling in application..?
– Chakravarthi Pradeep
Jan 22 at 17:58
So is your loop executed 256 times?
– CL.
Jan 22 at 18:05
Yes. After modifying start threshold there was no sound.
– Chakravarthi Pradeep
Jan 22 at 18:10
|
show 3 more comments
Your code attempts to read from a PCM capture device, (then probably process the data,) and then write the data to a PCM playback device.
At the beginning, when you have read, e.g., 100 samples, and then write 100 samples and start the playback, and then wait for the next 100 samples to be captured, the playback buffer will be completely empty when those next samples are available. And because your code is not infinitely fast, the playback device will then try to play a sample that is not there. This will result in an underrun, or in wrong data (depending on how you have configured the stop threshold).
To ensure that there are enough samples available for playback even while your code is executing, you should capture as much data as possible, and write it to the playback buffer, before you start the playback device. In other words, set the playback device's start threshold to the buffer size.
And there is no reason to change the stop threshold from its default value.
thank you for sharing above information. Information is really good for understanding. I had looked into some of your reference link . I had modified the my reference code to according into want you suggested me "set the playback device's start threshold to the buffer size." for this snd_pcm_sw_params_set_start_threshold(handle, swparams, buffer_size); . There is no sound at output after modifying start threshold to buffer size. Please share your valuable inputs.
– Chakravarthi Pradeep
Jan 22 at 17:38
Does your code actually fill the buffer completely?
– CL.
Jan 22 at 17:49
When I debugged my alsa application, chunk_size is 75 , buffer_size is 19200, count is 75. So when I do snd_pcm_readi and writei count is 75. Perhaps,reason for noise also includes circular buffer handling in application..?
– Chakravarthi Pradeep
Jan 22 at 17:58
So is your loop executed 256 times?
– CL.
Jan 22 at 18:05
Yes. After modifying start threshold there was no sound.
– Chakravarthi Pradeep
Jan 22 at 18:10
|
show 3 more comments
Your code attempts to read from a PCM capture device, (then probably process the data,) and then write the data to a PCM playback device.
At the beginning, when you have read, e.g., 100 samples, and then write 100 samples and start the playback, and then wait for the next 100 samples to be captured, the playback buffer will be completely empty when those next samples are available. And because your code is not infinitely fast, the playback device will then try to play a sample that is not there. This will result in an underrun, or in wrong data (depending on how you have configured the stop threshold).
To ensure that there are enough samples available for playback even while your code is executing, you should capture as much data as possible, and write it to the playback buffer, before you start the playback device. In other words, set the playback device's start threshold to the buffer size.
And there is no reason to change the stop threshold from its default value.
Your code attempts to read from a PCM capture device, (then probably process the data,) and then write the data to a PCM playback device.
At the beginning, when you have read, e.g., 100 samples, and then write 100 samples and start the playback, and then wait for the next 100 samples to be captured, the playback buffer will be completely empty when those next samples are available. And because your code is not infinitely fast, the playback device will then try to play a sample that is not there. This will result in an underrun, or in wrong data (depending on how you have configured the stop threshold).
To ensure that there are enough samples available for playback even while your code is executing, you should capture as much data as possible, and write it to the playback buffer, before you start the playback device. In other words, set the playback device's start threshold to the buffer size.
And there is no reason to change the stop threshold from its default value.
edited Jan 22 at 17:48
answered Jan 22 at 9:19
CL.CL.
1,311910
1,311910
thank you for sharing above information. Information is really good for understanding. I had looked into some of your reference link . I had modified the my reference code to according into want you suggested me "set the playback device's start threshold to the buffer size." for this snd_pcm_sw_params_set_start_threshold(handle, swparams, buffer_size); . There is no sound at output after modifying start threshold to buffer size. Please share your valuable inputs.
– Chakravarthi Pradeep
Jan 22 at 17:38
Does your code actually fill the buffer completely?
– CL.
Jan 22 at 17:49
When I debugged my alsa application, chunk_size is 75 , buffer_size is 19200, count is 75. So when I do snd_pcm_readi and writei count is 75. Perhaps,reason for noise also includes circular buffer handling in application..?
– Chakravarthi Pradeep
Jan 22 at 17:58
So is your loop executed 256 times?
– CL.
Jan 22 at 18:05
Yes. After modifying start threshold there was no sound.
– Chakravarthi Pradeep
Jan 22 at 18:10
|
show 3 more comments
thank you for sharing above information. Information is really good for understanding. I had looked into some of your reference link . I had modified the my reference code to according into want you suggested me "set the playback device's start threshold to the buffer size." for this snd_pcm_sw_params_set_start_threshold(handle, swparams, buffer_size); . There is no sound at output after modifying start threshold to buffer size. Please share your valuable inputs.
– Chakravarthi Pradeep
Jan 22 at 17:38
Does your code actually fill the buffer completely?
– CL.
Jan 22 at 17:49
When I debugged my alsa application, chunk_size is 75 , buffer_size is 19200, count is 75. So when I do snd_pcm_readi and writei count is 75. Perhaps,reason for noise also includes circular buffer handling in application..?
– Chakravarthi Pradeep
Jan 22 at 17:58
So is your loop executed 256 times?
– CL.
Jan 22 at 18:05
Yes. After modifying start threshold there was no sound.
– Chakravarthi Pradeep
Jan 22 at 18:10
thank you for sharing above information. Information is really good for understanding. I had looked into some of your reference link . I had modified the my reference code to according into want you suggested me "set the playback device's start threshold to the buffer size." for this snd_pcm_sw_params_set_start_threshold(handle, swparams, buffer_size); . There is no sound at output after modifying start threshold to buffer size. Please share your valuable inputs.
– Chakravarthi Pradeep
Jan 22 at 17:38
thank you for sharing above information. Information is really good for understanding. I had looked into some of your reference link . I had modified the my reference code to according into want you suggested me "set the playback device's start threshold to the buffer size." for this snd_pcm_sw_params_set_start_threshold(handle, swparams, buffer_size); . There is no sound at output after modifying start threshold to buffer size. Please share your valuable inputs.
– Chakravarthi Pradeep
Jan 22 at 17:38
Does your code actually fill the buffer completely?
– CL.
Jan 22 at 17:49
Does your code actually fill the buffer completely?
– CL.
Jan 22 at 17:49
When I debugged my alsa application, chunk_size is 75 , buffer_size is 19200, count is 75. So when I do snd_pcm_readi and writei count is 75. Perhaps,reason for noise also includes circular buffer handling in application..?
– Chakravarthi Pradeep
Jan 22 at 17:58
When I debugged my alsa application, chunk_size is 75 , buffer_size is 19200, count is 75. So when I do snd_pcm_readi and writei count is 75. Perhaps,reason for noise also includes circular buffer handling in application..?
– Chakravarthi Pradeep
Jan 22 at 17:58
So is your loop executed 256 times?
– CL.
Jan 22 at 18:05
So is your loop executed 256 times?
– CL.
Jan 22 at 18:05
Yes. After modifying start threshold there was no sound.
– Chakravarthi Pradeep
Jan 22 at 18:10
Yes. After modifying start threshold there was no sound.
– Chakravarthi Pradeep
Jan 22 at 18:10
|
show 3 more comments
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%2f1395216%2fnoise-in-beginning-of-alsa-application%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
Does
aplay
itself work?– CL.
Jan 17 at 7:45
@CL, I have dumped audio data to file and then played using aplay with dumped file. aplay is working fine with dumped data in application.
– Chakravarthi Pradeep
Jan 17 at 8:30
So your code is not identical with aplay's. The problem is somewhere in whatever you have coded differently.
– CL.
Jan 17 at 9:04
@CL, i'm sharing my audio render code , which is similar to aplay. github.com/chakripradeep/audiorender/blob/master/…
– Chakravarthi Pradeep
Jan 17 at 9:45
@CL, any ALSA API i'm missing in my code or any ALSA API needs to added to remove the noise in beginning ?
– Chakravarthi Pradeep
Jan 21 at 17:50