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
9ed608a4
Commit
9ed608a4
authored
Feb 24, 2019
by
David Reid
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update simple playback example.
parent
08e21aae
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
49 additions
and
42 deletions
+49
-42
README.md
README.md
+15
-13
examples/simple_playback.c
examples/simple_playback.c
+6
-6
mini_al.h
mini_al.h
+16
-11
tests/mal_test_0.vcxproj
tests/mal_test_0.vcxproj
+12
-12
No files found.
README.md
View file @
9ed608a4
...
...
@@ -9,7 +9,7 @@ Features
-
A simple build system.
-
It should Just Work out of the box, without the need to download and install any dependencies.
-
A simple API.
-
Supports
both playback and capture on all backends
.
-
Supports
playback, capture and full-duplex
.
-
Data conversion.
-
Sample format conversion, with optional dithering.
-
Sample rate conversion.
...
...
@@ -74,15 +74,16 @@ Simple Playback Example
#include <stdio.h>
// This is the function that's used for sending more data to the device for playback.
mal_uint32
on_send_frames_to_device
(
mal_device
*
pDevice
,
mal_uint32
frameCount
,
void
*
pSamples
)
void
data_callback
(
mal_device
*
pDevice
,
void
*
pOutput
,
const
void
*
pInput
,
mal_uint32
frameCount
)
{
mal_decoder
*
pDecoder
=
(
mal_decoder
*
)
pDevice
->
pUserData
;
if
(
pDecoder
==
NULL
)
{
return
0
;
return
;
}
return
(
mal_uint32
)
mal_decoder_read_pcm_frames
(
pDecoder
,
frameCount
,
pSamples
);
mal_decoder_read_pcm_frames
(
pDecoder
,
frameCount
,
pOutput
);
(
void
)
pInput
;
}
int
main
(
int
argc
,
char
**
argv
)
...
...
@@ -98,15 +99,16 @@ int main(int argc, char** argv)
return
-
2
;
}
mal_device_config
config
=
mal_device_config_init_playback
(
decoder
.
outputFormat
,
decoder
.
outputChannels
,
decoder
.
outputSampleRate
,
on_send_frames_to_device
,
&
decoder
);
mal_device_config
config
=
mal_device_config_init
(
mal_device_type_playback
);
config
.
playback
.
pDeviceID
=
NULL
;
config
.
playback
.
format
=
decoder
.
outputFormat
;
config
.
playback
.
channels
=
decoder
.
outputChannels
;
config
.
sampleRate
=
decoder
.
outputSampleRate
;
config
.
dataCallback
=
data_callback
;
config
.
pUserData
=
&
decoder
;
mal_device
device
;
if
(
mal_device_init
(
NULL
,
mal_device_type_playback
,
NULL
,
&
config
,
&
device
)
!=
MAL_SUCCESS
)
{
if
(
mal_device_init
(
NULL
,
&
config
,
&
device
)
!=
MAL_SUCCESS
)
{
printf
(
"Failed to open playback device.
\n
"
);
mal_decoder_uninit
(
&
decoder
);
return
-
3
;
...
...
@@ -126,7 +128,7 @@ int main(int argc, char** argv)
mal_decoder_uninit
(
&
decoder
);
return
0
;
}
}
}
```
...
...
examples/simple_playback.c
View file @
9ed608a4
...
...
@@ -10,7 +10,7 @@
#include <stdio.h>
void
on_send_frames_to_device
(
mal_device
*
pDevice
,
void
*
pOutput
,
const
void
*
pInput
,
mal_uint32
frameCount
)
void
data_callback
(
mal_device
*
pDevice
,
void
*
pOutput
,
const
void
*
pInput
,
mal_uint32
frameCount
)
{
mal_decoder
*
pDecoder
=
(
mal_decoder
*
)
pDevice
->
pUserData
;
if
(
pDecoder
==
NULL
)
{
...
...
@@ -40,7 +40,7 @@ int main(int argc, char** argv)
config
.
playback
.
format
=
decoder
.
outputFormat
;
config
.
playback
.
channels
=
decoder
.
outputChannels
;
config
.
sampleRate
=
decoder
.
outputSampleRate
;
config
.
dataCallback
=
on_send_frames_to_device
;
config
.
dataCallback
=
data_callback
;
config
.
pUserData
=
&
decoder
;
mal_device
device
;
...
...
mini_al.h
View file @
9ed608a4
...
...
@@ -50,24 +50,29 @@ of capture.
Playback Example
----------------
mal_uint32 on_send_samples(mal_device* pDevice, mal_uint32 frameCount, void* pSamples
)
void data_callback(mal_device* pDevice, void* pOutput, const void* pInput, mal_uint32 frameCount
)
{
// This callback is set at initialization time and will be called when a playback device needs more
// data. You need to write as many frames as you can to pSamples (but no more than frameCount) and
// then return the number of frames you wrote.
//
// The user data (pDevice->pUserData) is set by mal_device_init().
return (mal_uint32)mal_decoder_read_pcm_frames((mal_decoder*)pDevice->pUserData, frameCount, pSamples
);
mal_decoder* pDecoder = (mal_decoder*)pDevice->pUserData;
if (pDecoder == NULL) {
return;
}
mal_decoder_read_pcm_frames(pDecoder, frameCount, pOutput
);
}
...
mal_device_config config = mal_device_config_init_playback(decoder.outputFormat, decoder.outputChannels, decoder.outputSampleRate, on_send_frames_to_device, &decoder);
mal_device_config config = mal_device_config_init(mal_device_type_playback);
config.playback.pDeviceID = NULL;
config.playback.format = decoder.outputFormat;
config.playback.channels = decoder.outputChannels;
config.sampleRate = decoder.outputSampleRate;
config.dataCallback = data_callback;
config.pUserData = &decoder;
mal_device device;
mal_result result = mal_device_init(NULL, mal_device_type_playback, NULL, &config, &device);
if (result != MAL_SUCCESS) {
return -1;
if (mal_device_init(NULL, &config, &device) != MAL_SUCCESS) {
... An error occurred ...
}
mal_device_start(&device); // The device is sleeping by default so you'll need to start it manually.
tests/mal_test_0.vcxproj
View file @
9ed608a4
...
...
@@ -287,12 +287,12 @@
<ExcludedFromBuild
Condition=
"'$(Configuration)|$(Platform)'=='Release|x64'"
>
true
</ExcludedFromBuild>
</ClCompile>
<ClCompile
Include=
"..\examples\simple_playback.c"
>
<ExcludedFromBuild
Condition=
"'$(Configuration)|$(Platform)'=='Debug|Win32'"
>
tru
e
</ExcludedFromBuild>
<ExcludedFromBuild
Condition=
"'$(Configuration)|$(Platform)'=='Release|Win32'"
>
tru
e
</ExcludedFromBuild>
<ExcludedFromBuild
Condition=
"'$(Configuration)|$(Platform)'=='Debug|ARM'"
>
tru
e
</ExcludedFromBuild>
<ExcludedFromBuild
Condition=
"'$(Configuration)|$(Platform)'=='Release|ARM'"
>
tru
e
</ExcludedFromBuild>
<ExcludedFromBuild
Condition=
"'$(Configuration)|$(Platform)'=='Debug|x64'"
>
tru
e
</ExcludedFromBuild>
<ExcludedFromBuild
Condition=
"'$(Configuration)|$(Platform)'=='Release|x64'"
>
tru
e
</ExcludedFromBuild>
<ExcludedFromBuild
Condition=
"'$(Configuration)|$(Platform)'=='Debug|Win32'"
>
fals
e
</ExcludedFromBuild>
<ExcludedFromBuild
Condition=
"'$(Configuration)|$(Platform)'=='Release|Win32'"
>
fals
e
</ExcludedFromBuild>
<ExcludedFromBuild
Condition=
"'$(Configuration)|$(Platform)'=='Debug|ARM'"
>
fals
e
</ExcludedFromBuild>
<ExcludedFromBuild
Condition=
"'$(Configuration)|$(Platform)'=='Release|ARM'"
>
fals
e
</ExcludedFromBuild>
<ExcludedFromBuild
Condition=
"'$(Configuration)|$(Platform)'=='Debug|x64'"
>
fals
e
</ExcludedFromBuild>
<ExcludedFromBuild
Condition=
"'$(Configuration)|$(Platform)'=='Release|x64'"
>
fals
e
</ExcludedFromBuild>
</ClCompile>
<ClCompile
Include=
"..\research\tests\mal_resampler_test_0.c"
>
<ExcludedFromBuild
Condition=
"'$(Configuration)|$(Platform)'=='Debug|Win32'"
>
true
</ExcludedFromBuild>
...
...
@@ -359,12 +359,12 @@
<ExcludedFromBuild
Condition=
"'$(Configuration)|$(Platform)'=='Release|x64'"
>
true
</ExcludedFromBuild>
</ClCompile>
<ClCompile
Include=
"mal_test_0.c"
>
<ExcludedFromBuild
Condition=
"'$(Configuration)|$(Platform)'=='Debug|Win32'"
>
fals
e
</ExcludedFromBuild>
<ExcludedFromBuild
Condition=
"'$(Configuration)|$(Platform)'=='Debug|ARM'"
>
fals
e
</ExcludedFromBuild>
<ExcludedFromBuild
Condition=
"'$(Configuration)|$(Platform)'=='Release|Win32'"
>
fals
e
</ExcludedFromBuild>
<ExcludedFromBuild
Condition=
"'$(Configuration)|$(Platform)'=='Release|ARM'"
>
fals
e
</ExcludedFromBuild>
<ExcludedFromBuild
Condition=
"'$(Configuration)|$(Platform)'=='Debug|x64'"
>
fals
e
</ExcludedFromBuild>
<ExcludedFromBuild
Condition=
"'$(Configuration)|$(Platform)'=='Release|x64'"
>
fals
e
</ExcludedFromBuild>
<ExcludedFromBuild
Condition=
"'$(Configuration)|$(Platform)'=='Debug|Win32'"
>
tru
e
</ExcludedFromBuild>
<ExcludedFromBuild
Condition=
"'$(Configuration)|$(Platform)'=='Debug|ARM'"
>
tru
e
</ExcludedFromBuild>
<ExcludedFromBuild
Condition=
"'$(Configuration)|$(Platform)'=='Release|Win32'"
>
tru
e
</ExcludedFromBuild>
<ExcludedFromBuild
Condition=
"'$(Configuration)|$(Platform)'=='Release|ARM'"
>
tru
e
</ExcludedFromBuild>
<ExcludedFromBuild
Condition=
"'$(Configuration)|$(Platform)'=='Debug|x64'"
>
tru
e
</ExcludedFromBuild>
<ExcludedFromBuild
Condition=
"'$(Configuration)|$(Platform)'=='Release|x64'"
>
tru
e
</ExcludedFromBuild>
</ClCompile>
<ClCompile
Include=
"mal_test_0.cpp"
>
<ExcludedFromBuild
Condition=
"'$(Configuration)|$(Platform)'=='Debug|Win32'"
>
true
</ExcludedFromBuild>
...
...
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