mirror of
https://github.com/vsariola/sointu.git
synced 2025-07-20 14:04:34 -04:00
feat(examples): added playback timestamp extraction to ALSA example. (#190)
This commit is contained in:
@ -2,12 +2,17 @@
|
|||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include <time.h>
|
||||||
#include "physics_girl_st.h"
|
#include "physics_girl_st.h"
|
||||||
|
|
||||||
static SUsample sound_buffer[SU_LENGTH_IN_SAMPLES * SU_CHANNEL_COUNT];
|
static SUsample sound_buffer[SU_LENGTH_IN_SAMPLES * SU_CHANNEL_COUNT];
|
||||||
static snd_pcm_t *pcm_handle;
|
static snd_pcm_t *pcm_handle;
|
||||||
static pthread_t render_thread;
|
static pthread_t render_thread, playback_thread;
|
||||||
static uint32_t render_thread_handle;
|
static uint32_t render_thread_handle, playback_thread_handle;
|
||||||
|
|
||||||
|
void play() {
|
||||||
|
snd_pcm_writei(pcm_handle, sound_buffer, SU_LENGTH_IN_SAMPLES);
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char **args) {
|
int main(int argc, char **args) {
|
||||||
// Unix does not have gm.dls, no need to ifdef and setup here.
|
// Unix does not have gm.dls, no need to ifdef and setup here.
|
||||||
@ -33,7 +38,21 @@ int main(int argc, char **args) {
|
|||||||
0,
|
0,
|
||||||
SU_LENGTH_IN_SAMPLES
|
SU_LENGTH_IN_SAMPLES
|
||||||
);
|
);
|
||||||
snd_pcm_writei(pcm_handle, sound_buffer, SU_LENGTH_IN_SAMPLES);
|
playback_thread_handle = pthread_create(&playback_thread, 0, (void *(*)(void *))play, 0);
|
||||||
|
|
||||||
|
// This is for obtaining the playback time.
|
||||||
|
snd_pcm_status_t *status;
|
||||||
|
snd_pcm_status_malloc(&status);
|
||||||
|
snd_htimestamp_t htime, htstart;
|
||||||
|
snd_pcm_status(pcm_handle, status);
|
||||||
|
snd_pcm_status_get_htstamp(status, &htstart);
|
||||||
|
for(int sample; sample < SU_LENGTH_IN_SAMPLES; sample = (int)(((float)htime.tv_sec + (float)htime.tv_nsec * 1.e-9 - (float)htstart.tv_sec - (float)htstart.tv_nsec * 1.e-9) * SU_SAMPLE_RATE)) {
|
||||||
|
snd_pcm_status(pcm_handle, status);
|
||||||
|
snd_pcm_status_get_htstamp(status, &htime);
|
||||||
|
printf("Sample: %d\n", sample);
|
||||||
|
usleep(1000000 / 30);
|
||||||
|
}
|
||||||
|
snd_pcm_status_free(status);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user