Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
M
miniaudio
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
MyCard
miniaudio
Commits
830d9e6c
Commit
830d9e6c
authored
Dec 31, 2016
by
David Reid
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add s16 -> f32 conversion.
parent
ec6b12e3
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
47 additions
and
6 deletions
+47
-6
mini_al.h
mini_al.h
+47
-6
No files found.
mini_al.h
View file @
830d9e6c
...
@@ -1498,7 +1498,6 @@ static mal_result mal_post_error(mal_device* pDevice, const char* message, mal_r
...
@@ -1498,7 +1498,6 @@ static mal_result mal_post_error(mal_device* pDevice, const char* message, mal_r
}
}
#if 0
// Converts sample data from one format to f32.
// Converts sample data from one format to f32.
static
void
mal_samples_to_f32
(
float
*
pSamplesOut
,
const
void
*
pSamplesIn
,
mal_uint32
sampleCount
,
mal_format
formatIn
)
static
void
mal_samples_to_f32
(
float
*
pSamplesOut
,
const
void
*
pSamplesIn
,
mal_uint32
sampleCount
,
mal_format
formatIn
)
{
{
...
@@ -1517,15 +1516,15 @@ static void mal_samples_to_f32(float* pSamplesOut, const void* pSamplesIn, mal_u
...
@@ -1517,15 +1516,15 @@ static void mal_samples_to_f32(float* pSamplesOut, const void* pSamplesIn, mal_u
case
mal_format_s16
:
case
mal_format_s16
:
{
{
mal_int16
*
pSamplesInS16
=
(
mal_int16
*
)
pSamplesIn
;
mal_int16
*
pSamplesInS16
=
(
mal_int16
*
)
pSamplesIn
;
for (size_t i = 0; i < sampleCount; ++i) {
for
(
mal_uint32
i
=
0
;
i
<
sampleCount
;
++
i
)
{
pSamplesOut[i] = (pSamplesInS16[i] / 32767.0f);
mal_uint32
sign
=
(
pSamplesInS16
[
i
]
&
0x8000
)
>>
15
;
pSamplesOut
[
i
]
=
(
pSamplesInS16
[
i
]
/
(
float
)(
32767
+
sign
));
}
}
}
break
;
}
break
;
default:
break
;
default:
break
;
}
}
}
}
#endif
// Converts sample data from f32 to another format.
// Converts sample data from f32 to another format.
static
void
mal_samples_from_f32
(
void
*
pSamplesOut
,
const
float
*
pSamplesIn
,
mal_uint32
sampleCount
,
mal_format
formatOut
)
static
void
mal_samples_from_f32
(
void
*
pSamplesOut
,
const
float
*
pSamplesIn
,
mal_uint32
sampleCount
,
mal_format
formatOut
)
...
@@ -1654,9 +1653,51 @@ static inline void mal_device__send_frames_to_client(mal_device* pDevice, mal_ui
...
@@ -1654,9 +1653,51 @@ static inline void mal_device__send_frames_to_client(mal_device* pDevice, mal_ui
mal_assert
(
frameCount
>
0
);
mal_assert
(
frameCount
>
0
);
mal_assert
(
pSamples
!=
NULL
);
mal_assert
(
pSamples
!=
NULL
);
// Some format conversions are not currently supported.
if
(
pDevice
->
flags
&
(
MAL_DEVICE_FLAG_USING_FOREIGN_CHANNELS
|
MAL_DEVICE_FLAG_USING_FOREIGN_SAMPLE_RATE
))
{
return
;
}
if
(
pDevice
->
flags
&
MAL_DEVICE_FLAG_USING_FOREIGN_FORMAT
)
{
if
(
pDevice
->
format
==
mal_format_u8
||
pDevice
->
format
==
mal_format_s16
||
pDevice
->
format
==
mal_format_s24
||
pDevice
->
format
==
mal_format_s32
)
{
return
;
}
}
mal_recv_proc
onRecv
=
pDevice
->
onRecv
;
mal_recv_proc
onRecv
=
pDevice
->
onRecv
;
if
(
onRecv
)
{
if
(
onRecv
)
{
onRecv
(
pDevice
,
frameCount
,
pSamples
);
if
((
pDevice
->
flags
&
(
MAL_DEVICE_FLAG_USING_FOREIGN_FORMAT
|
MAL_DEVICE_FLAG_USING_FOREIGN_CHANNELS
|
MAL_DEVICE_FLAG_USING_FOREIGN_SAMPLE_RATE
))
==
0
)
{
// Fast path.
onRecv
(
pDevice
,
frameCount
,
pSamples
);
}
else
{
// Slow(er) path. Need to convert before sending to the client.
mal_uint8
scratchBuffer
[
4096
];
mal_uint32
chunkSampleCount
=
sizeof
(
scratchBuffer
)
/
mal_get_sample_size_in_bytes
(
pDevice
->
format
);
mal_uint32
chunkFrameCount
=
chunkSampleCount
/
pDevice
->
channels
;
mal_uint32
framesSent
=
0
;
mal_uint32
framesRemaining
=
frameCount
;
while
(
framesRemaining
>
0
)
{
mal_uint32
framesToSend
=
(
chunkFrameCount
<
framesRemaining
)
?
chunkFrameCount
:
framesRemaining
;
mal_uint32
samplesToSend
=
framesToSend
*
pDevice
->
channels
;
if
(
pDevice
->
flags
&
MAL_DEVICE_FLAG_USING_FOREIGN_FORMAT
)
{
if
(
pDevice
->
format
==
mal_format_f32
)
{
mal_samples_to_f32
((
float
*
)
scratchBuffer
,
(
mal_uint8
*
)
pSamples
+
(
framesSent
*
pDevice
->
internalChannels
*
mal_get_sample_size_in_bytes
(
pDevice
->
internalFormat
)),
samplesToSend
,
pDevice
->
internalFormat
);
}
else
{
// TODO: Implement the rest.
}
}
onRecv
(
pDevice
,
framesToSend
,
scratchBuffer
);
framesRemaining
-=
framesToSend
;
framesSent
+=
framesToSend
;
}
}
}
}
}
}
...
@@ -4581,7 +4622,7 @@ static mal_result mal_device_init__openal(mal_context* pContext, mal_device_type
...
@@ -4581,7 +4622,7 @@ static mal_result mal_device_init__openal(mal_context* pContext, mal_device_type
pDevice
->
openal
.
pContextALC
=
pContextALC
;
pDevice
->
openal
.
pContextALC
=
pContextALC
;
pDevice
->
openal
.
formatAL
=
formatAL
;
pDevice
->
openal
.
formatAL
=
formatAL
;
pDevice
->
openal
.
subBufferSizeInFrames
=
pDevice
->
bufferSizeInFrames
/
pDevice
->
periods
;
pDevice
->
openal
.
subBufferSizeInFrames
=
pDevice
->
bufferSizeInFrames
/
pDevice
->
periods
;
pDevice
->
openal
.
pIntermediaryBuffer
=
(
mal_uint8
*
)
mal_malloc
(
pDevice
->
openal
.
subBufferSizeInFrames
*
channelsAL
*
mal_get_sample_size_in_bytes
(
pDevice
->
f
ormat
));
pDevice
->
openal
.
pIntermediaryBuffer
=
(
mal_uint8
*
)
mal_malloc
(
pDevice
->
openal
.
subBufferSizeInFrames
*
channelsAL
*
mal_get_sample_size_in_bytes
(
pDevice
->
internalF
ormat
));
if
(
pDevice
->
openal
.
pIntermediaryBuffer
==
NULL
)
{
if
(
pDevice
->
openal
.
pIntermediaryBuffer
==
NULL
)
{
mal_device_uninit__openal
(
pDevice
);
mal_device_uninit__openal
(
pDevice
);
return
MAL_OUT_OF_MEMORY
;
return
MAL_OUT_OF_MEMORY
;
...
...
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