-
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
new examples for dmon, miniaudio and termbox2
built in extensions are fun! the tutorial documentation now links these
- Loading branch information
Showing
3 changed files
with
893 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#include <stdio.h> | ||
#include <dmon.h> | ||
|
||
static void watch_callback(dmon_watch_id watch_id, | ||
dmon_action action, | ||
const char* rootdir, | ||
const char* filepath, | ||
const char* oldfilepath, | ||
void* user) { | ||
(void)(user); | ||
(void)(watch_id); | ||
switch (action) { | ||
case DMON_ACTION_CREATE: | ||
fprintf(stderr,"CREATE: [%s]%s\n", rootdir, filepath); | ||
break; | ||
case DMON_ACTION_DELETE: | ||
fprintf(stderr,"DELETE: [%s]%s\n", rootdir, filepath); | ||
break; | ||
case DMON_ACTION_MODIFY: | ||
fprintf(stderr,"MODIFY: [%s]%s\n", rootdir, filepath); | ||
break; | ||
case DMON_ACTION_MOVE: | ||
fprintf(stderr,"MOVE: [%s]%s -> [%s]%s\n", rootdir, oldfilepath, rootdir, filepath); | ||
break; | ||
} | ||
} | ||
|
||
int main(int argc, char* argv[]) { | ||
if (argc > 1) { | ||
dmon_init(); | ||
puts("waiting for changes .."); | ||
dmon_watch(argv[1], watch_callback, DMON_WATCHFLAGS_RECURSIVE, NULL); | ||
getchar(); | ||
dmon_deinit(); | ||
} else { | ||
puts("usage: test dirname"); | ||
} | ||
return 0; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
#define MA_NO_DECODING | ||
#define MA_NO_ENCODING | ||
#define MINIAUDIO_IMPLEMENTATION | ||
#include <miniaudio.h> | ||
|
||
#include <stdio.h> | ||
|
||
#ifdef __EMSCRIPTEN__ | ||
#include <emscripten.h> | ||
|
||
void main_loop__em() | ||
{ | ||
} | ||
#endif | ||
|
||
#define DEVICE_FORMAT ma_format_f32 | ||
#define DEVICE_CHANNELS 2 | ||
#define DEVICE_SAMPLE_RATE 48000 | ||
|
||
void data_callback(ma_device* pDevice, void* pOutput, const void* pInput, ma_uint32 frameCount) | ||
{ | ||
ma_waveform* pSineWave; | ||
|
||
MA_ASSERT(pDevice->playback.channels == DEVICE_CHANNELS); | ||
|
||
pSineWave = (ma_waveform*)pDevice->pUserData; | ||
MA_ASSERT(pSineWave != NULL); | ||
|
||
ma_waveform_read_pcm_frames(pSineWave, pOutput, frameCount, NULL); | ||
|
||
(void)pInput; /* Unused. */ | ||
} | ||
|
||
int main(int argc, char** argv) | ||
{ | ||
ma_waveform sineWave; | ||
ma_device_config deviceConfig; | ||
ma_device device; | ||
ma_waveform_config sineWaveConfig; | ||
|
||
deviceConfig = ma_device_config_init(ma_device_type_playback); | ||
deviceConfig.playback.format = DEVICE_FORMAT; | ||
deviceConfig.playback.channels = DEVICE_CHANNELS; | ||
deviceConfig.sampleRate = DEVICE_SAMPLE_RATE; | ||
deviceConfig.dataCallback = data_callback; | ||
deviceConfig.pUserData = &sineWave; | ||
|
||
if (ma_device_init(NULL, &deviceConfig, &device) != MA_SUCCESS) { | ||
printf("Failed to open playback device.\n"); | ||
return -4; | ||
} | ||
|
||
printf("Device Name: %s\n", device.playback.name); | ||
|
||
sineWaveConfig = ma_waveform_config_init(device.playback.format, device.playback.channels, device.sampleRate, ma_waveform_type_sine, 0.2, 220); | ||
ma_waveform_init(&sineWaveConfig, &sineWave); | ||
|
||
if (ma_device_start(&device) != MA_SUCCESS) { | ||
printf("Failed to start playback device.\n"); | ||
ma_device_uninit(&device); | ||
return -5; | ||
} | ||
|
||
#ifdef __EMSCRIPTEN__ | ||
emscripten_set_main_loop(main_loop__em, 0, 1); | ||
#else | ||
printf("Press Enter to quit...\n"); | ||
getchar(); | ||
#endif | ||
|
||
ma_device_uninit(&device); | ||
|
||
(void)argc; | ||
(void)argv; | ||
return 0; | ||
} |
Oops, something went wrong.