mirror of
https://github.com/mackron/miniaudio.git
synced 2026-04-21 15:56:58 +02:00
Update examples.
This commit is contained in:
@@ -47,6 +47,12 @@ mal_uint32 on_send_frames(mal_device* pDevice, mal_uint32 frameCount, void* pSam
|
|||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
|
mal_context context;
|
||||||
|
if (mal_context_init(NULL, 0, &context) != MAL_SUCCESS) {
|
||||||
|
printf("Failed to initialize context.");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
mal_device_config config;
|
mal_device_config config;
|
||||||
config.format = mal_format_f32;
|
config.format = mal_format_f32;
|
||||||
config.channels = 2;
|
config.channels = 2;
|
||||||
@@ -60,7 +66,8 @@ int main()
|
|||||||
|
|
||||||
printf("Recording...\n");
|
printf("Recording...\n");
|
||||||
mal_device captureDevice;
|
mal_device captureDevice;
|
||||||
if (mal_device_init(&captureDevice, mal_device_type_capture, NULL, &config, NULL)) {
|
if (mal_device_init(&context, mal_device_type_capture, NULL, &config, NULL, &captureDevice) != MAL_SUCCESS) {
|
||||||
|
mal_context_uninit(&context);
|
||||||
printf("Failed to initialize capture device.\n");
|
printf("Failed to initialize capture device.\n");
|
||||||
return -2;
|
return -2;
|
||||||
}
|
}
|
||||||
@@ -74,7 +81,8 @@ int main()
|
|||||||
|
|
||||||
printf("Playing...\n");
|
printf("Playing...\n");
|
||||||
mal_device playbackDevice;
|
mal_device playbackDevice;
|
||||||
if (mal_device_init(&playbackDevice, mal_device_type_playback, NULL, &config, NULL)) {
|
if (mal_device_init(&context, mal_device_type_playback, NULL, &config, NULL, &playbackDevice) != MAL_SUCCESS) {
|
||||||
|
mal_context_uninit(&context);
|
||||||
printf("Failed to initialize playback device.\n");
|
printf("Failed to initialize playback device.\n");
|
||||||
return -3;
|
return -3;
|
||||||
}
|
}
|
||||||
@@ -84,5 +92,6 @@ int main()
|
|||||||
getchar();
|
getchar();
|
||||||
mal_device_uninit(&playbackDevice);
|
mal_device_uninit(&playbackDevice);
|
||||||
|
|
||||||
|
mal_context_uninit(&context);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -29,6 +29,12 @@ int main(int argc, char** argv)
|
|||||||
printf("Not a valid WAV file.");
|
printf("Not a valid WAV file.");
|
||||||
return -2;
|
return -2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mal_context context;
|
||||||
|
if (mal_context_init(NULL, 0, &context) != MAL_SUCCESS) {
|
||||||
|
printf("Failed to initialize context.");
|
||||||
|
return -3;
|
||||||
|
}
|
||||||
|
|
||||||
// In this example we use the default playback device with a default buffer size and period count.
|
// In this example we use the default playback device with a default buffer size and period count.
|
||||||
mal_device_config config;
|
mal_device_config config;
|
||||||
@@ -43,10 +49,11 @@ int main(int argc, char** argv)
|
|||||||
config.onLogCallback = NULL;
|
config.onLogCallback = NULL;
|
||||||
|
|
||||||
mal_device device;
|
mal_device device;
|
||||||
if (mal_device_init(&device, mal_device_type_playback, NULL, &config, &wav) != 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.");
|
||||||
|
mal_context_uninit(&context);
|
||||||
drwav_uninit(&wav);
|
drwav_uninit(&wav);
|
||||||
return -3;
|
return -4;
|
||||||
}
|
}
|
||||||
mal_device_start(&device);
|
mal_device_start(&device);
|
||||||
|
|
||||||
@@ -54,6 +61,7 @@ int main(int argc, char** argv)
|
|||||||
getchar();
|
getchar();
|
||||||
|
|
||||||
mal_device_uninit(&device);
|
mal_device_uninit(&device);
|
||||||
|
mal_context_uninit(&context);
|
||||||
drwav_uninit(&wav);
|
drwav_uninit(&wav);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user