@@ -188,7 +188,7 @@ public void Reset()
188188 EmphasisID = MPEG_EMPHASIS_UNKNOWN ;
189189 }
190190
191- public void LoadFromByteArray ( byte [ ] data )
191+ public void LoadFromByteArray ( ReadOnlySpan < byte > data )
192192 {
193193 VersionID = ( byte ) ( ( data [ 1 ] >> 3 ) & 3 ) ;
194194 LayerID = ( byte ) ( ( data [ 1 ] >> 1 ) & 3 ) ;
@@ -412,13 +412,13 @@ private static VBRData getXingInfo(Stream source)
412412 private static VBRData getFhGInfo ( Stream source )
413413 {
414414 VBRData result = new VBRData ( ) ;
415- byte [ ] data = new byte [ 9 ] ;
415+ Span < byte > data = stackalloc byte [ 9 ] ;
416416
417417 // Extract FhG VBR info at given position
418418 result . Found = true ;
419419 result . ID = VBR_ID_FHG . ToCharArray ( ) ;
420420 source . Seek ( 5 , SeekOrigin . Current ) ;
421- if ( source . Read ( data , 0 , 9 ) < 9 ) return result ;
421+ if ( source . Read ( data ) < 9 ) return result ;
422422
423423 result . Scale = data [ 0 ] ;
424424 result . Bytes =
@@ -439,12 +439,12 @@ private static VBRData getFhGInfo(Stream source)
439439
440440 private static VBRData findVBR ( Stream source , long position )
441441 {
442- byte [ ] data = new byte [ 4 ] ;
442+ Span < byte > data = stackalloc byte [ 4 ] ;
443443
444444 // Check for VBR header at given position
445445 source . Seek ( position , SeekOrigin . Begin ) ;
446446
447- if ( 4 == source . Read ( data , 0 , 4 ) )
447+ if ( 4 == source . Read ( data ) )
448448 {
449449 string vbrId = Utils . Latin1Encoding . GetString ( data ) ;
450450 switch ( vbrId )
@@ -481,13 +481,13 @@ public static bool HasValidFrame(Stream source)
481481 /// <summary>
482482 /// Find next MPEG frame starting from a given MPEG frame
483483 /// </summary>
484- private static FrameHeader findNextFrame ( Stream source , FrameHeader startingFrame , byte [ ] buffer )
484+ private static FrameHeader findNextFrame ( Stream source , FrameHeader startingFrame , Span < byte > buffer )
485485 {
486486 FrameHeader result = new FrameHeader ( ) ;
487487 result . Reset ( ) ;
488488
489489 source . Seek ( startingFrame . Offset + startingFrame . Size , SeekOrigin . Begin ) ;
490- if ( source . Read ( buffer , 0 , 4 ) < 4 || ! IsValidFrameHeader ( buffer ) ) return result ;
490+ if ( source . Read ( buffer ) < 4 || ! IsValidFrameHeader ( buffer ) ) return result ;
491491
492492 result . LoadFromByteArray ( buffer ) ;
493493 result . Offset = source . Position - 4 ;
@@ -506,10 +506,10 @@ private static FrameHeader findNextFrame(Stream source, FrameHeader startingFram
506506 private static FrameHeader findFirstFrame ( Stream source , ref VBRData oVBR , SizeInfo sizeInfo )
507507 {
508508 FrameHeader result = new FrameHeader ( ) ;
509- byte [ ] buffer = new byte [ 4 ] ;
509+ Span < byte > buffer = stackalloc byte [ 4 ] ;
510510 long sourceOffset = source . Position ;
511511
512- if ( source . Read ( buffer , 0 , 4 ) < 4 ) return result ;
512+ if ( source . Read ( buffer ) < 4 ) return result ;
513513 result . Found = IsValidFrameHeader ( buffer ) ;
514514
515515 /*
@@ -532,7 +532,7 @@ private static FrameHeader findFirstFrame(Stream source, ref VBRData oVBR, SizeI
532532 // If padding uses 0xFF bytes, take one step back in case header lies there
533533 if ( 0xFF == buffer [ 0 ] ) source . Seek ( - 1 , SeekOrigin . Current ) ;
534534
535- if ( source . Read ( buffer , 0 , 4 ) < 4 ) return result ;
535+ if ( source . Read ( buffer ) < 4 ) return result ;
536536 result . Found = IsValidFrameHeader ( buffer ) ;
537537 }
538538
@@ -550,7 +550,7 @@ private static FrameHeader findFirstFrame(Stream source, ref VBRData oVBR, SizeI
550550 while ( 0xFF != source . ReadByte ( ) && source . Position < limit ) { /* just advance the stream */ }
551551
552552 source . Seek ( - 1 , SeekOrigin . Current ) ;
553- if ( source . Read ( buffer , 0 , 4 ) < 4 ) break ;
553+ if ( source . Read ( buffer ) < 4 ) break ;
554554 result . Found = IsValidFrameHeader ( buffer ) ;
555555 }
556556
@@ -633,7 +633,7 @@ private static FrameHeader findFirstFrame(Stream source, ref VBRData oVBR, SizeI
633633
634634 private static FrameParsingResult parseExactAudioDataSize ( BufferedBinaryReader reader , FrameHeader firstFrame )
635635 {
636- byte [ ] buffer = new byte [ 4 ] ;
636+ Span < byte > buffer = stackalloc byte [ 4 ] ;
637637 var bitrates = new List < float > { firstFrame . BitRate } ;
638638 long topOffset = 0 ;
639639 reader . Seek ( firstFrame . Offset , SeekOrigin . Begin ) ;
0 commit comments