@@ -37,42 +37,49 @@ protected override async Task OnAfterRenderAsync(bool _)
37
37
38
38
running = true ;
39
39
40
- int bufferLength = ( int ) await Analyser . GetFftSizeAsync ( ) ;
41
- await using Uint8Array timeDomainData = await Uint8Array . CreateAsync ( JSRuntime , bufferLength ) ;
42
-
43
- while ( running )
40
+ try
44
41
{
45
- for ( int i = 0 ; i < Width ; i ++ )
42
+ int bufferLength = ( int ) await Analyser . GetFftSizeAsync ( ) ;
43
+ await using Uint8Array timeDomainData = await Uint8Array . CreateAsync ( JSRuntime , bufferLength ) ;
44
+
45
+ while ( running )
46
46
{
47
- if ( ! running )
47
+ for ( int i = 0 ; i < Width ; i ++ )
48
48
{
49
- break ;
50
- }
49
+ if ( ! running )
50
+ {
51
+ break ;
52
+ }
51
53
52
- await Analyser . GetByteTimeDomainDataAsync ( timeDomainData ) ;
54
+ await Analyser . GetByteTimeDomainDataAsync ( timeDomainData ) ;
53
55
54
- byte [ ] reading = await timeDomainData . GetAsArrayAsync ( ) ;
56
+ byte [ ] reading = await timeDomainData . GetAsArrayAsync ( ) ;
55
57
56
- double amplitude = reading . Average ( r => Math . Abs ( r - 128 ) ) / 128.0 ;
58
+ double amplitude = reading . Average ( r => Math . Abs ( r - 128 ) ) / 128.0 ;
57
59
58
- await using ( Context2D context = await canvas . GetContext2DAsync ( ) )
59
- {
60
- if ( i == 0 )
60
+ await using ( Context2D context = await canvas . GetContext2DAsync ( ) )
61
61
{
62
+ if ( i == 0 )
63
+ {
64
+ await context . FillAndStrokeStyles . FillStyleAsync ( $ "#fff") ;
65
+ await context . FillRectAsync ( 0 , 0 , Width * 10 , Height * 10 ) ;
66
+ }
67
+
62
68
await context . FillAndStrokeStyles . FillStyleAsync ( $ "#fff") ;
63
- await context . FillRectAsync ( 0 , 0 , Width * 10 , Height * 10 ) ;
64
- }
69
+ await context . FillRectAsync ( i * 10 , 0 , 10 , Height * 10 ) ;
65
70
66
- await context . FillAndStrokeStyles . FillStyleAsync ( $ "#fff") ;
67
- await context . FillRectAsync ( i * 10 , 0 , 10 , Height * 10 ) ;
71
+ await context . FillAndStrokeStyles . FillStyleAsync ( Color ) ;
72
+ await context . FillRectAsync ( i * 10 , ( Height * 10 / 2.0 ) - ( amplitude * Height * 10 ) , 10 , amplitude * 2 * Height * 10 ) ;
73
+ }
68
74
69
- await context . FillAndStrokeStyles . FillStyleAsync ( Color ) ;
70
- await context . FillRectAsync ( i * 10 , ( Height * 10 / 2.0 ) - ( amplitude * Height * 10 ) , 10 , amplitude * 2 * Height * 10 ) ;
75
+ await Task . Delay ( 1 ) ;
71
76
}
72
-
73
- await Task . Delay ( 1 ) ;
74
77
}
75
78
}
79
+ catch ( Exception e )
80
+ {
81
+ Console . WriteLine ( e . Message ) ;
82
+ }
76
83
}
77
84
78
85
public void Dispose ( )
0 commit comments