|
| 1 | +use super::{AudioNode, AudioNodeOptions, ChannelConfig, ChannelCountMode, ChannelInterpretation}; |
1 | 2 | use crate::context::{AudioContextRegistration, BaseAudioContext}; |
2 | 3 | use crate::events::{AudioProcessingEvent, EventHandler, EventPayload, EventType}; |
3 | | -use crate::node::{ChannelCountMode, ChannelInterpretation}; |
4 | 4 | use crate::render::{ |
5 | 5 | AudioParamValues, AudioProcessor, AudioRenderQuantum, AudioWorkletGlobalScope, |
6 | 6 | }; |
7 | 7 | use crate::{AudioBuffer, RENDER_QUANTUM_SIZE}; |
8 | 8 |
|
9 | | -use super::{AudioNode, AudioNodeOptions, ChannelConfig}; |
10 | | - |
11 | 9 | use std::any::Any; |
12 | 10 |
|
| 11 | +/// Options for constructing an [`ScriptProcessorNode`] |
| 12 | +#[derive(Clone, Debug)] |
| 13 | +pub struct ScriptProcessorOptions { |
| 14 | + pub buffer_size: usize, |
| 15 | + pub number_of_input_channels: usize, |
| 16 | + pub number_of_output_channels: usize, |
| 17 | +} |
| 18 | + |
13 | 19 | /// An AudioNode which can generate, process, or analyse audio directly using a script (deprecated) |
14 | 20 | #[derive(Debug)] |
15 | 21 | pub struct ScriptProcessorNode { |
@@ -56,12 +62,26 @@ impl AudioNode for ScriptProcessorNode { |
56 | 62 | } |
57 | 63 |
|
58 | 64 | impl ScriptProcessorNode { |
59 | | - pub(crate) fn new<C: BaseAudioContext>( |
60 | | - context: &C, |
61 | | - buffer_size: usize, |
62 | | - number_of_input_channels: usize, |
63 | | - number_of_output_channels: usize, |
64 | | - ) -> Self { |
| 65 | + /// Creates a `ScriptProcessorNode` |
| 66 | + /// |
| 67 | + /// # Arguments |
| 68 | + /// |
| 69 | + /// - `context` - Audio context in which the node will live |
| 70 | + /// - `options` - node options |
| 71 | + /// |
| 72 | + /// # Panics |
| 73 | + /// |
| 74 | + /// This function panics if: |
| 75 | + /// - `buffer_size` is not 256, 512, 1024, 2048, 4096, 8192, or 16384 |
| 76 | + /// - the number of input and output channels are both zero |
| 77 | + /// - either of the channel counts exceed [`MAX_CHANNELS`] |
| 78 | + pub fn new<C: BaseAudioContext>(context: &C, options: ScriptProcessorOptions) -> Self { |
| 79 | + let ScriptProcessorOptions { |
| 80 | + buffer_size, |
| 81 | + number_of_input_channels, |
| 82 | + number_of_output_channels, |
| 83 | + } = options; |
| 84 | + |
65 | 85 | assert!( |
66 | 86 | (buffer_size / 256).is_power_of_two() && buffer_size <= 16384, |
67 | 87 | "IndexSizeError - bufferSize must be one of: 256, 512, 1024, 2048, 4096, 8192, 16384", |
|
0 commit comments