diff options
author | Jean-Francois Mauguit <jfmauguit@mac.com> | 2024-09-24 09:03:25 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-09-24 09:03:25 -0400 |
commit | bab614c421ed7ae329d26bf028c4a3b1d2450f5a (patch) | |
tree | 12f17f78986871dd2cfb0a56e5e93b545c1ae0d0 /Src/Plugins/Output/out_ds/SoundBlock.cpp | |
parent | 4bde6044fddf053f31795b9eaccdd2a5a527d21f (diff) | |
parent | 20d28e80a5c861a9d5f449ea911ab75b4f37ad0d (diff) | |
download | winamp-bab614c421ed7ae329d26bf028c4a3b1d2450f5a.tar.gz |
Merge pull request #5 from WinampDesktop/community
Merge to main
Diffstat (limited to 'Src/Plugins/Output/out_ds/SoundBlock.cpp')
-rw-r--r-- | Src/Plugins/Output/out_ds/SoundBlock.cpp | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/Src/Plugins/Output/out_ds/SoundBlock.cpp b/Src/Plugins/Output/out_ds/SoundBlock.cpp new file mode 100644 index 00000000..226f7182 --- /dev/null +++ b/Src/Plugins/Output/out_ds/SoundBlock.cpp @@ -0,0 +1,70 @@ +#include "SoundBlock.h" +#include <memory.h> +#include <malloc.h> + +SoundBlock::SoundBlock() +{ + data = 0; + size = 0; + next = 0; + prev = 0; + start = 0; + used = 0; +} + +SoundBlock::~SoundBlock() +{ + if (data) free(data); +} + +void SoundBlock::SetData(void *new_data, size_t new_size) +{ + if (!data) data = malloc(new_size); + else if (new_size > size) + { + data = realloc(data, new_size); + if (!data) data = malloc(new_size); + else size = new_size; + } + + if (data) + { + memcpy(data, new_data, new_size); + used = new_size; + } + else + { + used = 0; + } + start = 0; +} + +void SoundBlock::Advance(size_t d) +{ + used -= d; + start += d; +} + +const void *SoundBlock::GetData() +{ + return (char*)data + start; +} + +size_t SoundBlock::GetDataSize() +{ + return used; +} + +size_t SoundBlock::Dump(void * out, size_t out_size) +{ + const void * src = GetData(); + if (out_size > used) out_size = used; + memcpy(out, src, out_size); + Advance(out_size); + return out_size; +} + +void SoundBlock::Clear() +{ + used = 0; +}
\ No newline at end of file |