|
2050 | 2050 | readonly attribute float sampleRate; |
2051 | 2051 | readonly attribute unsigned long numberOfFrames; |
2052 | 2052 | readonly attribute unsigned long numberOfChannels; |
2053 | | - readonly attribute unsigned long allocationSize; |
2054 | 2053 | readonly attribute long long duration; // microseconds |
2055 | 2054 | readonly attribute long long timestamp; // microseconds |
2056 | 2055 |
|
2057 | | - undefined copyTo([AllowShared] BufferSource destination, unsigned long planeNumber); |
| 2056 | + unsigned long allocationSize(AudioDataCopyToOptions options); |
| 2057 | + undefined copyTo([AllowShared] BufferSource destination, AudioDataCopyToOptions options); |
2058 | 2058 | AudioData clone(); |
2059 | 2059 | undefined close(); |
2060 | 2060 | }; |
|
2141 | 2141 | The {{AudioData/numberOfChannels}} getter steps are to return |
2142 | 2142 | {{AudioData/[[number of channels]]}}. |
2143 | 2143 |
|
2144 | | -: <dfn attribute for=AudioData>allocationSize</dfn> |
2145 | | -:: The the number of bytes allocated to hold all of the samples in this |
2146 | | - {{AudioData}}. |
2147 | | - |
2148 | | - The {{AudioData/allocationSize}} getter steps are to: |
2149 | | - 1. Let |sampleSize| be the number of bytes per sample, as defined by the |
2150 | | - {{AudioData/[[sample format]]}}. |
2151 | | - 2. Return the product of multiplying |sampleSize| by |
2152 | | - {{AudioData/[[number of channels]]}} and |
2153 | | - {{AudioData/[[number of frames]]}}. |
2154 | | - |
2155 | 2144 | : <dfn attribute for=AudioData>timestamp</dfn> |
2156 | 2145 | :: The presentation timestamp, in microseconds, for this {{AudioData}}. |
2157 | 2146 |
|
|
2168 | 2157 | 3. Return the product of |durationInSeconds| and |microsecondsPerSecond|. |
2169 | 2158 |
|
2170 | 2159 | ### Methods ###{#audiodata-methods} |
2171 | | -: <dfn method for=AudioData> |
2172 | | - copyTo(|destination|, |planeNumber|) |
2173 | | - </dfn> |
| 2160 | +: <dfn method for=AudioData>allocationSize(|options|)</dfn> |
| 2161 | +:: Returns the number of bytes required to hold the samples as described by |
| 2162 | + |options|. |
| 2163 | + |
| 2164 | + When invoked, run these steps: |
| 2165 | + 1. Let |copyElementCount| be the result of running the |
| 2166 | + [=Compute Copy Element Count=] algorithm with |options|. |
| 2167 | + 2. Let |bytesPerSample| be the number of bytes per sample, as defined by |
| 2168 | + the {{AudioData/[[sample format]]}}. |
| 2169 | + 3. Return the product of multiplying |bytesPerSample| by |
| 2170 | + |copyElementCount|. |
| 2171 | + |
| 2172 | +: <dfn method for=AudioData>copyTo(|destination|, |options|)</dfn> |
2174 | 2173 | :: Copies the samples from the specified plane of the {{AudioData}} to the |
2175 | 2174 | destination buffer. |
2176 | 2175 |
|
2177 | 2176 | When invoked, run these steps: |
2178 | 2177 | 1. If the value of |frame|'s {{AudioData/[[detached]]}} internal slot is |
2179 | 2178 | `true`, throw an {{InvalidStateError}} {{DOMException}}. |
2180 | | - 2. Let |allocationSize| be the number of bytes allocated to hold this |
2181 | | - {{AudioData}}'s [=media resource=], as described by the getter steps of |
2182 | | - {{AudioData/allocationSize}}. |
2183 | | - 3. If |allocationSize| is greater than `destination.byteLength`, throw a |
2184 | | - {{TypeError}}. |
2185 | | - 4. Let |resource| be the [=media resource=] referenced by |
| 2179 | + 2. Let |copyElementCount| be the result of running the |
| 2180 | + [=Compute Copy Element Count=] algorithm with |options|. |
| 2181 | + 3. Let |bytesPerSample| be the number of bytes per sample, as defined by |
| 2182 | + the {{AudioData/[[sample format]]}}. |
| 2183 | + 4. If the product of multiplying |bytesPerSample| by |copyElementCount| is |
| 2184 | + greater than `destination.byteLength`, throw a {{RangeError}}. |
| 2185 | + 5. Let |resource| be the [=media resource=] referenced by |
2186 | 2186 | {{AudioData/[[resource reference]]}}. |
2187 | | - 5. Let |planeBytes| be the region of |resource| corresponding to |
2188 | | - |planeNumber|. |
2189 | | - 6. Copy the |planeBytes| into |destination|. |
| 2187 | + 6. Let |planeFrames| be the region of |resource| corresponding to |
| 2188 | + |options|.{{AudioDataCopyToOptions/planeIndex}}. |
| 2189 | + 7. Copy elements of |planeFrames| into |destination|, starting with the |
| 2190 | + frame positioned at |options|.{{AudioDataCopyToOptions/frameOffset}} |
| 2191 | + and stopping after |copyElementCount| elements have been copied. |
2190 | 2192 |
|
2191 | 2193 | : <dfn method for=AudioData>clone()</dfn> |
2192 | 2194 | :: Creates a new AudioData with a reference to the same [=media resource=]. |
|
2207 | 2209 |
|
2208 | 2210 | ### Algorithms ### {#audiodata-algorithms} |
2209 | 2211 |
|
| 2212 | +: <dfn>Compute Copy Element Count</dfn> (with |options|) |
| 2213 | +:: Run these steps: |
| 2214 | + 1. Let |frameCount| be the number of frames in the plane identified by |
| 2215 | + |options|.{{AudioDataCopyToOptions/planeIndex}}. |
| 2216 | + 2. If |options|.{{AudioDataCopyToOptions/frameOffset}} is greater than or |
| 2217 | + equal to |frameCount|, throw a {{RangeError}}. |
| 2218 | + 3. Let |copyFrameCount| be the difference of subtracting |
| 2219 | + |options|.{{AudioDataCopyToOptions/frameOffset}} from |frameCount|. |
| 2220 | + 4. If |options|.{{AudioDataCopyToOptions/frameCount}} [=map/exists=]: |
| 2221 | + 1. If |options|.{{AudioDataCopyToOptions/frameCount}} is greater than |
| 2222 | + |copyFrameCount|, throw a {{RangeError}}. |
| 2223 | + 2. Otherwise, assign |options|.{{AudioDataCopyToOptions/frameCount}} |
| 2224 | + to |copyFrameCount|. |
| 2225 | + 5. Let |elementCount| be |copyFrameCount|. |
| 2226 | + 6. If {{AudioData/[[sample format]]}} describes an interleaved |
| 2227 | + {{AudioSampleFormat}}, mutliply |elementCount| by |
| 2228 | + {{AudioData/[[number of channels]]}} |
| 2229 | + 7. return |elementCount|. |
| 2230 | + |
2210 | 2231 | : <dfn>Clone AudioData</dfn> (with |data|) |
2211 | 2232 | :: Run these steps: |
2212 | 2233 | 1. Let |clone| be a new {{AudioData}} initialized as follows: |
|
2222 | 2243 | |clone|. |
2223 | 2244 | 2. Return |clone|. |
2224 | 2245 |
|
| 2246 | +### AudioDataCopyToOptions ### {#audiodata-copy-to-options} |
| 2247 | + |
| 2248 | +<xmp class='idl'> |
| 2249 | +dictionary AudioDataCopyToOptions { |
| 2250 | + required unsigned long planeIndex; |
| 2251 | + unsigned long frameOffset = 0; |
| 2252 | + unsigned long frameCount; |
| 2253 | +}; |
| 2254 | +</xmp> |
| 2255 | + |
| 2256 | +: <dfn dict-member for=AudioDataCopyToOptions>planeIndex</dfn> |
| 2257 | +:: The index identifying the plane to copy from. |
| 2258 | + |
| 2259 | +: <dfn dict-member for=AudioDataCopyToOptions>frameOffset</dfn> |
| 2260 | +:: An offset into the source plane data indicating which frame to begin |
| 2261 | + copying from. Defaults to `0`. |
| 2262 | + |
| 2263 | +: <dfn dict-member for=AudioDataCopyToOptions>frameCount</dfn> |
| 2264 | +:: The number of frames to copy. If not provided, the copy will include all |
| 2265 | + frames in the plane beginning with {{AudioDataCopyToOptions/frameOffset}}. |
| 2266 | + |
2225 | 2267 | Audio Sample Format{#audio-sample-format} |
2226 | 2268 | ----------------------------------------- |
2227 | 2269 | Audo sample formats describe the numeric type used to represent a single |
|
0 commit comments