MCPcopy Create free account
hub / github.com/DescentDevelopers/Descent3 / UpdateData

Method UpdateData

stream_audio/streamaudio.cpp:855–912  ·  view source on GitHub ↗

updates file buffers

Source from the content-addressed store, hash-verified

853#pragma optimize("", off)
854// updates file buffers
855void AudioStream::UpdateData() {
856 int nextbuffer = ((m_fbufidx + 1) % STRM_BUFCOUNT);
857 // check if are on a measure boundary for current stream. if so, then check if we have a next request pending
858 if (CHECK_FLAG(m_buffer[nextbuffer].flags, STRM_BUFF_USED)) {
859 return;
860 }
861 // quit out if we can.
862 if (nextbuffer == m_sbufidx) {
863 return;
864 }
865 // do read!
866 // READ DATA INTO BUFFER. UPDATE BYTES LEFT PER MEASURE, ETC.
867 if (m_readahead) {
868 // ok update the next buffer with data
869 m_fbufidx = nextbuffer;
870 // mprintf(0,"%c",m_fbufidx+'a');
871 // if our stream's current id does not match the streaming buffer's id, then we need to reallocate
872 // the stream buffer with the new memory size
873 if (m_buffer[m_fbufidx].id != (int)m_curid) {
874 if (m_buffer[m_fbufidx].data) {
875 mem_free(m_buffer[m_fbufidx].data);
876 }
877 m_buffer[m_fbufidx].data = (uint8_t *)mem_malloc(m_bufsize);
878 }
879 m_buffer[m_fbufidx].nbytes = AudioStream::ReadFileData(m_fbufidx, m_bufsize);
880 m_buffer[m_fbufidx].flags = 0;
881 m_buffer[m_fbufidx].flags |= STRM_BUFF_USED;
882 m_buffer[m_fbufidx].id = (int)m_curid;
883 m_playbytesleft -= m_buffer[m_fbufidx].nbytes;
884 // mprintf(0, "[%d]:pbytesleft=%d\n", m_curid, m_playbytesleft);
885 LOGFILE((_logfp, "[%d]:pbytesleft=%d\n", m_curid, m_playbytesleft));
886 if (m_playbytesleft <= (m_bufsize / 4)) {
887 // mprintf(0, "STRM[%d]: ", m_curid);
888 if (m_buffer[m_fbufidx].nbytes == 0) {
889 memset(m_buffer[m_fbufidx].data, 0, 4);
890 m_buffer[m_fbufidx].nbytes = 4;
891 mprintf(0, "making empty buffer and");
892 }
893 // mprintf(0, "TERMINAL buffer.\n");
894 LOGFILE((_logfp, "STRM[%d]: TERMINAL buffer.\n", m_curid));
895 m_buffer[m_fbufidx].flags |= STRM_BUFF_TERMINAL;
896 m_readahead = false;
897 m_readahead_finished_loop = true;
898 }
899 // looping?
900 if (CHECK_FLAG(m_buffer[m_fbufidx].flags, STRM_BUFF_TERMINAL)) {
901 if (m_loopcount == -1) {
902 m_buffer[m_fbufidx].flags |= STRM_BUFF_LOOPEND;
903 AudioStream::Reset();
904 } else if (m_loopcount > 0) {
905 m_buffer[m_fbufidx].flags |= STRM_BUFF_LOOPEND;
906 AudioStream::Reset();
907 m_loopcount--;
908 }
909 m_readahead_finished_loop = true;
910 }
911 }
912}

Callers 15

FrameMethod · 0.80
OnInitDialogMethod · 0.80
OnBtnDetectMethod · 0.80
OnVideocardDetectMethod · 0.80
OnInitDialogMethod · 0.80
OnBtnAudioDetectMethod · 0.80
OnInitDialogMethod · 0.80
ClearListMethod · 0.80
AddToListMethod · 0.80
RemoveFromListMethod · 0.80
LoadListMethod · 0.80
SaveListMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected