/* ------------------------------------------------- / sx_audio_sink_buffer_get() / /---------------------------------------------------*/ UINT8 *sx_audio_sink_buffer_get(void){ UINT8 *buf = audioplay_get_buffer(st); assert(buf != NULL); return buf; }
void PlayBuffer(short *PCMData, int size) { AUDIOPLAY_STATE_T *st; int32_t ret; int phase = 0; int inc = 256<<16; int dinc = 0; int buffer_bytes = (BUFFER_SIZE_SAMPLES * bitdepth * OUT_CHANNELS(nchannels))>>3; ret = audioplay_create(&st, samplerate, nchannels, bitdepth, bufferCount, buffer_bytes); ret = audioplay_set_dest(st, audio_dest[dest]); int sectorNumber= (size-1)/BUFFER_SIZE_SAMPLES+1; int i; for (i=0;i<sectorNumber;i++) { uint8_t *buf; int16_t *p; uint32_t latency; while((buf = audioplay_get_buffer(st)) == NULL) usleep(CTTW_SLEEP_TIME*1000); p = (int16_t *) buf; if ((i+1)*BUFFER_SIZE_SAMPLES<=size) { memcpy(p,PCMData+i*BUFFER_SIZE_SAMPLES,sizeof(short)*BUFFER_SIZE_SAMPLES); } else { memcpy(p,PCMData+i*BUFFER_SIZE_SAMPLES,sizeof(short)*(size-i*BUFFER_SIZE_SAMPLES)); memset(p+size-i*BUFFER_SIZE_SAMPLES,0,sizeof(short)*((i+1)*BUFFER_SIZE_SAMPLES-size)); } // try and wait for a minimum latency time (in ms) before // sending the next packet while((latency = audioplay_get_latency(st)) > (samplerate * (MIN_LATENCY_TIME + CTTW_SLEEP_TIME) / 1000)) usleep(CTTW_SLEEP_TIME*1000); //if (i==m_CurPlayStartSector) usleep(CTTW_SLEEP_TIME*1000); ret = audioplay_play_buffer(st, buf, buffer_bytes); } audioplay_delete(st); }