mirror of
https://github.com/mackron/miniaudio.git
synced 2026-04-24 01:04:02 +02:00
Add a non-interactive mode for the deviceio test.
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
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
|
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
|
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"
|
#include "../test_common/ma_test_common.c"
|
||||||
|
|
||||||
|
#ifndef AUTO_CLOSE_TIME_IN_MILLISECONDS
|
||||||
|
#define AUTO_CLOSE_TIME_IN_MILLISECONDS 5000
|
||||||
|
#endif
|
||||||
|
|
||||||
typedef enum
|
typedef enum
|
||||||
{
|
{
|
||||||
source_type_waveform,
|
source_type_waveform,
|
||||||
@@ -60,6 +64,8 @@ static struct
|
|||||||
ma_decoder decoder;
|
ma_decoder decoder;
|
||||||
ma_encoder encoder;
|
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 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;
|
} g_State;
|
||||||
|
|
||||||
const char* get_mode_description(ma_device_type deviceType)
|
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)
|
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)
|
switch (pDevice->type)
|
||||||
{
|
{
|
||||||
case ma_device_type_playback:
|
case ma_device_type_playback:
|
||||||
@@ -403,6 +414,7 @@ int main(int argc, char** argv)
|
|||||||
ma_noise_type noiseType = ma_noise_type_white;
|
ma_noise_type noiseType = ma_noise_type_white;
|
||||||
const char* pFilePath = NULL; /* Input or output file path, depending on the mode. */
|
const char* pFilePath = NULL; /* Input or output file path, depending on the mode. */
|
||||||
ma_bool32 enumerate = MA_TRUE;
|
ma_bool32 enumerate = MA_TRUE;
|
||||||
|
ma_bool32 interactive = MA_TRUE;
|
||||||
|
|
||||||
/* Default to a sine wave if nothing is passed into the command line. */
|
/* Default to a sine wave if nothing is passed into the command line. */
|
||||||
waveformType = ma_waveform_type_sine;
|
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. */
|
/* We need to iterate over the command line arguments and gather our settings. */
|
||||||
for (iarg = 1; iarg < argc; iarg += 1) {
|
for (iarg = 1; iarg < argc; iarg += 1) {
|
||||||
|
if (strcmp(argv[iarg], "--auto") == 0) {
|
||||||
|
interactive = MA_FALSE;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
/* mode */
|
/* mode */
|
||||||
if (try_parse_mode(argv[iarg], &deviceType)) {
|
if (try_parse_mode(argv[iarg], &deviceType)) {
|
||||||
continue;
|
continue;
|
||||||
@@ -577,7 +594,8 @@ int main(int argc, char** argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Now we just keep looping and wait for user input. */
|
/* Now we just keep looping and wait for user input. */
|
||||||
for (;;) {
|
while (!g_State.wantsToClose) {
|
||||||
|
if (interactive) {
|
||||||
int c;
|
int c;
|
||||||
|
|
||||||
if (ma_device_is_started(&g_State.device)) {
|
if (ma_device_is_started(&g_State.device)) {
|
||||||
@@ -594,6 +612,7 @@ int main(int argc, char** argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (c == 'q' || c == 'Q') {
|
if (c == 'q' || c == 'Q') {
|
||||||
|
g_State.wantsToClose = MA_TRUE;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (c == 'p' || c == 'P') {
|
if (c == 'p' || c == 'P') {
|
||||||
@@ -609,6 +628,10 @@ int main(int argc, char** argv)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
/* Running in auto-close mode. Just sleep for a bit. The data callback will control when this loop aborts. */
|
||||||
|
ma_sleep(10);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
done:
|
done:
|
||||||
|
|||||||
Reference in New Issue
Block a user