// 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; }
// 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; }
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 = downMix(size); if(size>0) { memcpy(&output_buffer[w],(unsigned char*)samples,size); w+=size; } } }