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
a321e6a5
Commit
a321e6a5
authored
Feb 25, 2018
by
David Reid
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update the simple playback example.
This makes the multi playback example obsolete and has thus been removed.
parent
25618ab3
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
134 deletions
+20
-134
examples/multi_playback.c
examples/multi_playback.c
+0
-108
examples/simple_playback.c
examples/simple_playback.c
+20
-26
No files found.
examples/multi_playback.c
deleted
100644 → 0
View file @
25618ab3
#define _CRT_SECURE_NO_WARNINGS
// These are implemented at the bottom of this file.
#define STB_VORBIS_HEADER_ONLY
#include "../extras/stb_vorbis.c"
#include "../extras/dr_flac.h"
#include "../extras/dr_wav.h"
#include "../extras/dr_mp3.h"
#define MAL_IMPLEMENTATION
#include "../mini_al.h"
mal_uint32
on_send_frames_to_device
(
mal_device
*
pDevice
,
mal_uint32
frameCount
,
void
*
pFramesOut
)
{
mal_decoder
*
pDecoder
=
(
mal_decoder
*
)
pDevice
->
pUserData
;
if
(
pDecoder
==
NULL
)
{
return
0
;
}
return
(
mal_uint32
)
mal_decoder_read
(
pDecoder
,
frameCount
,
pFramesOut
);
}
int
main
(
int
argc
,
char
**
argv
)
{
if
(
argc
<
2
)
{
printf
(
"No input file."
);
return
-
1
;
}
mal_decoder
decoder
;
mal_result
result
=
mal_decoder_init_file
(
argv
[
1
],
NULL
,
&
decoder
);
if
(
result
!=
MAL_SUCCESS
)
{
return
-
2
;
}
mal_context
context
;
if
(
mal_context_init
(
NULL
,
0
,
NULL
,
&
context
)
!=
MAL_SUCCESS
)
{
printf
(
"Failed to initialize context.
\n
"
);
mal_decoder_uninit
(
&
decoder
);
return
-
3
;
}
mal_device_config
deviceConfig
=
mal_device_config_init_playback
(
decoder
.
outputFormat
,
decoder
.
outputChannels
,
decoder
.
outputSampleRate
,
on_send_frames_to_device
);
mal_copy_memory
(
&
deviceConfig
.
channelMap
,
decoder
.
outputChannelMap
,
sizeof
(
decoder
.
outputChannelMap
));
mal_device
device
;
if
(
mal_device_init
(
&
context
,
mal_device_type_playback
,
NULL
,
&
deviceConfig
,
&
decoder
,
&
device
)
!=
MAL_SUCCESS
)
{
printf
(
"Failed to initialize device.
\n
"
);
mal_context_uninit
(
&
context
);
mal_decoder_uninit
(
&
decoder
);
return
-
4
;
}
if
(
mal_device_start
(
&
device
)
!=
MAL_SUCCESS
)
{
printf
(
"Failed to start playback device.
\n
"
);
mal_device_uninit
(
&
device
);
mal_context_uninit
(
&
context
);
mal_decoder_uninit
(
&
decoder
);
return
-
5
;
}
printf
(
"Press Enter to quit..."
);
getchar
();
mal_device_uninit
(
&
device
);
mal_context_uninit
(
&
context
);
mal_decoder_uninit
(
&
decoder
);
return
0
;
}
#define DR_FLAC_IMPLEMENTATION
#include "../extras/dr_flac.h"
#define DR_WAV_IMPLEMENTATION
#include "../extras/dr_wav.h"
#define DR_MP3_IMPLEMENTATION
#include "../extras/dr_mp3.h"
#if defined(_MSC_VER)
#pragma warning(push)
#pragma warning(disable:4456)
#pragma warning(disable:4457)
#pragma warning(disable:4100)
#pragma warning(disable:4244)
#pragma warning(disable:4701)
#pragma warning(disable:4245)
#endif
#if defined(__GNUC__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-value"
#pragma GCC diagnostic ignored "-Wunused-parameter"
#ifndef __clang__
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
#endif
#endif
#undef STB_VORBIS_HEADER_ONLY
#include "../extras/stb_vorbis.c"
#if defined(_MSC_VER)
#pragma warning(pop)
#endif
#if defined(__GNUC__)
#pragma GCC diagnostic pop
#endif
examples/simple_playback.c
View file @
a321e6a5
#define DR_FLAC_IMPLEMENTATION
#include "../extras/dr_flac.h" // Enables FLAC decoding.
#define DR_MP3_IMPLEMENTATION
#include "../extras/dr_mp3.h" // Enables MP3 decoding.
#define DR_WAV_IMPLEMENTATION
#include "../extras/dr_wav.h" // Enables WAV decoding.
#define MAL_IMPLEMENTATION
#define MAL_IMPLEMENTATION
#include "../mini_al.h"
#include "../mini_al.h"
#define DR_WAV_IMPLEMENTATION
#include "../extras/dr_wav.h"
#include <stdio.h>
#include <stdio.h>
// This is the function that's used for sending more data to the device for playback.
// 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
)
mal_uint32
on_send_frames_to_device
(
mal_device
*
pDevice
,
mal_uint32
frameCount
,
void
*
pSamples
)
{
{
drwav
*
pWav
=
(
drwav
*
)
pDevice
->
pUserData
;
mal_decoder
*
pDecoder
=
(
mal_decoder
*
)
pDevice
->
pUserData
;
if
(
p
Wav
==
NULL
)
{
if
(
p
Decoder
==
NULL
)
{
return
0
;
return
0
;
}
}
return
(
mal_uint32
)
drwav_read_s16
(
pWav
,
frameCount
*
pDevice
->
channels
,
(
mal_int16
*
)
pSamples
)
/
pDevice
->
channels
;
return
(
mal_uint32
)
mal_decoder_read
(
pDecoder
,
frameCount
,
pSamples
)
;
}
}
int
main
(
int
argc
,
char
**
argv
)
int
main
(
int
argc
,
char
**
argv
)
...
@@ -24,43 +28,33 @@ int main(int argc, char** argv)
...
@@ -24,43 +28,33 @@ int main(int argc, char** argv)
return
-
1
;
return
-
1
;
}
}
drwav
wav
;
mal_decoder
decoder
;
if
(
!
drwav_init_file
(
&
wav
,
argv
[
1
]))
{
mal_result
result
=
mal_decoder_init_file
(
argv
[
1
],
NULL
,
&
decoder
);
printf
(
"Not a valid WAV file.
\n
"
);
if
(
result
!=
MAL_SUCCESS
)
{
return
-
2
;
return
-
2
;
}
}
mal_context
context
;
mal_device_config
config
=
mal_device_config_init_playback
(
decoder
.
outputFormat
,
decoder
.
outputChannels
,
decoder
.
outputSampleRate
,
on_send_frames_to_device
);
if
(
mal_context_init
(
NULL
,
0
,
NULL
,
&
context
)
!=
MAL_SUCCESS
)
{
printf
(
"Failed to initialize context.
\n
"
);
drwav_uninit
(
&
wav
);
return
-
3
;
}
mal_device_config
config
=
mal_device_config_init_playback
(
mal_format_s16
,
wav
.
channels
,
wav
.
sampleRate
,
on_send_frames_to_device
);
mal_device
device
;
mal_device
device
;
if
(
mal_device_init
(
&
context
,
mal_device_type_playback
,
NULL
,
&
config
,
&
wav
,
&
device
)
!=
MAL_SUCCESS
)
{
if
(
mal_device_init
(
NULL
,
mal_device_type_playback
,
NULL
,
&
config
,
&
decoder
,
&
device
)
!=
MAL_SUCCESS
)
{
printf
(
"Failed to open playback device.
\n
"
);
printf
(
"Failed to open playback device.
\n
"
);
mal_context_uninit
(
&
context
);
mal_decoder_uninit
(
&
decoder
);
drwav_uninit
(
&
wav
);
return
-
3
;
return
-
4
;
}
}
if
(
mal_device_start
(
&
device
)
!=
MAL_SUCCESS
)
{
if
(
mal_device_start
(
&
device
)
!=
MAL_SUCCESS
)
{
printf
(
"Failed to start playback device.
\n
"
);
printf
(
"Failed to start playback device.
\n
"
);
mal_device_uninit
(
&
device
);
mal_device_uninit
(
&
device
);
mal_context_uninit
(
&
context
);
mal_decoder_uninit
(
&
decoder
);
drwav_uninit
(
&
wav
);
return
-
4
;
return
-
5
;
}
}
printf
(
"Press Enter to quit..."
);
printf
(
"Press Enter to quit..."
);
getchar
();
getchar
();
mal_device_uninit
(
&
device
);
mal_device_uninit
(
&
device
);
mal_context_uninit
(
&
context
);
mal_decoder_uninit
(
&
decoder
);
drwav_uninit
(
&
wav
);
return
0
;
return
0
;
}
}
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