Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mpd
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Иван Мажукин
mpd
Commits
b7315f83
Commit
b7315f83
authored
Nov 09, 2004
by
Warren Dukes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add a buffer to audio layer, so we only send data to audio devices 32 times per second
git-svn-id:
https://svn.musicpd.org/mpd/trunk@2553
09075e82-0dd4-0310-85a5-a0d7c8717e4f
parent
9b03731c
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
53 additions
and
15 deletions
+53
-15
audio.c
src/audio.c
+53
-13
audioOutput.c
src/audioOutput.c
+0
-2
No files found.
src/audio.c
View file @
b7315f83
...
...
@@ -42,6 +42,10 @@ static mpd_sint8 myAudioDevicesEnabled[AUDIO_MAX_DEVICES];
static
mpd_uint8
audioOpened
=
0
;
static
mpd_sint32
audioBufferSize
=
0
;
static
char
*
audioBuffer
=
NULL
;
static
mpd_sint32
audioBufferPos
=
0
;
void
copyAudioFormat
(
AudioFormat
*
dest
,
AudioFormat
*
src
)
{
if
(
!
src
)
return
;
...
...
@@ -221,6 +225,32 @@ inline void syncAudioDevicesEnabledArrays() {
}
}
static
int
flushAudioBuffer
()
{
int
ret
=
-
1
;
int
i
;
if
(
audioBufferPos
==
0
)
return
0
;
if
(
0
!=
memcmp
(
pdAudioDevicesEnabled
,
myAudioDevicesEnabled
,
AUDIO_MAX_DEVICES
))
{
syncAudioDevicesEnabledArrays
();
}
for
(
i
=
0
;
i
<
audioOutputArraySize
;
i
++
)
{
if
(
!
myAudioDevicesEnabled
[
i
])
continue
;
if
(
0
==
playAudioOutput
(
audioOutputArray
[
i
],
audioBuffer
,
audioBufferPos
))
{
ret
=
0
;
}
}
audioBufferPos
=
0
;
return
ret
;
}
int
openAudioDevice
(
AudioFormat
*
audioFormat
)
{
int
isCurrentFormat
=
isCurrentAudioFormat
(
audioFormat
);
int
ret
=
-
1
;
...
...
@@ -228,8 +258,12 @@ int openAudioDevice(AudioFormat * audioFormat) {
if
(
!
audioOutputArray
)
return
-
1
;
if
(
!
isCurrentFormat
)
{
if
(
!
audioOpened
||
!
isCurrentFormat
)
{
flushAudioBuffer
();
copyAudioFormat
(
&
audio_format
,
audioFormat
);
audioBufferSize
=
(
audio_format
.
bits
/
8
)
*
audio_format
.
channels
;
audioBufferSize
*=
audio_format
.
sampleRate
>>
5
;
audioBuffer
=
realloc
(
audioBuffer
,
audioBufferSize
);
}
syncAudioDevicesEnabledArrays
();
...
...
@@ -252,23 +286,23 @@ int openAudioDevice(AudioFormat * audioFormat) {
}
int
playAudio
(
char
*
playChunk
,
int
size
)
{
int
ret
=
-
1
;
int
i
;
int
send
;
while
(
size
>
0
)
{
send
=
audioBufferSize
-
audioBufferPos
;
send
=
send
<
size
?
send
:
size
;
if
(
0
!=
memcmp
(
pdAudioDevicesEnabled
,
myAudioDevicesEnabled
,
AUDIO_MAX_DEVICES
))
{
syncAudioDevicesEnabledArrays
();
}
memcpy
(
audioBuffer
+
audioBufferPos
,
playChunk
,
send
);
audioBufferPos
+=
send
;
size
-=
send
;
playChunk
+=
send
;
for
(
i
=
0
;
i
<
audioOutputArraySize
;
i
++
)
{
if
(
!
myAudioDevicesEnabled
[
i
])
continue
;
if
(
0
==
playAudioOutput
(
audioOutputArray
[
i
],
playChunk
,
size
))
{
ret
=
0
;
if
(
audioBufferPos
==
audioBufferSize
)
{
if
(
flushAudioBuffer
()
<
0
)
return
-
1
;
}
}
return
ret
;
return
0
;
}
int
isAudioDeviceOpen
()
{
...
...
@@ -278,6 +312,12 @@ int isAudioDeviceOpen() {
void
closeAudioDevice
()
{
int
i
;
flushAudioBuffer
();
free
(
audioBuffer
);
audioBuffer
=
NULL
;
audioBufferSize
=
0
;
for
(
i
=
0
;
i
<
audioOutputArraySize
;
i
++
)
{
closeAudioOutput
(
audioOutputArray
[
i
]);
}
...
...
src/audioOutput.c
View file @
b7315f83
...
...
@@ -160,9 +160,7 @@ int playAudioOutput(AudioOutput * audioOutput, char * playChunk, int size) {
}
blockSignals
();
ret
=
audioOutput
->
playFunc
(
audioOutput
,
playChunk
,
size
);
unblockSignals
();
return
ret
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment