fifo.h 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #ifndef FIFO_H
  2. #define FIFO_H
  3. #ifdef __cplusplus
  4. extern "C"
  5. {
  6. #endif
  7. #define PCMMAX(a,b) ((a) > (b) ? (a) : (b))
  8. #define PCMMIN(a,b) ((a) > (b) ? (b) : (a))
  9. typedef struct PCMFifoBuffer {
  10. unsigned char *buffer;
  11. unsigned char *rptr, *wptr, *end;
  12. } PCMFifoBuffer;
  13. int pcm_fifo_init(PCMFifoBuffer *f, int size);
  14. void pcm_fifo_free(PCMFifoBuffer *f);
  15. int pcm_fifo_size(PCMFifoBuffer *f);
  16. int pcm_fifo_read(PCMFifoBuffer *f, unsigned char *buf, int buf_size);
  17. int pcm_fifo_generic_read(PCMFifoBuffer *f, int buf_size, void (*func)(void*, void*, int), void* dest);
  18. void pcm_fifo_write(PCMFifoBuffer *f, const unsigned char *buf, int size);
  19. void pcm_fifo_realloc(PCMFifoBuffer *f, unsigned int size);
  20. void pcm_fifo_drain(PCMFifoBuffer *f, int size);
  21. static unsigned char pcm_fifo_peek(PCMFifoBuffer *f, int offs)
  22. {
  23. unsigned char *ptr = f->rptr + offs;
  24. if (ptr >= f->end)
  25. ptr -= f->end - f->buffer;
  26. return *ptr;
  27. }
  28. #ifdef __cplusplus
  29. }
  30. #endif
  31. #endif /* FIFO_H */