Skip to content

Commit 0db2aae

Browse files
authored
Merge pull request w3c#228 from w3c/audiodata_readpcm
Define AudioDataCopyToOptions with frameOffset and frameCount
2 parents 47196de + c2a1c9c commit 0db2aae

1 file changed

Lines changed: 67 additions & 25 deletions

File tree

index.src.html

Lines changed: 67 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2050,11 +2050,11 @@
20502050
readonly attribute float sampleRate;
20512051
readonly attribute unsigned long numberOfFrames;
20522052
readonly attribute unsigned long numberOfChannels;
2053-
readonly attribute unsigned long allocationSize;
20542053
readonly attribute long long duration; // microseconds
20552054
readonly attribute long long timestamp; // microseconds
20562055

2057-
undefined copyTo([AllowShared] BufferSource destination, unsigned long planeNumber);
2056+
unsigned long allocationSize(AudioDataCopyToOptions options);
2057+
undefined copyTo([AllowShared] BufferSource destination, AudioDataCopyToOptions options);
20582058
AudioData clone();
20592059
undefined close();
20602060
};
@@ -2141,17 +2141,6 @@
21412141
The {{AudioData/numberOfChannels}} getter steps are to return
21422142
{{AudioData/[[number of channels]]}}.
21432143

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-
21552144
: <dfn attribute for=AudioData>timestamp</dfn>
21562145
:: The presentation timestamp, in microseconds, for this {{AudioData}}.
21572146

@@ -2168,25 +2157,38 @@
21682157
3. Return the product of |durationInSeconds| and |microsecondsPerSecond|.
21692158

21702159
### 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>
21742173
:: Copies the samples from the specified plane of the {{AudioData}} to the
21752174
destination buffer.
21762175

21772176
When invoked, run these steps:
21782177
1. If the value of |frame|'s {{AudioData/[[detached]]}} internal slot is
21792178
`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
21862186
{{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.
21902192

21912193
: <dfn method for=AudioData>clone()</dfn>
21922194
:: Creates a new AudioData with a reference to the same [=media resource=].
@@ -2207,6 +2209,25 @@
22072209

22082210
### Algorithms ### {#audiodata-algorithms}
22092211

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+
22102231
: <dfn>Clone AudioData</dfn> (with |data|)
22112232
:: Run these steps:
22122233
1. Let |clone| be a new {{AudioData}} initialized as follows:
@@ -2222,6 +2243,27 @@
22222243
|clone|.
22232244
2. Return |clone|.
22242245

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+
22252267
Audio Sample Format{#audio-sample-format}
22262268
-----------------------------------------
22272269
Audo sample formats describe the numeric type used to represent a single

0 commit comments

Comments
 (0)