SoundBlockList.cpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. #include "SoundBlockList.h"
  2. #include <memory.h>
  3. void SoundBlockList::AddBlock(void * data, size_t size)
  4. {
  5. SoundBlock * b = remove(b_free);
  6. if (!b) b=new SoundBlock;
  7. b->SetData(data,size);
  8. mount2(b_first,b,b_last);
  9. data_buffered+=size;
  10. #ifdef USE_LOG
  11. char boo[256] = {0};
  12. wsprintf(boo,"AddBlock: %u, +%u",data_buffered,size);
  13. log_write(boo);
  14. #endif
  15. }
  16. size_t SoundBlockList::DumpBlocks(void * out1, size_t size1)
  17. {
  18. char * p1=(char*)out1;
  19. size_t rv=0;
  20. while(b_last && size1)
  21. {
  22. if (size1)
  23. {
  24. size_t d=b_last->Dump(p1,size1);
  25. p1+=d;
  26. size1-=d;
  27. rv+=d;
  28. }
  29. if (b_last->GetDataSize()==0)
  30. {
  31. mount(b_free,removelast(b_first,b_last));
  32. }
  33. }
  34. if (size1) memset(p1,silence_filler,size1);
  35. data_buffered-=rv;
  36. return rv;
  37. }
  38. void SoundBlockList::Reset()
  39. {
  40. if (b_first)
  41. {
  42. connect(b_last,b_free);
  43. b_free=b_first;
  44. }
  45. b_first=0;
  46. b_last=0;
  47. data_buffered=0;
  48. }
  49. SoundBlockList::~SoundBlockList()
  50. {
  51. SoundBlock * p;
  52. while(b_first)
  53. {
  54. p=b_first;
  55. b_first=b_first->next;
  56. delete p;
  57. }
  58. while(b_free)
  59. {
  60. p=b_free;
  61. b_free=b_free->next;
  62. delete p;
  63. }
  64. }
  65. size_t SoundBlockList::DataSize()
  66. {
  67. return data_buffered;
  68. }
  69. SoundBlockList::SoundBlockList(int sil)
  70. {
  71. b_first = 0;b_last = 0;b_free = 0;data_buffered = 0;silence_filler = sil;
  72. }
  73. void SoundBlockList::advance(SoundBlock * &b)
  74. {
  75. b = b->next;
  76. }
  77. void SoundBlockList::goback(SoundBlock * &b)
  78. {
  79. b = b->prev;
  80. }
  81. void SoundBlockList::mount(SoundBlock * &first, SoundBlock * add)
  82. {
  83. connect(0, add);
  84. connect(add, first);
  85. first = add;
  86. }
  87. void SoundBlockList::mount2(SoundBlock * &first, SoundBlock * add, SoundBlock * &last)
  88. {
  89. mount(first, add);
  90. if (!last) last = add;
  91. }
  92. SoundBlock *SoundBlockList::remove(SoundBlock * &list)
  93. {
  94. SoundBlock * b = list;
  95. if (b)
  96. {
  97. advance(list);
  98. connect(0, list);
  99. connect(b, 0);
  100. }
  101. return b;
  102. }
  103. SoundBlock *SoundBlockList::removelast(SoundBlock * &first, SoundBlock * &last)
  104. {
  105. SoundBlock * b = last;
  106. if (b)
  107. {
  108. goback(last);
  109. connect(last, 0);
  110. connect(0, b);
  111. if (!last) first = 0;
  112. }
  113. return b;
  114. }