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
700d7aa2
Commit
700d7aa2
authored
Mar 17, 2005
by
Warren Dukes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
dynamically allocate a buffer for 0.5s of audio for OS X
git-svn-id:
https://svn.musicpd.org/mpd/trunk@3097
09075e82-0dd4-0310-85a5-a0d7c8717e4f
parent
a8543879
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
13 deletions
+20
-13
audioOutput_osx.c
src/audioOutputs/audioOutput_osx.c
+20
-13
No files found.
src/audioOutputs/audioOutput_osx.c
View file @
700d7aa2
...
...
@@ -26,13 +26,12 @@
#include "../log.h"
#define BUFFER_SIZE 131072
typedef
struct
_OsxData
{
AudioUnit
au
;
pthread_mutex_t
mutex
;
pthread_cond_t
condition
;
char
buffer
[
BUFFER_SIZE
];
char
*
buffer
;
int
bufferSize
;
int
pos
;
int
len
;
int
go
;
...
...
@@ -49,6 +48,8 @@ static OsxData * newOsxData() {
ret
->
len
=
0
;
ret
->
go
=
0
;
ret
->
started
=
0
;
ret
->
buffer
=
NULL
;
ret
->
bufferSize
=
0
;
return
ret
;
}
...
...
@@ -89,6 +90,7 @@ static int osx_initDriver(AudioOutput * audioOutput, ConfigParam * param) {
}
static
void
freeOsxData
(
OsxData
*
od
)
{
if
(
od
->
buffer
)
free
(
od
->
buffer
);
free
(
od
);
}
...
...
@@ -143,7 +145,7 @@ static OSStatus osx_render(void * vdata,
while
((
od
->
go
||
od
->
len
)
&&
bufferSize
)
{
while
(
od
->
go
&&
od
->
len
<
bufferSize
&&
od
->
len
<
BUFFER_SIZE
)
od
->
len
<
od
->
bufferSize
)
{
pthread_cond_signal
(
&
od
->
condition
);
pthread_cond_wait
(
&
od
->
condition
,
&
od
->
mutex
);
...
...
@@ -153,8 +155,8 @@ static OSStatus osx_render(void * vdata,
bufferSize
-=
bytesToCopy
;
od
->
len
-=
bytesToCopy
;
if
(
od
->
pos
+
bytesToCopy
>
BUFFER_SIZE
)
{
int
bytes
=
BUFFER_SIZE
-
od
->
pos
;
if
(
od
->
pos
+
bytesToCopy
>
od
->
bufferSize
)
{
int
bytes
=
od
->
bufferSize
-
od
->
pos
;
memcpy
(
buffer
->
mData
+
curpos
,
od
->
buffer
+
od
->
pos
,
bytes
);
od
->
pos
=
0
;
curpos
+=
bytes
;
...
...
@@ -165,7 +167,7 @@ static OSStatus osx_render(void * vdata,
od
->
pos
+=
bytesToCopy
;
curpos
+=
bytesToCopy
;
if
(
od
->
pos
>=
BUFFER_SIZE
)
od
->
pos
=
0
;
if
(
od
->
pos
>=
od
->
bufferSize
)
od
->
pos
=
0
;
}
buffer
->
mDataByteSize
-=
bufferSize
;
...
...
@@ -240,6 +242,11 @@ static int osx_openDevice(AudioOutput * audioOutput) {
return
-
1
;
}
/* create a buffer of 0.5s */
od
->
bufferSize
=
(
audioFormat
->
sampleRate
>>
1
)
*
(
audioFormat
->
bits
>>
3
)
*
(
audioFormat
->
channels
);
od
->
buffer
=
realloc
(
od
->
buffer
,
od
->
bufferSize
);
od
->
pos
=
0
;
od
->
len
=
0
;
...
...
@@ -266,21 +273,21 @@ static int osx_play(AudioOutput * audioOutput, char * playChunk, int size) {
pthread_mutex_lock
(
&
od
->
mutex
);
curpos
=
od
->
pos
+
od
->
len
;
if
(
curpos
>=
BUFFER_SIZE
)
curpos
-=
BUFFER_SIZE
;
if
(
curpos
>=
od
->
bufferSize
)
curpos
-=
od
->
bufferSize
;
while
(
size
)
{
while
(
od
->
len
>=
BUFFER_SIZE
)
{
while
(
od
->
len
>=
od
->
bufferSize
)
{
pthread_cond_signal
(
&
od
->
condition
);
pthread_cond_wait
(
&
od
->
condition
,
&
od
->
mutex
);
}
bytesToCopy
=
BUFFER_SIZE
-
od
->
len
;
bytesToCopy
=
od
->
bufferSize
-
od
->
len
;
bytesToCopy
=
bytesToCopy
<
size
?
bytesToCopy
:
size
;
size
-=
bytesToCopy
;
od
->
len
+=
bytesToCopy
;
if
(
curpos
+
bytesToCopy
>
BUFFER_SIZE
)
{
int
bytes
=
BUFFER_SIZE
-
curpos
;
if
(
curpos
+
bytesToCopy
>
od
->
bufferSize
)
{
int
bytes
=
od
->
bufferSize
-
curpos
;
memcpy
(
od
->
buffer
+
curpos
,
playChunk
,
bytes
);
curpos
=
0
;
playChunk
+=
bytes
;
...
...
@@ -291,7 +298,7 @@ static int osx_play(AudioOutput * audioOutput, char * playChunk, int size) {
curpos
+=
bytesToCopy
;
playChunk
+=
bytesToCopy
;
if
(
curpos
>=
BUFFER_SIZE
)
curpos
=
0
;
if
(
curpos
>=
od
->
bufferSize
)
curpos
=
0
;
}
pthread_cond_signal
(
&
od
->
condition
);
...
...
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