wav_parser.h 1.7 KB

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