mirror of
https://github.com/mackron/miniaudio.git
synced 2026-04-23 16:54:03 +02:00
Update examples.
This commit is contained in:
+14
-1
@@ -6,4 +6,17 @@ will be placed in the "bin" directory.
|
|||||||
|
|
||||||
Then you can run executables like this:
|
Then you can run executables like this:
|
||||||
|
|
||||||
../bin/simple_playback my_sound.wav
|
../bin/simple_playback my_sound.wav
|
||||||
|
|
||||||
|
Emscripten
|
||||||
|
----------
|
||||||
|
On Windows, you need to move into the build and run emsdk_env.bat from a command prompt using an absolute
|
||||||
|
path like "C:\emsdk\emsdk_env.bat". Note that PowerShell doesn't work for me for some reason. Then, run the
|
||||||
|
relevant batch file:
|
||||||
|
|
||||||
|
ma_build_examples_emscripten.bat
|
||||||
|
|
||||||
|
The output will be placed in the bin folder. If you have output WASM it may not work when running the web
|
||||||
|
page locally. To test you can run with something like this:
|
||||||
|
|
||||||
|
emrun ../bin/simple_playback_emscripten.html
|
||||||
@@ -33,7 +33,7 @@ void data_callback_fixed(ma_device* pDevice, void* pOutput, const void* pInput,
|
|||||||
*/
|
*/
|
||||||
printf("frameCount=%d\n", frameCount);
|
printf("frameCount=%d\n", frameCount);
|
||||||
|
|
||||||
ma_sine_wave_read_f32(&g_sineWave, frameCount, (float*)pOutput);
|
ma_sine_wave_read_pcm_frames(&g_sineWave, pOutput, frameCount, ma_format_f32, pDevice->playback.channels);
|
||||||
|
|
||||||
/* Unused in this example. */
|
/* Unused in this example. */
|
||||||
(void)pDevice;
|
(void)pDevice;
|
||||||
@@ -48,9 +48,9 @@ void data_callback(ma_device* pDevice, void* pOutput, const void* pInput, ma_uin
|
|||||||
*/
|
*/
|
||||||
ma_uint32 pcmFramesAvailableInRB;
|
ma_uint32 pcmFramesAvailableInRB;
|
||||||
ma_uint32 pcmFramesProcessed = 0;
|
ma_uint32 pcmFramesProcessed = 0;
|
||||||
ma_uint8* pRunningOutput = pOutput;
|
ma_uint8* pRunningOutput = (ma_uint8*)pOutput;
|
||||||
|
|
||||||
ma_assert(pDevice->playback.channels == DEVICE_CHANNELS);
|
MA_ASSERT(pDevice->playback.channels == DEVICE_CHANNELS);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
The first thing to do is check if there's enough data available in the ring buffer. If so we can read from it. Otherwise we need to keep filling
|
The first thing to do is check if there's enough data available in the ring buffer. If so we can read from it. Otherwise we need to keep filling
|
||||||
@@ -85,7 +85,7 @@ void data_callback(ma_device* pDevice, void* pOutput, const void* pInput, ma_uin
|
|||||||
ma_pcm_rb_reset(&g_rb);
|
ma_pcm_rb_reset(&g_rb);
|
||||||
ma_pcm_rb_acquire_write(&g_rb, &framesToWrite, &pWriteBuffer);
|
ma_pcm_rb_acquire_write(&g_rb, &framesToWrite, &pWriteBuffer);
|
||||||
{
|
{
|
||||||
ma_assert(framesToWrite == PCM_FRAME_CHUNK_SIZE); /* <-- This should always work in this example because we just reset the ring buffer. */
|
MA_ASSERT(framesToWrite == PCM_FRAME_CHUNK_SIZE); /* <-- This should always work in this example because we just reset the ring buffer. */
|
||||||
data_callback_fixed(pDevice, pWriteBuffer, NULL, framesToWrite);
|
data_callback_fixed(pDevice, pWriteBuffer, NULL, framesToWrite);
|
||||||
}
|
}
|
||||||
ma_pcm_rb_commit_write(&g_rb, framesToWrite, pWriteBuffer);
|
ma_pcm_rb_commit_write(&g_rb, framesToWrite, pWriteBuffer);
|
||||||
@@ -102,7 +102,7 @@ int main(int argc, char** argv)
|
|||||||
ma_device device;
|
ma_device device;
|
||||||
|
|
||||||
ma_sine_wave_init(0.2, 400, DEVICE_SAMPLE_RATE, &g_sineWave);
|
ma_sine_wave_init(0.2, 400, DEVICE_SAMPLE_RATE, &g_sineWave);
|
||||||
ma_pcm_rb_init(DEVICE_FORMAT, DEVICE_CHANNELS, PCM_FRAME_CHUNK_SIZE, NULL, &g_rb);
|
ma_pcm_rb_init(DEVICE_FORMAT, DEVICE_CHANNELS, PCM_FRAME_CHUNK_SIZE, NULL, NULL, &g_rb);
|
||||||
|
|
||||||
deviceConfig = ma_device_config_init(ma_device_type_playback);
|
deviceConfig = ma_device_config_init(ma_device_type_playback);
|
||||||
deviceConfig.playback.format = DEVICE_FORMAT;
|
deviceConfig.playback.format = DEVICE_FORMAT;
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ properties. The output buffer in the callback will be null whereas the input buf
|
|||||||
void data_callback(ma_device* pDevice, void* pOutput, const void* pInput, ma_uint32 frameCount)
|
void data_callback(ma_device* pDevice, void* pOutput, const void* pInput, ma_uint32 frameCount)
|
||||||
{
|
{
|
||||||
drwav* pWav = (drwav*)pDevice->pUserData;
|
drwav* pWav = (drwav*)pDevice->pUserData;
|
||||||
ma_assert(pWav != NULL);
|
MA_ASSERT(pWav != NULL);
|
||||||
|
|
||||||
drwav_write_pcm_frames(pWav, frameCount, pInput);
|
drwav_write_pcm_frames(pWav, frameCount, pInput);
|
||||||
|
|
||||||
|
|||||||
+4
-4
@@ -112,8 +112,8 @@ int main(int argc, char** argv)
|
|||||||
deviceConfig.playback.channels = 2;
|
deviceConfig.playback.channels = 2;
|
||||||
deviceConfig.playback.shareMode = ma_share_mode_shared;
|
deviceConfig.playback.shareMode = ma_share_mode_shared;
|
||||||
deviceConfig.sampleRate = 0;
|
deviceConfig.sampleRate = 0;
|
||||||
deviceConfig.bufferSizeInFrames = 0;
|
deviceConfig.periodSizeInFrames = 0;
|
||||||
deviceConfig.bufferSizeInMilliseconds = 60;
|
deviceConfig.periodSizeInMilliseconds = 10;
|
||||||
deviceConfig.periods = 3;
|
deviceConfig.periods = 3;
|
||||||
deviceConfig.dataCallback = data_callback;
|
deviceConfig.dataCallback = data_callback;
|
||||||
deviceConfig.stopCallback = stop_callback;
|
deviceConfig.stopCallback = stop_callback;
|
||||||
@@ -129,9 +129,9 @@ int main(int argc, char** argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* For debugging. */
|
/* For debugging. */
|
||||||
printf("device.playback.internalBufferSizeInFrames = %d\n", device.playback.internalBufferSizeInFrames);
|
printf("device.playback.internalPeriodSizeInFrames = %d\n", device.playback.internalPeriodSizeInFrames);
|
||||||
printf("device.playback.internalPeriods = %d\n", device.playback.internalPeriods);
|
printf("device.playback.internalPeriods = %d\n", device.playback.internalPeriods);
|
||||||
printf("device.capture.internalBufferSizeInFrames = %d\n", device.capture.internalBufferSizeInFrames);
|
printf("device.capture.internalPeriodSizeInFrames = %d\n", device.capture.internalPeriodSizeInFrames);
|
||||||
printf("device.capture.internalPeriods = %d\n", device.capture.internalPeriods);
|
printf("device.capture.internalPeriods = %d\n", device.capture.internalPeriods);
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user