void m1sdr_TimeCheck(void) { #if VALGRIND m1sdr_Update(); #else audio_buf_info info; ioctl(audiofd, SNDCTL_DSP_GETOSPACE, &info); if (oss_nw) { int err; m1sdr_Update(); playtime++; // output the generated samples err = write(audiofd, samples, nDSoundSegLen * 4); if (err == -1) { perror("write\n"); } #if LOG_WAVE fwrite(samples, nDSoundSegLen*4, 1, logfil); #endif } else { while (info.bytes >= (nDSoundSegLen * 4)) { m1sdr_Update(); playtime++; // output the generated samples write(audiofd, samples, nDSoundSegLen * 4); #if LOG_WAVE fwrite(samples, nDSoundSegLen*4, 1, logfil); #endif ioctl(audiofd, SNDCTL_DSP_GETOSPACE, &info); } } usleep(50); #endif }
// checks the play position to see if we should trigger another update void m1sdr_TimeCheck(void) { // int timeout; snd_pcm_sframes_t avail = 0; #if VALGRIND m1sdr_Update(); #else switch (lnxdrv_apimode) { case 0: // SDL #ifdef USE_SDL SDL_LockAudio(); while ((bufstat[writebuf] == 0) && (writebuf != playbuf)) { m1sdr_Update(); playtime++; } SDL_UnlockAudio(); #endif break; case 1: // ALSA if ((!pHandle) || (!oss_playing)) { m1sdr_Update(); playtime++; return; } avail = snd_pcm_avail_update(pHandle); // printf("avail %d\n", avail); #if 0 if (avail < 0) { int err; if ((err = snd_pcm_prepare(pHandle)) < 0) { fprintf (stderr, "cannot prepare audio interface for use (%s)\n", snd_strerror(err)); return 0; } } #endif while (avail >= nDSoundSegLen) { int status; m1sdr_Update(); waveLogFrame((unsigned char *)samples, nDSoundSegLen * 4); playtime++; status = snd_pcm_writei(pHandle, samples, nDSoundSegLen); if (status < 0) { if (status == -EAGAIN) { // printf("EAGAIN\n"); do { status = snd_pcm_resume(pHandle); } while (status == -EAGAIN); } if (status == -ESTRPIPE) { // printf("ESTRPIPE\n"); do { status = snd_pcm_resume(pHandle); } while (status == -EAGAIN); } if (status < 0) { status = snd_pcm_prepare(pHandle); } } avail = snd_pcm_avail_update(pHandle); } break; case 2: // OSS if ((audiofd == -1) || (!oss_playing)) { m1sdr_Update(); playtime++; return; } ioctl(audiofd, SNDCTL_DSP_GETOSPACE, &info); if (oss_nw) { int err; m1sdr_Update(); // output the generated samples err = write(audiofd, samples, nDSoundSegLen * 4); if (err == -1) { perror("write\n"); } waveLogFrame((unsigned char *)samples, nDSoundSegLen * 4); } else { while (info.bytes >= (nDSoundSegLen * 4)) { m1sdr_Update(); playtime++; // output the generated samples write(audiofd, samples, nDSoundSegLen * 4); waveLogFrame((unsigned char *)samples, nDSoundSegLen * 4); ioctl(audiofd, SNDCTL_DSP_GETOSPACE, &info); } } break; case 3: // PulseAudio { #if !PULSE_USE_SIMPLE int size; if ((!my_pa_context) || (!my_pa_stream) || (!my_pa_mainloop)) { return; } while (1) { if (pa_context_get_state(my_pa_context) != PA_CONTEXT_READY || pa_stream_get_state(my_pa_stream) != PA_STREAM_READY || pa_mainloop_iterate(my_pa_mainloop, 0, NULL) < 0) { usleep(50); return; } size = pa_stream_writable_size(my_pa_stream); // printf("stream has %d bytes avail, want %d\n", size, nDSoundSegLen*4); if (size >= (nDSoundSegLen*4)) { m1sdr_Update(); playtime++; waveLogFrame((unsigned char *)samples, nDSoundSegLen * 4); if (pa_stream_write(my_pa_stream, (uint8_t*)samples, nDSoundSegLen*4, NULL, 0, PA_SEEK_RELATIVE) < 0) { // printf("pa_stream_write() failed: %s\n", pa_strerror(pa_context_errno(my_pa_context))); } } else { usleep(50); return; } } #else m1sdr_Update(); playtime++; waveLogFrame((unsigned char *)samples, nDSoundSegLen * 4); pa_simple_write(my_simple, samples, nDSoundSegLen*4, NULL); #endif } break; } usleep(50); #endif }