OSS: Work on the blocking read/write API.

This commit is contained in:
David Reid
2018-07-30 10:34:09 +10:00
parent 4e6f702f55
commit 6caa823ea2
2 changed files with 37 additions and 80 deletions
+18 -14
View File
@@ -1,22 +1,22 @@
#include <stdio.h>
#define MINI_AL_IMPLEMENTATION
#include "../mini_al.h"
#define DR_WAV_IMPLEMENTATION
#include "../extras/dr_wav.h"
#define MINI_AL_IMPLEMENTATION
#include "../mini_al.h"
int main(int argc, char** argv)
{
(void)argc;
(void)argv;
mal_result result;
mal_backend backend = mal_backend_alsa;
mal_backend backend = mal_backend_oss;
mal_device_config deviceConfig = mal_device_config_init_default(NULL);
deviceConfig.format = mal_format_f32;
deviceConfig.bufferSizeInFrames = 1024*4;
deviceConfig.bufferSizeInFrames = 1024*8;
//deviceConfig.bufferSizeInMilliseconds = 80;
deviceConfig.periods = 2;
deviceConfig.shareMode = mal_share_mode_shared;
@@ -32,23 +32,27 @@ int main(int argc, char** argv)
printf("Is Passthrough: %s\n", device.dsp.isPassthrough ? "YES" : "NO");
printf("Format: %s -> %s\n", mal_get_format_name(device.format), mal_get_format_name(device.internalFormat));
printf("Channels: %d -> %d\n", device.channels, device.internalChannels);
printf("Sample Rate: %d -> %d\n", device.sampleRate, device.internalSampleRate);
printf("Buffer Size In Frames: %d\n", device.bufferSizeInFrames);
drwav* pWav = drwav_open_file("res/private/song1_short_s16.wav");
if (pWav == NULL) {
mal_decoder_config decoderConfig = mal_decoder_config_init(mal_format_f32, device.channels, device.sampleRate);
mal_decoder decoder;
printf("LOADING DECODER\n");
result = mal_decoder_init_file("res/sine_s16_mono_48000.wav", &decoderConfig, &decoder);
if (result != MAL_SUCCESS) {
printf("Failed to load sound file.\n");
}
/* The device is started by just writing data to it. In our case we are just writing a sine wave. */
mal_sine_wave sineWave;
mal_sine_wave_init(0.25, 400, device.sampleRate, &sineWave);
mal_sine_wave_init(0.25, 400, device.sampleRate/2, &sineWave);
mal_bool32 stopped = MAL_FALSE;
while (!stopped) {
float buffer[4096*4]; float* pBuffer = buffer;
mal_uint32 frameCount = (mal_uint32)mal_sine_wave_read_f32_ex(&sineWave, mal_countof(buffer) / device.channels, device.channels, mal_stream_layout_interleaved, &pBuffer);
//mal_uint32 frameCount = (mal_uint32)drwav_read_pcm_frames_f32(pWav, mal_countof(buffer) / device.channels, pBuffer);
float buffer[1024*32]; float* pBuffer = buffer;
//mal_uint32 frameCount = (mal_uint32)mal_sine_wave_read_f32_ex(&sineWave, mal_countof(buffer) / device.channels, device.channels, mal_stream_layout_interleaved, &pBuffer);
mal_uint32 frameCount = (mal_uint32)mal_decoder_read_pcm_frames(&decoder, mal_countof(buffer) / device.channels, pBuffer);
result = mal_device_write(&device, pBuffer, frameCount);
if (result != MAL_SUCCESS) {
@@ -85,7 +89,7 @@ int main(int argc, char** argv)
int counter = 0;
mal_bool32 stopped = MAL_FALSE;
while (!stopped) {
float buffer[1024*16];
float buffer[1024*4];
mal_uint32 frameCount = mal_countof(buffer) / device.channels;
result = mal_device_read(&device, buffer, frameCount);
@@ -102,7 +106,7 @@ int main(int argc, char** argv)
}
}
drwav_close(pWav);
mal_decoder_uninit(&decoder);
#endif
printf("DONE\n");