mirror of
https://github.com/vsariola/sointu.git
synced 2025-07-18 13:04:25 -04:00
Added usage examples in C; Added asm include file with track info to sointu-compile.
This commit is contained in:
committed by
Veikko Sariola
parent
dff484739c
commit
d0efcc3001
27
examples/code/C/cplay.unix.c
Normal file
27
examples/code/C/cplay.unix.c
Normal file
@ -0,0 +1,27 @@
|
||||
#include <alsa/asoundlib.h>
|
||||
#include <pthread.h>
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include "physics_girl_st.h"
|
||||
|
||||
static SUsample sound_buffer[SU_LENGTH_IN_SAMPLES * SU_CHANNEL_COUNT];
|
||||
static snd_pcm_t *pcm_handle;
|
||||
static pthread_t render_thread;
|
||||
static uint32_t render_thread_handle;
|
||||
|
||||
int main(int argc, char **args) {
|
||||
// Unix does not have gm.dls, no need to ifdef and setup here.
|
||||
|
||||
// We render in the background while playing already.
|
||||
render_thread_handle = pthread_create(&render_thread, 0, (void * (*)(void *))su_render_song, sound_buffer);
|
||||
|
||||
// We can't start playing too early or the missing samples will be audible.
|
||||
sleep(2.);
|
||||
|
||||
// Play the track.
|
||||
snd_pcm_open(&pcm_handle, "default", SND_PCM_STREAM_PLAYBACK, 0);
|
||||
snd_pcm_set_params(pcm_handle, SND_PCM_FORMAT_FLOAT, SND_PCM_ACCESS_RW_INTERLEAVED, SU_CHANNEL_COUNT, SU_SAMPLE_RATE, 0, SU_LENGTH_IN_SAMPLES);
|
||||
snd_pcm_writei(pcm_handle, sound_buffer, SU_LENGTH_IN_SAMPLES);
|
||||
|
||||
return 0;
|
||||
}
|
Reference in New Issue
Block a user