libgui/include/gui/sounds/BufferCircle.hpp

144 lines
3.5 KiB
C++
Raw Normal View History

2018-06-21 20:44:58 +02:00
/***************************************************************************
* Copyright (C) 2010
* by Dimok
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any
* damages arising from the use of this software.
*
* Permission is granted to anyone to use this software for any
* purpose, including commercial applications, and to alter it and
* redistribute it freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you
* must not claim that you wrote the original software. If you use
* this software in a product, an acknowledgment in the product
* documentation would be appreciated but is not required.
*
* 2. Altered source versions must be plainly marked as such, and
* must not be misrepresented as being the original software.
*
* 3. This notice may not be removed or altered from any source
* distribution.
*
* for WiiXplorer 2010
***************************************************************************/
#ifndef BUFFER_CIRCLE_HPP_
#define BUFFER_CIRCLE_HPP_
2022-02-05 14:28:08 +01:00
#include <cstddef>
2018-06-21 20:44:58 +02:00
#include <stdint.h>
2022-02-05 14:28:08 +01:00
#include <vector>
2018-06-21 20:44:58 +02:00
class BufferCircle {
public:
//!> Constructor
BufferCircle();
2020-08-13 12:38:07 +02:00
2018-06-21 20:44:58 +02:00
//!> Destructor
~BufferCircle();
2020-08-13 12:38:07 +02:00
2018-06-21 20:44:58 +02:00
//!> Set circle size
void Resize(int32_t size);
2020-08-13 12:38:07 +02:00
2018-06-21 20:44:58 +02:00
//!> Get the circle size
int32_t Size() {
return SoundBuffer.size();
};
2020-08-13 12:38:07 +02:00
2018-06-21 20:44:58 +02:00
//!> Set/resize the buffer size
void SetBufferBlockSize(int32_t size);
2020-08-13 12:38:07 +02:00
2018-06-21 20:44:58 +02:00
//!> Remove a buffer
void RemoveBuffer(int32_t pos);
2020-08-13 12:38:07 +02:00
2018-06-21 20:44:58 +02:00
//!> Set all buffers clear
void ClearBuffer();
2020-08-13 12:38:07 +02:00
2018-06-21 20:44:58 +02:00
//!> Free all buffers
void FreeBuffer();
2020-08-13 12:38:07 +02:00
2018-06-21 20:44:58 +02:00
//!> Switch to next buffer
void LoadNext();
2020-08-13 12:38:07 +02:00
2018-06-21 20:44:58 +02:00
//!> Get the current buffer
2020-08-13 12:38:07 +02:00
uint8_t *GetBuffer() {
2018-06-21 20:44:58 +02:00
return GetBuffer(which);
};
2020-08-13 12:38:07 +02:00
2018-06-21 20:44:58 +02:00
//!> Get a buffer at a position
2020-08-13 12:38:07 +02:00
uint8_t *GetBuffer(int32_t pos) {
2022-02-05 14:28:08 +01:00
if (!Valid(pos)) {
return NULL;
} else {
return SoundBuffer[pos];
}
2018-06-21 20:44:58 +02:00
};
2020-08-13 12:38:07 +02:00
2018-06-21 20:44:58 +02:00
//!> Get current buffer size
uint32_t GetBufferSize() {
return GetBufferSize(which);
};
2020-08-13 12:38:07 +02:00
2018-06-21 20:44:58 +02:00
//!> Get buffer size at position
uint32_t GetBufferSize(int32_t pos) {
2022-02-05 14:28:08 +01:00
if (!Valid(pos)) {
return 0;
} else {
return BufferSize[pos];
}
2018-06-21 20:44:58 +02:00
};
2020-08-13 12:38:07 +02:00
2018-06-21 20:44:58 +02:00
//!> Is current buffer ready
bool IsBufferReady() {
return IsBufferReady(which);
};
2020-08-13 12:38:07 +02:00
2018-06-21 20:44:58 +02:00
//!> Is a buffer at a position ready
bool IsBufferReady(int32_t pos) {
2022-02-05 14:28:08 +01:00
if (!Valid(pos)) {
return false;
} else {
return BufferReady[pos];
}
2018-06-21 20:44:58 +02:00
};
2020-08-13 12:38:07 +02:00
2018-06-21 20:44:58 +02:00
//!> Set a buffer at a position to a ready state
void SetBufferReady(int32_t pos, bool st);
2020-08-13 12:38:07 +02:00
2018-06-21 20:44:58 +02:00
//!> Set the buffersize at a position
void SetBufferSize(int32_t pos, int32_t size);
2020-08-13 12:38:07 +02:00
2018-06-21 20:44:58 +02:00
//!> Get the current position in the circle
uint16_t Which() {
return which;
};
//!> Get the next location
inline uint16_t Next() {
2020-08-13 12:38:07 +02:00
return (which + 1 >= Size()) ? 0 : which + 1;
2018-06-21 20:44:58 +02:00
}
2020-08-13 12:38:07 +02:00
2018-06-21 20:44:58 +02:00
inline uint16_t Prev() {
2022-02-05 14:28:08 +01:00
if (Size() == 0) {
return 0;
} else {
return ((int32_t) which - 1 < 0) ? Size() - 1 : which - 1;
}
2018-06-21 20:44:58 +02:00
}
2020-08-13 12:38:07 +02:00
2018-06-21 20:44:58 +02:00
protected:
//!> Check if the position is a valid position in the vector
bool Valid(int32_t pos) {
return !(pos < 0 || pos >= Size());
};
uint16_t which;
uint32_t BufferBlockSize;
std::vector<uint8_t *> SoundBuffer;
std::vector<uint32_t> BufferSize;
std::vector<bool> BufferReady;
};
#endif