// returns bytes read, else -1 if error (0 is OK) int AmAudio::get(unsigned long long system_ts, unsigned char* buffer, int output_sample_rate, unsigned int nb_samples) { int size = calcBytesToRead((int)((float)nb_samples * (float)getSampleRate() / (float)output_sample_rate)); unsigned int rd_ts = scaleSystemTS(system_ts); //DBG("\tread(rd_ts = %10.u; size = %u)\n",rd_ts,size); size = read(rd_ts,size); if(size <= 0){ return size; } size = decode(size); if(size < 0) { DBG("decode returned %i\n",size); return -1; } size = downMix(size); size = resampleOutput((unsigned char*)samples, size, getSampleRate(), output_sample_rate); if(size>0) memcpy(buffer,(unsigned char*)samples,size); return size; }
void AmBufferedAudio::input_get_audio(unsigned int user_ts) { if (r && (r != w)) { // move contents to beginning of buffer memmove(output_buffer, &output_buffer[r], w-r); w -= r; r = 0; } while (w < full_buffer_thresh) { int size = calcBytesToRead(PCM16_B2S(output_buffer_size - w)); // DBG("calc %d bytes to read\n", size); // resync might be delayed until buffer empty // (but output resync never happens) size = read(user_ts + PCM16_B2S(w-r),size); // DBG("read returned size = %d\n",size); if(size <= 0){ err_code = size; eof = true; return; } size = decode(size); if(size < 0) { // DBG("decode returned %i\n",size); err_code = size; eof = true; return; } // DBG("decode returned %i\n",size); size = downMixChannels(size); size = downMixRate(size); if(size>0) { memcpy(&output_buffer[w],(unsigned char*)samples,size); w+=size; } } }
// returns bytes read, else -1 if error (0 is OK) int AmAudio::get(unsigned int user_ts, unsigned char* buffer, unsigned int nb_samples) { int size = calcBytesToRead(nb_samples); size = read(user_ts,size); //DBG("size = %d\n",size); if(size <= 0){ return size; } size = decode(size); if(size < 0) { DBG("decode returned %i\n",size); return -1; } size = downMix(size); if(size>0) memcpy(buffer,(unsigned char*)samples,size); return size; }
int AmPlaylist::get(unsigned int user_ts, unsigned char* buffer, unsigned int nb_samples) { int ret = -1; cur_mut.lock(); updateCurrentItem(); while(cur_item && cur_item->play && (ret = cur_item->play->get(user_ts,buffer,nb_samples)) <= 0){ DBG("get: gotoNextItem\n"); gotoNextItem(); } if(!cur_item || !cur_item->play) { ret = calcBytesToRead(nb_samples); memset(buffer,0,ret); } cur_mut.unlock(); return ret; }