Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
Digital Signal Processing Engine Library
Manage
Activity
Members
Labels
Plan
Issues
5
Issue boards
Milestones
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container Registry
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
DSPE
Digital Signal Processing Engine Library
Commits
1c6db70c
Commit
1c6db70c
authored
3 years ago
by
Damian Karaś
Browse files
Options
Downloads
Patches
Plain Diff
ALSA_support: sound recording algorithm v2
Signed-off-by:
Damian Karaś
<
s176030@student.pg.edu.pl
>
parent
f0cb886a
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/cpp/ALSA_support.cpp
+58
-57
58 additions, 57 deletions
src/cpp/ALSA_support.cpp
src/include/ALSA_support.h
+0
-2
0 additions, 2 deletions
src/include/ALSA_support.h
with
58 additions
and
59 deletions
src/cpp/ALSA_support.cpp
+
58
−
57
View file @
1c6db70c
...
...
@@ -43,7 +43,6 @@ DSP::ALSA_object_t::ALSA_object_t()
InDevNo
=
1
;
NextBufferOutInd
=
0
;
NextBufferInInd
=
0
;
/* 44100 bits/second sampling rate (CD quality) */
sampling_rate_alsa
=
44100
;
...
...
@@ -69,6 +68,9 @@ DSP::ALSA_object_t::~ALSA_object_t()
buffers_32bit
.
clear
();
buffers_32bit_f
.
clear
();
buffers_64bit
.
clear
();
capture_buffer
.
clear
();
pcm_buffer
.
clear
();
pcm_buffer_size_in_frames
.
clear
();
...
...
@@ -149,7 +151,7 @@ int DSP::ALSA_object_t::open_alsa_device(snd_pcm_stream_t stream_type)
//! Errors controller in set_snd_pcm_format() function
int
errc
;
//! Local configuration space handler
//! Local configuration space handler
snd_pcm_hw_params_t
*
params
;
//! For logging
...
...
@@ -166,7 +168,7 @@ int DSP::ALSA_object_t::open_alsa_device(snd_pcm_stream_t stream_type)
//! \TODO Test mode: Open mode (see SND_PCM_NONBLOCK, SND_PCM_ASYNC)
if
(
stream_type
==
SND_PCM_STREAM_PLAYBACK
)
if
(
stream_type
==
SND_PCM_STREAM_PLAYBACK
)
DSP
::
log
<<
"Opening PCM device for playback."
<<
endl
;
else
...
...
@@ -396,6 +398,7 @@ int DSP::ALSA_object_t::open_alsa_device(snd_pcm_stream_t stream_type)
{
pcm_buffer
.
resize
(
DSP
::
NoOfAudioOutputBuffers
);
pcm_buffer_size_in_frames
.
resize
(
DSP
::
NoOfAudioOutputBuffers
);
switch
(
no_of_bytes_in_channel
)
{
case
1
:
...
...
@@ -900,63 +903,70 @@ bool DSP::ALSA_object_t::get_wave_in_raw_buffer(DSP::e::SampleType &InSampleType
InSampleType
=
this
->
InSampleTypeALSA
;
snd_pcm_sframes_t
rc
;
wave_in_raw_buffer
.
resize
(
NoOfAudioInputBuffers
);
// one spare buffer
for
(
unsigned
int
ind
=
0
;
ind
<
DSP
::
NoOfAudioInputBuffers
-
1
;
ind
++
)
for
(
unsigned
int
ind
=
0
;
ind
<
pcm_buffer
.
size
();
ind
++
)
{
while
(
pcm_buffer_size_in_frames
[
ind
])
{
rc
=
snd_pcm_readi
(
alsa_handle
,
pcm_buffer
[
ind
],
pcm_buffer_size_in_frames
[
ind
]);
switch
(
-
rc
)
{
case
EPIPE
:
switch
(
-
rc
)
{
case
EPIPE
:
#ifdef AUDIO_DEBUG_MESSAGES_ON
// EPIPE means underrun
DSP
::
log
<<
"Underrun occurred"
<<
endl
;
#endif // AUDIO_DEBUG_MESSAGES_ON
#ifdef AUDIO_DEBUG_MESSAGES_ON
// EPIPE means underrun
DSP
::
log
<<
"Underrun occurred"
<<
endl
;
#endif // AUDIO_DEBUG_MESSAGES_ON
snd_pcm_prepare
(
alsa_handle
);
break
;
snd_pcm_prepare
(
alsa_handle
);
break
;
case
EAGAIN
:
case
EAGAIN
:
#ifdef AUDIO_DEBUG_MESSAGES_ON
DSP
::
log
<<
"EAGAIN occurred. Waiting for a free buffer."
<<
endl
;
#endif // AUDIO_DEBUG_MESSAGES_ON
#ifdef AUDIO_DEBUG_MESSAGES_ON
DSP
::
log
<<
"EAGAIN occurred. Waiting for a free buffer."
<<
endl
;
#endif // AUDIO_DEBUG_MESSAGES_ON
DSP
::
f
::
Sleep
(
0
);
break
;
DSP
::
f
::
Sleep
(
0
);
break
;
default:
if
(
rc
>
0
)
{
pcm_buffer_size_in_frames
[
ind
]
-=
rc
;
pcm_buffer
[
ind
]
+=
rc
*
no_of_channels_alsa
*
no_of_bytes_in_channel
;
#ifdef AUDIO_DEBUG_MESSAGES_ON
DSP
::
log
<<
"Short read. Current rc = "
<<
rc
<<
"."
<<
endl
;
#endif // AUDIO_DEBUG_MESSAGES_ON
wave_in_raw_buffer
.
push_back
(
*
pcm_buffer
[
ind
]);
}
else
{
#ifdef AUDIO_DEBUG_MESSAGES_ON
// EPIPE means underrun
DSP
::
log
<<
"Unsupported error."
<<
endl
;
DSP
::
log
<<
"Error from readi: "
<<
snd_strerror
(
rc
)
<<
endl
;
#endif // AUDIO_DEBUG_MESSAGES_ON
pcm_buffer_size_in_frames
[
ind
]
=
0
;
return
false
;
}
break
;
default:
if
(
rc
>
0
)
{
pcm_buffer_size_in_frames
[
ind
]
-=
rc
;
pcm_buffer
[
ind
]
+=
rc
*
no_of_channels_alsa
*
no_of_bytes_in_channel
;
#ifdef AUDIO_DEBUG_MESSAGES_ON
DSP
::
log
<<
"Short read. Current rc = "
<<
rc
<<
"."
<<
endl
;
#endif // AUDIO_DEBUG_MESSAGES_ON
if
(
pcm_buffer_size_in_frames
[
ind
]
==
0
)
{
std
::
swap
(
wave_in_raw_buffer
,
capture_buffer
);
DSP
::
log
<<
"Inbuffer is full."
<<
endl
;
return
true
;
}
}
else
{
#ifdef AUDIO_DEBUG_MESSAGES_ON
// EPIPE means underrun
DSP
::
log
<<
"Unsupported error."
<<
endl
;
DSP
::
log
<<
"Error from readi: "
<<
snd_strerror
(
rc
)
<<
endl
;
#endif // AUDIO_DEBUG_MESSAGES_ON
pcm_buffer_size_in_frames
[
ind
]
=
0
;
return
false
;
}
break
;
}
}
}
return
true
;
}
snd_pcm_sframes_t
DSP
::
ALSA_object_t
::
pcm_writei
(
const
void
*
buffer
,
const
snd_pcm_uframes_t
&
frames
)
...
...
@@ -1021,15 +1031,6 @@ snd_pcm_sframes_t DSP::ALSA_object_t::pcm_writei(const void *buffer, const snd_p
return
rc
;
}
/*
snd_pcm_sframes_t DSP::ALSA_object_t::pcm_readi(const void *buffer, const snd_pcm_uframes_t &frames)
{
snd_pcm_sframes_t rc;
return rc;
}
*/
void
DSP
::
ALSA_object_t
::
close_alsa_device
(
bool
do_drain
,
bool
use_log
)
{
if
(
alsa_handle
!=
NULL
)
...
...
This diff is collapsed.
Click to expand it.
src/include/ALSA_support.h
+
0
−
2
View file @
1c6db70c
...
...
@@ -37,8 +37,6 @@ namespace DSP {
//! keeping track of which outbuffer is currently being filled
unsigned
int
NextBufferOutInd
;
//! keeping track of which inbuffer is currently being filled
unsigned
int
NextBufferInInd
;
//! sampling rate
unsigned
int
sampling_rate_alsa
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment