mirror of
https://github.com/mackron/miniaudio.git
synced 2026-04-21 15:56:58 +02:00
Fix OSS build.
This commit is contained in:
@@ -19025,8 +19025,8 @@ mal_result mal_device_init_fd__oss(mal_context* pContext, const mal_device_confi
|
|||||||
ossFragmentSizePower += 1;
|
ossFragmentSizePower += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
ossFragment = (int)((pDevice->periods << 16) | ossFragmentSizePower);
|
ossFragment = (int)((pConfig->periods << 16) | ossFragmentSizePower);
|
||||||
ossResult = ioctl(pDevice->oss.fd, SNDCTL_DSP_SETFRAGMENT, &ossFragment);
|
ossResult = ioctl(fd, SNDCTL_DSP_SETFRAGMENT, &ossFragment);
|
||||||
if (ossResult == -1) {
|
if (ossResult == -1) {
|
||||||
close(fd);
|
close(fd);
|
||||||
return mal_post_error(pDevice, MAL_LOG_LEVEL_ERROR, "[OSS] Failed to set fragment size and period count.", MAL_FORMAT_NOT_SUPPORTED);
|
return mal_post_error(pDevice, MAL_LOG_LEVEL_ERROR, "[OSS] Failed to set fragment size and period count.", MAL_FORMAT_NOT_SUPPORTED);
|
||||||
|
|||||||
+20
-20
@@ -14,29 +14,29 @@ int main(int argc, char** argv)
|
|||||||
mal_result result;
|
mal_result result;
|
||||||
mal_backend backend = mal_backend_oss;
|
mal_backend backend = mal_backend_oss;
|
||||||
|
|
||||||
mal_device_config deviceConfig = mal_device_config_init_default(NULL);
|
mal_device_config deviceConfig = mal_device_config_init(mal_device_type_playback);
|
||||||
deviceConfig.format = mal_format_f32;
|
deviceConfig.playback.format = mal_format_f32;
|
||||||
|
deviceConfig.capture.format = mal_format_f32;
|
||||||
deviceConfig.bufferSizeInFrames = 1024*8;
|
deviceConfig.bufferSizeInFrames = 1024*8;
|
||||||
//deviceConfig.bufferSizeInMilliseconds = 80;
|
//deviceConfig.bufferSizeInMilliseconds = 80;
|
||||||
deviceConfig.periods = 2;
|
deviceConfig.periods = 2;
|
||||||
deviceConfig.shareMode = mal_share_mode_shared;
|
|
||||||
|
|
||||||
#if 1
|
#if 0
|
||||||
/* Playback */
|
/* Playback */
|
||||||
mal_device device;
|
mal_device device;
|
||||||
result = mal_device_init_ex(&backend, 1, NULL, mal_device_type_playback, NULL, &deviceConfig, &device);
|
result = mal_device_init_ex(&backend, 1, NULL, &deviceConfig, &device);
|
||||||
if (result != MAL_SUCCESS) {
|
if (result != MAL_SUCCESS) {
|
||||||
printf("Failed to initialize device.\n");
|
printf("Failed to initialize device.\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("Is Passthrough: %s\n", device.dsp.isPassthrough ? "YES" : "NO");
|
printf("Is Passthrough: %s\n", device.playback.converter.isPassthrough ? "YES" : "NO");
|
||||||
printf("Format: %s -> %s\n", mal_get_format_name(device.format), mal_get_format_name(device.internalFormat));
|
printf("Format: %s -> %s\n", mal_get_format_name(device.playback.format), mal_get_format_name(device.playback.internalFormat));
|
||||||
printf("Channels: %d -> %d\n", device.channels, device.internalChannels);
|
printf("Channels: %d -> %d\n", device.playback.channels, device.playback.internalChannels);
|
||||||
printf("Sample Rate: %d -> %d\n", device.sampleRate, device.internalSampleRate);
|
printf("Sample Rate: %d -> %d\n", device.sampleRate, device.playback.internalSampleRate);
|
||||||
printf("Buffer Size In Frames: %d\n", device.bufferSizeInFrames);
|
printf("Buffer Size In Frames: %d\n", device.playback.internalBufferSizeInFrames);
|
||||||
|
|
||||||
mal_decoder_config decoderConfig = mal_decoder_config_init(mal_format_f32, device.channels, device.sampleRate);
|
mal_decoder_config decoderConfig = mal_decoder_config_init(mal_format_f32, device.playback.channels, device.sampleRate);
|
||||||
mal_decoder decoder;
|
mal_decoder decoder;
|
||||||
printf("LOADING DECODER\n");
|
printf("LOADING DECODER\n");
|
||||||
result = mal_decoder_init_file("res/sine_s16_mono_48000.wav", &decoderConfig, &decoder);
|
result = mal_decoder_init_file("res/sine_s16_mono_48000.wav", &decoderConfig, &decoder);
|
||||||
@@ -51,8 +51,8 @@ int main(int argc, char** argv)
|
|||||||
mal_bool32 stopped = MAL_FALSE;
|
mal_bool32 stopped = MAL_FALSE;
|
||||||
while (!stopped) {
|
while (!stopped) {
|
||||||
float buffer[1024*32]; float* pBuffer = buffer;
|
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_sine_wave_read_f32_ex(&sineWave, mal_countof(buffer) / device.playback.channels, device.playback.channels, mal_stream_layout_interleaved, &pBuffer);
|
||||||
mal_uint32 frameCount = (mal_uint32)mal_decoder_read_pcm_frames(&decoder, mal_countof(buffer) / device.channels, pBuffer);
|
mal_uint32 frameCount = (mal_uint32)mal_decoder_read_pcm_frames(&decoder, mal_countof(buffer) / device.playback.channels, pBuffer);
|
||||||
|
|
||||||
result = mal_device_write(&device, pBuffer, frameCount);
|
result = mal_device_write(&device, pBuffer, frameCount);
|
||||||
if (result != MAL_SUCCESS) {
|
if (result != MAL_SUCCESS) {
|
||||||
@@ -62,22 +62,24 @@ int main(int argc, char** argv)
|
|||||||
|
|
||||||
printf("TESTING: frameCount=%d\n", frameCount);
|
printf("TESTING: frameCount=%d\n", frameCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mal_decoder_uninit(&decoder);
|
||||||
#else
|
#else
|
||||||
/* Capture */
|
/* Capture */
|
||||||
mal_device device;
|
mal_device device;
|
||||||
result = mal_device_init_ex(&backend, 1, NULL, mal_device_type_capture, NULL, &deviceConfig, &device);
|
result = mal_device_init_ex(&backend, 1, NULL, &deviceConfig, &device);
|
||||||
if (result != MAL_SUCCESS) {
|
if (result != MAL_SUCCESS) {
|
||||||
printf("Failed to initialize device.\n");
|
printf("Failed to initialize device.\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("Is Passthrough: %s\n", device.dsp.isPassthrough ? "YES" : "NO");
|
printf("Is Passthrough: %s\n", device.capture.converter.isPassthrough ? "YES" : "NO");
|
||||||
printf("Format: %s\n", mal_get_format_name(device.format));
|
printf("Format: %s\n", mal_get_format_name(device.capture.format));
|
||||||
|
|
||||||
drwav_data_format format;
|
drwav_data_format format;
|
||||||
format.container = drwav_container_riff;
|
format.container = drwav_container_riff;
|
||||||
format.format = DR_WAVE_FORMAT_IEEE_FLOAT;
|
format.format = DR_WAVE_FORMAT_IEEE_FLOAT;
|
||||||
format.channels = device.channels;
|
format.channels = device.capture.channels;
|
||||||
format.sampleRate = device.sampleRate;
|
format.sampleRate = device.sampleRate;
|
||||||
format.bitsPerSample = 32;
|
format.bitsPerSample = 32;
|
||||||
drwav* pWav = drwav_open_file_write("recording.wav", &format);
|
drwav* pWav = drwav_open_file_write("recording.wav", &format);
|
||||||
@@ -90,7 +92,7 @@ int main(int argc, char** argv)
|
|||||||
mal_bool32 stopped = MAL_FALSE;
|
mal_bool32 stopped = MAL_FALSE;
|
||||||
while (!stopped) {
|
while (!stopped) {
|
||||||
float buffer[1024*4];
|
float buffer[1024*4];
|
||||||
mal_uint32 frameCount = mal_countof(buffer) / device.channels;
|
mal_uint32 frameCount = mal_countof(buffer) / device.capture.channels;
|
||||||
|
|
||||||
result = mal_device_read(&device, buffer, frameCount);
|
result = mal_device_read(&device, buffer, frameCount);
|
||||||
if (result != MAL_SUCCESS) {
|
if (result != MAL_SUCCESS) {
|
||||||
@@ -105,8 +107,6 @@ int main(int argc, char** argv)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mal_decoder_uninit(&decoder);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
printf("DONE\n");
|
printf("DONE\n");
|
||||||
|
|||||||
Reference in New Issue
Block a user