Initial working implementation of full-duplex on WASAPI.

This commit is contained in:
David Reid
2019-02-09 17:39:49 +10:00
parent 934c7d5e63
commit 32c64703dd
5 changed files with 303 additions and 151 deletions
+38 -12
View File
@@ -3,6 +3,9 @@
#define MINI_AL_IMPLEMENTATION
#include "../mini_al.h"
#define DR_WAV_IMPLEMENTATION
#include "../extras/dr_wav.h"
void log_callback(mal_context* pContext, mal_device* pDevice, mal_uint32 logLevel, const char* message)
{
(void)pContext;
@@ -21,14 +24,31 @@ void data_callback(mal_device* pDevice, void* pOutput, const void* pInput, mal_u
{
/* In this test the format and channel count are the same for both input and output which means we can just memcpy(). */
mal_copy_memory(pOutput, pInput, frameCount * mal_get_bytes_per_frame(pDevice->format, pDevice->channels));
/* Also write to a wav file for debugging. */
drwav* pWav = (drwav*)pDevice->pUserData;
mal_assert(pWav != NULL);
drwav_write_pcm_frames(pWav, frameCount, pInput);
}
int main(int argc, char** argv)
{
mal_result result;
(void)argc;
(void)argv;
drwav_data_format wavFormat;
wavFormat.container = drwav_container_riff;
wavFormat.format = DR_WAVE_FORMAT_IEEE_FLOAT;
wavFormat.channels = 2;
wavFormat.sampleRate = 44100;
wavFormat.bitsPerSample = 32;
drwav wav;
if (drwav_init_file_write(&wav, "output.wav", &wavFormat) == DRWAV_FALSE) {
printf("Failed to initialize output file.\n");
return -1;
}
mal_backend backend = mal_backend_wasapi;
@@ -43,16 +63,18 @@ int main(int argc, char** argv)
}
mal_device_config deviceConfig = mal_device_config_init(mal_device_type_duplex);
deviceConfig.pPlaybackDeviceID = NULL;
deviceConfig.format = mal_format_f32;
deviceConfig.channels = 2;
deviceConfig.sampleRate = 44100;
deviceConfig.bufferSizeInMilliseconds = 50;
deviceConfig.periods = 3;
deviceConfig.shareMode = mal_share_mode_shared;
deviceConfig.dataCallback = data_callback;
deviceConfig.stopCallback = stop_callback;
deviceConfig.pUserData = NULL;
deviceConfig.capture.pDeviceID = NULL;
deviceConfig.capture.format = mal_format_f32;
deviceConfig.capture.channels = 2;
deviceConfig.playback.pDeviceID = NULL;
deviceConfig.playback.format = mal_format_f32;
deviceConfig.playback.channels = 2;
deviceConfig.sampleRate = 44100;
deviceConfig.bufferSizeInMilliseconds = 1000;
deviceConfig.periods = 3;
deviceConfig.dataCallback = data_callback;
deviceConfig.stopCallback = stop_callback;
deviceConfig.pUserData = &wav;
mal_device device;
result = mal_device_init(&context, &deviceConfig, &device);
@@ -66,5 +88,9 @@ int main(int argc, char** argv)
getchar();
mal_device_uninit(&device);
drwav_uninit(&wav);
(void)argc;
(void)argv;
return 0;
}
+13 -12
View File
@@ -272,11 +272,11 @@
</ClCompile>
<ClCompile Include="..\examples\simple_capture.c">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">false</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">false</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">false</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">false</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">false</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\examples\simple_enumeration.c">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
@@ -319,7 +319,7 @@
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="mal_duplex.c">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">false</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">true</ExcludedFromBuild>
@@ -359,12 +359,12 @@
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="mal_test_0.c">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">false</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">false</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">false</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">false</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">false</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">false</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="mal_test_0.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
@@ -386,6 +386,7 @@
<ItemGroup>
<ClInclude Include="..\mini_al.h" />
<ClInclude Include="..\research\mal_resampler.h" />
<ClInclude Include="..\research\mal_ring_buffer.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
+3
View File
@@ -68,5 +68,8 @@
<ClInclude Include="..\research\mal_resampler.h">
<Filter>Source Files</Filter>
</ClInclude>
<ClInclude Include="..\research\mal_ring_buffer.h">
<Filter>Source Files</Filter>
</ClInclude>
</ItemGroup>
</Project>