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
cff683a1
Commit
cff683a1
authored
Feb 18, 2025
by
David Reid
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add a non-interactive mode for the deviceio test.
parent
62d64d14
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
50 additions
and
27 deletions
+50
-27
tests/test_deviceio/ma_test_deviceio.c
tests/test_deviceio/ma_test_deviceio.c
+50
-27
No files found.
tests/test_deviceio/ma_test_deviceio.c
View file @
cff683a1
/*
USAGE: ma_test_deviceio [input/output file] [mode] [backend] [waveform] [noise]
USAGE: ma_test_deviceio [input/output file] [mode] [backend] [waveform] [noise]
[--auto]
In playback mode the input file is optional, in which case a waveform or noise source will be used instead. For capture and loopback modes
it must specify an output parameter, and must be specified. In duplex mode it is optional, but if specified will be an output file that
...
...
@@ -43,6 +43,10 @@ are specified the last one on the command line will have priority.
*/
#include "../test_common/ma_test_common.c"
#ifndef AUTO_CLOSE_TIME_IN_MILLISECONDS
#define AUTO_CLOSE_TIME_IN_MILLISECONDS 5000
#endif
typedef
enum
{
source_type_waveform
,
...
...
@@ -60,6 +64,8 @@ static struct
ma_decoder
decoder
;
ma_encoder
encoder
;
ma_bool32
hasEncoder
;
/* Used for duplex mode to determine whether or not audio data should be written to a file. */
ma_bool32
wantsToClose
;
ma_uint64
runTimeInFrames
;
/* Only used in auto mode. */
}
g_State
;
const
char
*
get_mode_description
(
ma_device_type
deviceType
)
...
...
@@ -340,6 +346,11 @@ void on_notification(const ma_device_notification* pNotification)
void
on_data
(
ma_device
*
pDevice
,
void
*
pFramesOut
,
const
void
*
pFramesIn
,
ma_uint32
frameCount
)
{
g_State
.
runTimeInFrames
+=
frameCount
;
if
(
g_State
.
runTimeInFrames
>=
(
g_State
.
device
.
sampleRate
*
AUTO_CLOSE_TIME_IN_MILLISECONDS
)
/
1000
)
{
g_State
.
wantsToClose
=
MA_TRUE
;
}
switch
(
pDevice
->
type
)
{
case
ma_device_type_playback
:
...
...
@@ -403,6 +414,7 @@ int main(int argc, char** argv)
ma_noise_type
noiseType
=
ma_noise_type_white
;
const
char
*
pFilePath
=
NULL
;
/* Input or output file path, depending on the mode. */
ma_bool32
enumerate
=
MA_TRUE
;
ma_bool32
interactive
=
MA_TRUE
;
/* Default to a sine wave if nothing is passed into the command line. */
waveformType
=
ma_waveform_type_sine
;
...
...
@@ -410,6 +422,11 @@ int main(int argc, char** argv)
/* We need to iterate over the command line arguments and gather our settings. */
for
(
iarg
=
1
;
iarg
<
argc
;
iarg
+=
1
)
{
if
(
strcmp
(
argv
[
iarg
],
"--auto"
)
==
0
)
{
interactive
=
MA_FALSE
;
continue
;
}
/* mode */
if
(
try_parse_mode
(
argv
[
iarg
],
&
deviceType
))
{
continue
;
...
...
@@ -577,37 +594,43 @@ int main(int argc, char** argv)
}
/* Now we just keep looping and wait for user input. */
for
(;;)
{
int
c
;
while
(
!
g_State
.
wantsToClose
)
{
if
(
interactive
)
{
int
c
;
if
(
ma_device_is_started
(
&
g_State
.
device
))
{
printf
(
"Press Q to quit, P to pause.
\n
"
);
}
else
{
printf
(
"Press Q to quit, P to resume.
\n
"
);
}
for
(;;)
{
c
=
getchar
();
if
(
c
!=
'\n'
)
{
break
;
}
}
if
(
c
==
'q'
||
c
==
'Q'
)
{
break
;
}
if
(
c
==
'p'
||
c
==
'P'
)
{
if
(
ma_device_is_started
(
&
g_State
.
device
))
{
result
=
ma_device_stop
(
&
g_State
.
device
);
if
(
result
!=
MA_SUCCESS
)
{
printf
(
"ERROR: Error when stopping the device: %s
\n
"
,
ma_result_description
(
result
));
}
printf
(
"Press Q to quit, P to pause.
\n
"
);
}
else
{
result
=
ma_device_start
(
&
g_State
.
device
);
if
(
result
!=
MA_SUCCESS
)
{
printf
(
"ERROR: Error when starting the device: %s
\n
"
,
ma_result_description
(
result
));
printf
(
"Press Q to quit, P to resume.
\n
"
);
}
for
(;;)
{
c
=
getchar
();
if
(
c
!=
'\n'
)
{
break
;
}
}
if
(
c
==
'q'
||
c
==
'Q'
)
{
g_State
.
wantsToClose
=
MA_TRUE
;
break
;
}
if
(
c
==
'p'
||
c
==
'P'
)
{
if
(
ma_device_is_started
(
&
g_State
.
device
))
{
result
=
ma_device_stop
(
&
g_State
.
device
);
if
(
result
!=
MA_SUCCESS
)
{
printf
(
"ERROR: Error when stopping the device: %s
\n
"
,
ma_result_description
(
result
));
}
}
else
{
result
=
ma_device_start
(
&
g_State
.
device
);
if
(
result
!=
MA_SUCCESS
)
{
printf
(
"ERROR: Error when starting the device: %s
\n
"
,
ma_result_description
(
result
));
}
}
}
}
else
{
/* Running in auto-close mode. Just sleep for a bit. The data callback will control when this loop aborts. */
ma_sleep
(
10
);
}
}
...
...
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