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
5d0705b3
Commit
5d0705b3
authored
Dec 03, 2017
by
David Reid
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Check the return value of mal_device_start() in examples.
parent
8727d3d8
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
56 additions
and
20 deletions
+56
-20
README.md
README.md
+14
-8
examples/advanced_config.c
examples/advanced_config.c
+7
-2
examples/multi_playback.c
examples/multi_playback.c
+8
-2
examples/simple_capture.c
examples/simple_capture.c
+16
-3
examples/simple_playback.c
examples/simple_playback.c
+11
-5
No files found.
README.md
View file @
5d0705b3
...
@@ -62,7 +62,7 @@ Simple Playback Example
...
@@ -62,7 +62,7 @@ Simple Playback Example
#include "../mini_al.h"
#include "../mini_al.h"
#define DR_WAV_IMPLEMENTATION
#define DR_WAV_IMPLEMENTATION
#include "dr_wav.h"
#include "
../extras/
dr_wav.h"
#include <stdio.h>
#include <stdio.h>
...
@@ -80,20 +80,20 @@ mal_uint32 on_send_frames_to_device(mal_device* pDevice, mal_uint32 frameCount,
...
@@ -80,20 +80,20 @@ mal_uint32 on_send_frames_to_device(mal_device* pDevice, mal_uint32 frameCount,
int
main
(
int
argc
,
char
**
argv
)
int
main
(
int
argc
,
char
**
argv
)
{
{
if
(
argc
<
2
)
{
if
(
argc
<
2
)
{
printf
(
"No input file."
);
printf
(
"No input file.
\n
"
);
return
-
1
;
return
-
1
;
}
}
drwav
wav
;
drwav
wav
;
if
(
!
drwav_init_file
(
&
wav
,
argv
[
1
]))
{
if
(
!
drwav_init_file
(
&
wav
,
argv
[
1
]))
{
printf
(
"Not a valid WAV file."
);
printf
(
"Not a valid WAV file.
\n
"
);
return
-
2
;
return
-
2
;
}
}
mal_context
context
;
mal_context
context
;
if
(
mal_context_init
(
NULL
,
0
,
NULL
,
&
context
)
!=
MAL_SUCCESS
)
{
if
(
mal_context_init
(
NULL
,
0
,
NULL
,
&
context
)
!=
MAL_SUCCESS
)
{
printf
(
"Failed to initialize context."
);
printf
(
"Failed to initialize context.
\n
"
);
drwav_uninit
(
&
wav
);
drwav_uninit
(
&
wav
);
return
-
3
;
return
-
3
;
}
}
...
@@ -101,13 +101,19 @@ int main(int argc, char** argv)
...
@@ -101,13 +101,19 @@ int main(int argc, char** argv)
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
(
&
context
,
mal_device_type_playback
,
NULL
,
&
config
,
&
wav
,
&
device
)
!=
MAL_SUCCESS
)
{
printf
(
"Failed to open playback device."
);
printf
(
"Failed to open playback device.
\n
"
);
mal_context_uninit
(
&
context
);
mal_context_uninit
(
&
context
);
drwav_uninit
(
&
wav
);
drwav_uninit
(
&
wav
);
return
-
4
;
return
-
4
;
}
}
mal_device_start
(
&
device
);
if
(
mal_device_start
(
&
device
)
!=
MAL_SUCCESS
)
{
printf
(
"Failed to start playback device.
\n
"
);
mal_device_uninit
(
&
device
);
mal_context_uninit
(
&
context
);
drwav_uninit
(
&
wav
);
return
-
5
;
}
printf
(
"Press Enter to quit..."
);
printf
(
"Press Enter to quit..."
);
getchar
();
getchar
();
...
...
examples/advanced_config.c
View file @
5d0705b3
...
@@ -155,12 +155,17 @@ int main(int argc, char** argv)
...
@@ -155,12 +155,17 @@ int main(int argc, char** argv)
mal_device
playbackDevice
;
mal_device
playbackDevice
;
if
(
mal_device_init
(
&
context
,
mal_device_type_playback
,
NULL
,
&
deviceConfig
,
NULL
,
&
playbackDevice
)
!=
MAL_SUCCESS
)
{
if
(
mal_device_init
(
&
context
,
mal_device_type_playback
,
NULL
,
&
deviceConfig
,
NULL
,
&
playbackDevice
)
!=
MAL_SUCCESS
)
{
printf
(
"Failed to initialize playback device."
);
printf
(
"Failed to initialize playback device.
\n
"
);
mal_context_uninit
(
&
context
);
mal_context_uninit
(
&
context
);
return
-
7
;
return
-
7
;
}
}
mal_device_start
(
&
playbackDevice
);
if
(
mal_device_start
(
&
playbackDevice
)
!=
MAL_SUCCESS
)
{
printf
(
"Failed to start playback device.
\n
"
);
mal_device_uninit
(
&
playbackDevice
);
mal_context_uninit
(
&
context
);
return
-
8
;
}
printf
(
"Press Enter to quit..."
);
printf
(
"Press Enter to quit..."
);
getchar
();
getchar
();
...
...
examples/multi_playback.c
View file @
5d0705b3
...
@@ -92,7 +92,7 @@ int main(int argc, char** argv)
...
@@ -92,7 +92,7 @@ int main(int argc, char** argv)
drwav
*
wav
=
NULL
;
drwav
*
wav
=
NULL
;
stb_vorbis
*
vorbis
=
NULL
;
stb_vorbis
*
vorbis
=
NULL
;
if
(
type
==
UNK
&&
(
flac
=
drflac_open_file
(
argv
[
1
]))
!=
NULL
)
type
=
FLAC
;
if
(
type
==
UNK
&&
(
flac
=
drflac_open_file
(
argv
[
1
]))
!=
NULL
)
type
=
FLAC
;
if
(
type
==
UNK
&&
(
wav
=
drwav_open_file
(
&
wav
,
argv
[
1
]))
!=
NULL
)
type
=
WAV
;
if
(
type
==
UNK
&&
(
wav
=
drwav_open_file
(
argv
[
1
]))
!=
NULL
)
type
=
WAV
;
if
(
type
==
UNK
&&
(
vorbis
=
stb_vorbis_open_filename
(
argv
[
1
],
NULL
,
NULL
))
!=
NULL
)
type
=
VORBIS
;
if
(
type
==
UNK
&&
(
vorbis
=
stb_vorbis_open_filename
(
argv
[
1
],
NULL
,
NULL
))
!=
NULL
)
type
=
VORBIS
;
if
(
type
==
UNK
&&
(
jar_xm_create_context_from_file
(
&
xm
,
48000
,
argv
[
1
])
==
0
))
type
=
XM
;
if
(
type
==
UNK
&&
(
jar_xm_create_context_from_file
(
&
xm
,
48000
,
argv
[
1
])
==
0
))
type
=
XM
;
if
(
type
==
UNK
&&
(
jar_mod_load_file
(
&
mod
,
argv
[
1
])
!=
0
)
)
type
=
MOD
;
if
(
type
==
UNK
&&
(
jar_mod_load_file
(
&
mod
,
argv
[
1
])
!=
0
)
)
type
=
MOD
;
...
@@ -148,7 +148,13 @@ int main(int argc, char** argv)
...
@@ -148,7 +148,13 @@ int main(int argc, char** argv)
goto
end
;
goto
end
;
}
}
mal_device_start
(
&
device
);
if
(
mal_device_start
(
&
device
)
!=
MAL_SUCCESS
)
{
printf
(
"Failed to start playback device.
\n
"
);
mal_device_uninit
(
&
device
);
mal_context_uninit
(
&
context
);
exitcode
=
-
4
;
goto
end
;
}
printf
(
"Press Enter to quit..."
);
printf
(
"Press Enter to quit..."
);
getchar
();
getchar
();
...
...
examples/simple_capture.c
View file @
5d0705b3
...
@@ -63,10 +63,16 @@ int main()
...
@@ -63,10 +63,16 @@ int main()
return
-
2
;
return
-
2
;
}
}
mal_device_start
(
&
captureDevice
);
if
(
mal_device_start
(
&
captureDevice
)
!=
MAL_SUCCESS
)
{
mal_device_uninit
(
&
captureDevice
);
mal_context_uninit
(
&
context
);
printf
(
"Failed to start capture device.
\n
"
);
return
-
3
;
}
printf
(
"Press Enter to stop recording...
\n
"
);
printf
(
"Press Enter to stop recording...
\n
"
);
getchar
();
getchar
();
mal_device_uninit
(
&
captureDevice
);
mal_device_uninit
(
&
captureDevice
);
...
@@ -76,12 +82,19 @@ int main()
...
@@ -76,12 +82,19 @@ int main()
if
(
mal_device_init
(
&
context
,
mal_device_type_playback
,
NULL
,
&
config
,
NULL
,
&
playbackDevice
)
!=
MAL_SUCCESS
)
{
if
(
mal_device_init
(
&
context
,
mal_device_type_playback
,
NULL
,
&
config
,
NULL
,
&
playbackDevice
)
!=
MAL_SUCCESS
)
{
mal_context_uninit
(
&
context
);
mal_context_uninit
(
&
context
);
printf
(
"Failed to initialize playback device.
\n
"
);
printf
(
"Failed to initialize playback device.
\n
"
);
return
-
3
;
return
-
4
;
}
if
(
mal_device_start
(
&
playbackDevice
)
!=
MAL_SUCCESS
)
{
mal_device_uninit
(
&
playbackDevice
);
mal_context_uninit
(
&
context
);
printf
(
"Failed to start playback device.
\n
"
);
return
-
5
;
}
}
mal_device_start
(
&
playbackDevice
);
printf
(
"Press Enter to quit...
\n
"
);
printf
(
"Press Enter to quit...
\n
"
);
getchar
();
getchar
();
mal_device_uninit
(
&
playbackDevice
);
mal_device_uninit
(
&
playbackDevice
);
mal_context_uninit
(
&
context
);
mal_context_uninit
(
&
context
);
...
...
examples/simple_playback.c
View file @
5d0705b3
...
@@ -20,19 +20,19 @@ mal_uint32 on_send_frames_to_device(mal_device* pDevice, mal_uint32 frameCount,
...
@@ -20,19 +20,19 @@ mal_uint32 on_send_frames_to_device(mal_device* pDevice, mal_uint32 frameCount,
int
main
(
int
argc
,
char
**
argv
)
int
main
(
int
argc
,
char
**
argv
)
{
{
if
(
argc
<
2
)
{
if
(
argc
<
2
)
{
printf
(
"No input file."
);
printf
(
"No input file.
\n
"
);
return
-
1
;
return
-
1
;
}
}
drwav
wav
;
drwav
wav
;
if
(
!
drwav_init_file
(
&
wav
,
argv
[
1
]))
{
if
(
!
drwav_init_file
(
&
wav
,
argv
[
1
]))
{
printf
(
"Not a valid WAV file."
);
printf
(
"Not a valid WAV file.
\n
"
);
return
-
2
;
return
-
2
;
}
}
mal_context
context
;
mal_context
context
;
if
(
mal_context_init
(
NULL
,
0
,
NULL
,
&
context
)
!=
MAL_SUCCESS
)
{
if
(
mal_context_init
(
NULL
,
0
,
NULL
,
&
context
)
!=
MAL_SUCCESS
)
{
printf
(
"Failed to initialize context."
);
printf
(
"Failed to initialize context.
\n
"
);
drwav_uninit
(
&
wav
);
drwav_uninit
(
&
wav
);
return
-
3
;
return
-
3
;
}
}
...
@@ -41,13 +41,19 @@ int main(int argc, char** argv)
...
@@ -41,13 +41,19 @@ int main(int argc, char** argv)
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
(
&
context
,
mal_device_type_playback
,
NULL
,
&
config
,
&
wav
,
&
device
)
!=
MAL_SUCCESS
)
{
printf
(
"Failed to open playback device."
);
printf
(
"Failed to open playback device.
\n
"
);
mal_context_uninit
(
&
context
);
mal_context_uninit
(
&
context
);
drwav_uninit
(
&
wav
);
drwav_uninit
(
&
wav
);
return
-
4
;
return
-
4
;
}
}
mal_device_start
(
&
device
);
if
(
mal_device_start
(
&
device
)
!=
MAL_SUCCESS
)
{
printf
(
"Failed to start playback device.
\n
"
);
mal_device_uninit
(
&
device
);
mal_context_uninit
(
&
context
);
drwav_uninit
(
&
wav
);
return
-
5
;
}
printf
(
"Press Enter to quit..."
);
printf
(
"Press Enter to quit..."
);
getchar
();
getchar
();
...
...
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