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
fc905ec9
Commit
fc905ec9
authored
Jan 11, 2025
by
David Reid
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add simple_spatialization example.
parent
3081e314
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
76 additions
and
0 deletions
+76
-0
examples/simple_spatialization.c
examples/simple_spatialization.c
+76
-0
No files found.
examples/simple_spatialization.c
0 → 100644
View file @
fc905ec9
/*
Demonstrates how to do basic spatialization via the high level API.
You can position and orientate sounds to create a simple spatialization effect. This example shows
how to do this.
In addition to positioning sounds, there is the concept of a listener. This can also be positioned
and orientated to help with spatialization.
This example only covers the basics to get your started. See the documentation for more detailed
information on the available features.
To use this example, pass in the path of a sound as the first argument. The sound will be
positioned in front of the listener, while the listener rotates on the the spot to create an
orbiting effect. Terminate the program with Ctrl+C.
*/
#define MINIAUDIO_IMPLEMENTATION
#include "../miniaudio.h"
#include <stdio.h>
#include <math.h>
/* For sinf() and cosf() */
int
main
(
int
argc
,
char
**
argv
)
{
ma_result
result
;
ma_engine
engine
;
ma_sound
sound
;
float
listenerAngle
=
0
;
if
(
argc
<
2
)
{
printf
(
"No input file.
\n
"
);
return
-
1
;
}
result
=
ma_engine_init
(
NULL
,
&
engine
);
if
(
result
!=
MA_SUCCESS
)
{
printf
(
"Failed to initialize engine.
\n
"
);
return
-
1
;
}
result
=
ma_sound_init_from_file
(
&
engine
,
argv
[
1
],
0
,
NULL
,
NULL
,
&
sound
);
if
(
result
!=
MA_SUCCESS
)
{
printf
(
"Failed to load sound: %s
\n
"
,
argv
[
1
]);
ma_engine_uninit
(
&
engine
);
return
-
1
;
}
/* This sets the position of the sound. miniaudio follows the same coordinate system as OpenGL, where -Z is forward. */
ma_sound_set_position
(
&
sound
,
0
,
0
,
-
1
);
/*
This sets the position of the listener. The second parameter is the listener index. If you have only a single listener, which is
most likely, just use 0. The position defaults to (0,0,0).
*/
ma_engine_listener_set_position
(
&
engine
,
0
,
0
,
0
,
0
);
/* Sounds are stopped by default. We'll start it once initial parameters have been setup. */
ma_sound_start
(
&
sound
);
/* Rotate the listener on the spot to create an orbiting effect. */
for
(;;)
{
listenerAngle
+=
0
.
01
f
;
ma_engine_listener_set_direction
(
&
engine
,
0
,
sinf
(
listenerAngle
),
0
,
cosf
(
listenerAngle
));
ma_sleep
(
1
);
}
/* Won't actually get here, but do this to tear down. */
ma_sound_uninit
(
&
sound
);
ma_engine_uninit
(
&
engine
);
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