wav_parser.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. #pragma once
  2. #include <toolbox/stream/stream.h>
  3. #include <furi.h>
  4. #include <furi_hal.h>
  5. #include <gui/gui.h>
  6. #include <dialogs/dialogs.h>
  7. #include <notification/notification_messages.h>
  8. #include <gui/view_holder.h>
  9. #include <toolbox/stream/file_stream.h>
  10. #include "wav_player_view.h"
  11. #ifdef __cplusplus
  12. extern "C" {
  13. #endif
  14. typedef enum {
  15. FormatTagPCM = 0x0001,
  16. FormatTagIEEE_FLOAT = 0x0003,
  17. } FormatTag;
  18. typedef struct {
  19. uint8_t riff[4];
  20. uint32_t size;
  21. uint8_t wave[4];
  22. } WavHeaderChunk;
  23. typedef struct {
  24. uint8_t fmt[4];
  25. uint32_t size;
  26. uint16_t tag;
  27. uint16_t channels;
  28. uint32_t sample_rate;
  29. uint32_t byte_per_sec;
  30. uint16_t block_align;
  31. uint16_t bits_per_sample;
  32. } WavFormatChunk;
  33. typedef struct {
  34. uint8_t data[4];
  35. uint32_t size;
  36. } WavDataChunk;
  37. typedef struct WavParser WavParser;
  38. typedef struct {
  39. Storage* storage;
  40. Stream* stream;
  41. WavParser* parser;
  42. uint8_t* sample_buffer;
  43. uint8_t* tmp_buffer;
  44. uint32_t sample_rate;
  45. uint16_t num_channels;
  46. uint16_t bits_per_sample;
  47. size_t samples_count_half;
  48. size_t samples_count;
  49. FuriMessageQueue* queue;
  50. float volume;
  51. bool play;
  52. WavPlayerView* view;
  53. ViewHolder* view_holder;
  54. Gui* gui;
  55. NotificationApp* notification;
  56. FuriString* path;
  57. } WavPlayerApp;
  58. WavParser* wav_parser_alloc();
  59. void wav_parser_free(WavParser* parser);
  60. bool wav_parser_parse(WavParser* parser, Stream* stream, WavPlayerApp* app);
  61. size_t wav_parser_get_data_start(WavParser* parser);
  62. size_t wav_parser_get_data_end(WavParser* parser);
  63. size_t wav_parser_get_data_len(WavParser* parser);
  64. #ifdef __cplusplus
  65. }
  66. #endif