Xeno-rat
Loading...
Searching...
No Matches
NAudio.Wave.Mp3FileReaderBase Class Reference

Class for reading from MP3 files. More...

Inheritance diagram for NAudio.Wave.Mp3FileReaderBase:
Collaboration diagram for NAudio.Wave.Mp3FileReaderBase:

Public Member Functions

 Mp3FileReaderBase (string mp3FileName, FrameDecompressorBuilder frameDecompressorBuilder)
 Supports opening a MP3 file.
 
 Mp3FileReaderBase (Stream inputStream, FrameDecompressorBuilder frameDecompressorBuilder)
 Opens MP3 from a stream rather than a file Will not dispose of this stream itself.
 
delegate IMp3FrameDecompressor FrameDecompressorBuilder (WaveFormat mp3Format)
 Function that can create an MP3 Frame decompressor.
 
Mp3Frame ReadNextFrame ()
 Reads the next MP3 frame from the stream and advances the position by one frame.
 
override int Read (byte[] sampleBuffer, int offset, int numBytes)
 Reads a specified number of bytes from the MP3 file into the sample buffer.
 
- Public Member Functions inherited from NAudio.Wave.WaveStream
override void Flush ()
 Flushes the buffer of the current stream and causes any buffered data to be written to the underlying device.
 
override long Seek (long offset, SeekOrigin origin)
 Sets the position within the current stream.
 
override void SetLength (long length)
 Throws a NotSupportedException with the message "Can't set length of a WaveFormatString".
 
override void Write (byte[] buffer, int offset, int count)
 Throws a NotSupportedException with the message "Can't write to a WaveFormatString".
 
void Skip (int seconds)
 Skips the playback to a new position in the audio file based on the specified number of seconds.
 
virtual bool HasData (int count)
 Checks if there is data available at the current position.
 

Protected Member Functions

 Mp3FileReaderBase (Stream inputStream, FrameDecompressorBuilder frameDecompressorBuilder, bool ownInputStream)
 
override void Dispose (bool disposing)
 Releases the unmanaged resources used by the Mp3Stream, and optionally releases the managed resources.
 

Properties

Mp3WaveFormat Mp3WaveFormat [get, private set]
 The MP3 wave format (n.b. NOT the output format of this stream - see the WaveFormat property)
 
Id3v2Tag Id3v2Tag [get]
 ID3v2 tag if present.
 
byte[] Id3v1Tag [get]
 ID3v1 tag if present.
 
override long Length [get]
 This is the length in bytes of data available to be read out from the Read method (i.e. the decompressed MP3 length) n.b. this may return 0 for files whose length is unknown.
 
override WaveFormat WaveFormat [get]
 WaveStream.WaveFormat
 
override long Position [get, set]
 Stream.Position
 
XingHeader XingHeader [get]
 Xing header if present.
 
- Properties inherited from NAudio.Wave.WaveStream
WaveFormat WaveFormat [get]
 Retrieves the WaveFormat for this stream.
 
override bool CanRead [get]
 We can read from this stream.
 
override bool CanSeek [get]
 We can seek within this stream.
 
override bool CanWrite [get]
 We can't write to this stream.
 
virtual int BlockAlign [get]
 The block alignment for this wavestream. Do not modify the Position to anything that is not a whole multiple of this value.
 
virtual TimeSpan CurrentTime [get, set]
 The current position in the stream in Time format.
 
virtual TimeSpan TotalTime [get]
 Total length in real-time of the stream (may be an estimate for compressed files)
 
- Properties inherited from NAudio.Wave.IWaveProvider

Private Member Functions

void CreateTableOfContents ()
 Creates a table of contents for the MP3 file by reading the frames and populating the table of contents list.
 
void ValidateFrameFormat (Mp3Frame frame)
 Validates the format of the MP3 frame.
 
double TotalSeconds ()
 Calculates the total seconds based on the total samples and sample rate.
 
Mp3Frame ReadNextFrame (bool readData)
 Reads the next mp3 frame.
 

Private Attributes

readonly WaveFormat waveFormat
 
Stream mp3Stream
 
readonly long mp3DataLength
 
readonly long dataStartPosition
 
readonly XingHeader xingHeader
 
readonly bool ownInputStream
 
List< Mp3IndextableOfContents
 
int tocIndex
 
long totalSamples
 
readonly int bytesPerSample
 
readonly int bytesPerDecodedFrame
 
IMp3FrameDecompressor decompressor
 
readonly byte[] decompressBuffer
 
int decompressBufferOffset
 
int decompressLeftovers
 
bool repositionedFlag
 
long position
 
readonly object repositionLock = new object()
 

Detailed Description

Class for reading from MP3 files.

Constructor & Destructor Documentation

◆ Mp3FileReaderBase() [1/3]

NAudio.Wave.Mp3FileReaderBase.Mp3FileReaderBase ( string mp3FileName,
FrameDecompressorBuilder frameDecompressorBuilder )
inline

Supports opening a MP3 file.

Parameters
mp3FileNameMP3 File name
frameDecompressorBuilderFactory method to build a frame decompressor

◆ Mp3FileReaderBase() [2/3]

NAudio.Wave.Mp3FileReaderBase.Mp3FileReaderBase ( Stream inputStream,
FrameDecompressorBuilder frameDecompressorBuilder )
inline

Opens MP3 from a stream rather than a file Will not dispose of this stream itself.

Parameters
inputStreamThe incoming stream containing MP3 data
frameDecompressorBuilderFactory method to build a frame decompressor

◆ Mp3FileReaderBase() [3/3]

NAudio.Wave.Mp3FileReaderBase.Mp3FileReaderBase ( Stream inputStream,
FrameDecompressorBuilder frameDecompressorBuilder,
bool ownInputStream )
inlineprotected
Here is the call graph for this function:

Member Function Documentation

◆ CreateTableOfContents()

void NAudio.Wave.Mp3FileReaderBase.CreateTableOfContents ( )
inlineprivate

Creates a table of contents for the MP3 file by reading the frames and populating the table of contents list.

This method estimates the number of entries needed for the table of contents list based on the MP3 data length to minimize array resizing. It iterates through the MP3 frames, reading each frame and populating the table of contents list with information such as file position, sample position, sample count, and byte count. The method also validates the format of each frame and updates the total samples count. If an EndOfStreamException is encountered during frame reading, it is caught and handled without affecting the process.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Dispose()

override void NAudio.Wave.Mp3FileReaderBase.Dispose ( bool disposing)
inlineprotected

Releases the unmanaged resources used by the Mp3Stream, and optionally releases the managed resources.

Parameters
disposingTrue to release both managed and unmanaged resources; false to release only unmanaged resources.

This method disposes the Mp3Stream and the decompressor if they are not null. If disposing is true, it also disposes the managed resources.

◆ FrameDecompressorBuilder()

delegate IMp3FrameDecompressor NAudio.Wave.Mp3FileReaderBase.FrameDecompressorBuilder ( WaveFormat mp3Format)

Function that can create an MP3 Frame decompressor.

Parameters
mp3FormatA WaveFormat object describing the MP3 file format
Returns
An MP3 Frame decompressor

◆ Read()

override int NAudio.Wave.Mp3FileReaderBase.Read ( byte[] sampleBuffer,
int offset,
int numBytes )
inline

Reads a specified number of bytes from the MP3 file into the sample buffer.

Parameters
sampleBufferThe buffer to store the read bytes.
offsetThe zero-based byte offset in sampleBuffer at which to begin storing the data read from the current stream.
numBytesThe maximum number of bytes to read.
Returns
The total number of bytes read into the buffer.

This method reads a specified number of bytes from the MP3 file into the sample buffer. It uses a decompressor to decompress the frames and copy the decompressed data into the sample buffer. The method handles repositioning, warm-up frames, and purging of data as needed.

Implements NAudio.Wave.IWaveProvider.

Here is the call graph for this function:

◆ ReadNextFrame() [1/2]

Mp3Frame NAudio.Wave.Mp3FileReaderBase.ReadNextFrame ( )
inline

Reads the next MP3 frame from the stream and advances the position by one frame.

Parameters
readDataA boolean value indicating whether to read the frame data.
Returns
The next MP3 frame read from the stream, or null if the end of the stream is reached unexpectedly.

This method attempts to load the next MP3 frame from the input stream. If successful, it advances the position by one frame. If the end of the stream is reached unexpectedly, an EndOfStreamException is caught and suppressed for now, as it indicates an unexpected end of the stream halfway through a frame.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ReadNextFrame() [2/2]

Mp3Frame NAudio.Wave.Mp3FileReaderBase.ReadNextFrame ( bool readData)
inlineprivate

Reads the next mp3 frame.

Returns
Next mp3 frame, or null if EOF
Here is the call graph for this function:

◆ TotalSeconds()

double NAudio.Wave.Mp3FileReaderBase.TotalSeconds ( )
inlineprivate

Calculates the total seconds based on the total samples and sample rate.

Returns
The total seconds calculated based on the total samples and sample rate.
Here is the caller graph for this function:

◆ ValidateFrameFormat()

void NAudio.Wave.Mp3FileReaderBase.ValidateFrameFormat ( Mp3Frame frame)
inlineprivate

Validates the format of the MP3 frame.

Parameters
frameThe MP3 frame to be validated.
Exceptions
InvalidOperationExceptionThrown when the sample rate of the input frame does not match the sample rate of the MP3 wave format, or when the channel count of the input frame does not match the channel count of the MP3 wave format.

This method validates the format of the input MP3 frame by checking its sample rate and channel count against the sample rate and channel count of the MP3 wave format. If the sample rate or channel count does not match, an InvalidOperationException is thrown with a descriptive message.

Here is the caller graph for this function:

Member Data Documentation

◆ bytesPerDecodedFrame

readonly int NAudio.Wave.Mp3FileReaderBase.bytesPerDecodedFrame
private

◆ bytesPerSample

readonly int NAudio.Wave.Mp3FileReaderBase.bytesPerSample
private

◆ dataStartPosition

readonly long NAudio.Wave.Mp3FileReaderBase.dataStartPosition
private

◆ decompressBuffer

readonly byte [] NAudio.Wave.Mp3FileReaderBase.decompressBuffer
private

◆ decompressBufferOffset

int NAudio.Wave.Mp3FileReaderBase.decompressBufferOffset
private

◆ decompressLeftovers

int NAudio.Wave.Mp3FileReaderBase.decompressLeftovers
private

◆ decompressor

IMp3FrameDecompressor NAudio.Wave.Mp3FileReaderBase.decompressor
private

◆ mp3DataLength

readonly long NAudio.Wave.Mp3FileReaderBase.mp3DataLength
private

◆ mp3Stream

Stream NAudio.Wave.Mp3FileReaderBase.mp3Stream
private

◆ ownInputStream

readonly bool NAudio.Wave.Mp3FileReaderBase.ownInputStream
private

◆ position

long NAudio.Wave.Mp3FileReaderBase.position
private

◆ repositionedFlag

bool NAudio.Wave.Mp3FileReaderBase.repositionedFlag
private

◆ repositionLock

readonly object NAudio.Wave.Mp3FileReaderBase.repositionLock = new object()
private

◆ tableOfContents

List<Mp3Index> NAudio.Wave.Mp3FileReaderBase.tableOfContents
private

◆ tocIndex

int NAudio.Wave.Mp3FileReaderBase.tocIndex
private

◆ totalSamples

long NAudio.Wave.Mp3FileReaderBase.totalSamples
private

◆ waveFormat

readonly WaveFormat NAudio.Wave.Mp3FileReaderBase.waveFormat
private

◆ xingHeader

readonly XingHeader NAudio.Wave.Mp3FileReaderBase.xingHeader
private

Property Documentation

◆ Id3v1Tag

byte [] NAudio.Wave.Mp3FileReaderBase.Id3v1Tag
get

ID3v1 tag if present.

◆ Id3v2Tag

Id3v2Tag NAudio.Wave.Mp3FileReaderBase.Id3v2Tag
get

ID3v2 tag if present.

◆ Length

override long NAudio.Wave.Mp3FileReaderBase.Length
get

This is the length in bytes of data available to be read out from the Read method (i.e. the decompressed MP3 length) n.b. this may return 0 for files whose length is unknown.

◆ Mp3WaveFormat

Mp3WaveFormat NAudio.Wave.Mp3FileReaderBase.Mp3WaveFormat
getprivate set

The MP3 wave format (n.b. NOT the output format of this stream - see the WaveFormat property)

◆ Position

override long NAudio.Wave.Mp3FileReaderBase.Position
getset

Stream.Position

◆ WaveFormat

override WaveFormat NAudio.Wave.Mp3FileReaderBase.WaveFormat
get

WaveStream.WaveFormat

Implements NAudio.Wave.IWaveProvider.

◆ XingHeader

XingHeader NAudio.Wave.Mp3FileReaderBase.XingHeader
get

Xing header if present.


The documentation for this class was generated from the following file: