edith_codecs
Clone
https://git.tahinli.com/Tahinli/edith_codecs.git
0 watching0 forksRust370.3 MiBbede77eTahinli2 months ago3534 commits
| 1 | //! RIFF/WAVE and AVI audio chunk reading. |
| 2 | //! |
| 3 | //! [`WavWriter`] streams samples as they arrive and patches the RIFF, `data` |
| 4 | //! and `fact` sizes in [`WavWriter::finalize`] — a dropped writer therefore |
| 5 | //! leaves a file whose header lies, which is why finalizing is fallible and |
| 6 | //! explicit. [`WavReader`] walks the chunk list rather than assuming |
| 7 | //! `fmt `-then-`data`, so `LIST`/`INFO`, `fact`, `bext` and any other chunk a |
| 8 | //! recorder inserted are skipped, odd-sized chunks included (RIFF pads them to |
| 9 | //! an even boundary and the padding byte is not part of the chunk). |
| 10 | //! |
| 11 | //! Covered: 8/16/24/32-bit integer PCM and 32-bit float, 1 to 8 channels |
| 12 | //! (mono through 7.1), any sample rate. `WAVE_FORMAT_EXTENSIBLE` is written |
| 13 | //! whenever the file has more than two channels or more than 16 bits per |
| 14 | //! sample — the depth/layout combinations where players are entitled to |
| 15 | //! distrust a plain `WAVE_FORMAT_PCM` header — and is read whatever the file |
| 16 | //! declares. |
| 17 | //! |
| 18 | //! Not covered: RF64/BW64 (>4 GiB), ADPCM and other compressed WAVE tags, |
| 19 | //! 64-bit float, AVI video frames, and non-audio AVI chunks. Each unsupported |
| 20 | //! WAVE tag is [`Error::Unsupported`] naming itself, never a silent misread. |
| 21 | //! |
| 22 | //! The crate stands alone — [`WavSpec`] is its own type — but converts into the |
| 23 | //! family IR on request: [`WavSpec::sample_format`] and [`WavSpec::layout`]. |
| 24 | |
| 25 | |
| 26 | |
| 27 | |
| 28 | |
| 29 | |
| 30 | |
| 31 | |
| 32 | pub use ; |
| 33 | pub use ; |
| 34 | pub use WavReader; |
| 35 | pub use ; |
| 36 | |
| 37 | /// Whether samples are stored as integers (`WAVE_FORMAT_PCM`) or as floats |
| 38 | /// (`WAVE_FORMAT_IEEE_FLOAT`). |
| 39 | |
| 40 | |
| 41 | |
| 42 | |
| 43 | |
| 44 | |
| 45 | |
| 46 | |
| 47 | /// What the `fmt ` chunk says about the audio. |
| 48 | |
| 49 | |
| 50 | |
| 51 | |
| 52 | |
| 53 | |
| 54 | |
| 55 | |
| 56 | |
| 57 | |
| 58 | |
| 59 | |
| 60 | /// `WAVE_FORMAT_PCM`. |
| 61 | const FORMAT_PCM: u16 = 1; |
| 62 | /// `WAVE_FORMAT_IEEE_FLOAT`. |
| 63 | const FORMAT_FLOAT: u16 = 3; |
| 64 | /// `WAVE_FORMAT_EXTENSIBLE`. |
| 65 | const FORMAT_EXTENSIBLE: u16 = 0xFFFE; |
| 66 | |
| 67 | |
| 68 | |
| 69 | |
| 70 | |
| 71 | |
| 72 | |
| 73 | |
| 74 | |
| 75 | |
| 76 | |
| 77 | |
| 78 | |
| 79 | |
| 80 | |
| 81 | |
| 82 | |
| 83 | |
| 84 | |
| 85 | |
| 86 | |
| 87 | |
| 88 | |
| 89 | |
| 90 | |
| 91 | |
| 92 | |
| 93 | |
| 94 | |
| 95 | |
| 96 | |
| 97 | |
| 98 | |
| 99 | |
| 100 | |
| 101 | |
| 102 | |
| 103 | |
| 104 | |
| 105 | |
| 106 | |
| 107 | |
| 108 | |
| 109 | |
| 110 | |
| 111 | |
| 112 | |
| 113 | |
| 114 | |
| 115 | |
| 116 | |
| 117 | |
| 118 | |
| 119 | |
| 120 | |
| 121 | |
| 122 | |
| 123 | |
| 124 | |
| 125 | |
| 126 | |
| 127 | |
| 128 | |
| 129 | |
| 130 | |
| 131 | |
| 132 | |
| 133 | |
| 134 | |
| 135 | |
| 136 | |
| 137 | |
| 138 | |
| 139 | |
| 140 | |
| 141 | |
| 142 | |
| 143 | |
| 144 | |
| 145 | |
| 146 | |
| 147 | |
| 148 | |
| 149 | |
| 150 | |
| 151 | |
| 152 | |
| 153 | |
| 154 |