Class for reading from MP3 files.
More...
|
| 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.
|
|
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.
|
|
|
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.
|
|
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)
|
|
Class for reading from MP3 files.
◆ Mp3FileReaderBase() [1/3]
NAudio.Wave.Mp3FileReaderBase.Mp3FileReaderBase |
( |
string | mp3FileName, |
|
|
FrameDecompressorBuilder | frameDecompressorBuilder ) |
|
inline |
Supports opening a MP3 file.
- Parameters
-
mp3FileName | MP3 File name |
frameDecompressorBuilder | Factory 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
-
inputStream | The incoming stream containing MP3 data |
frameDecompressorBuilder | Factory method to build a frame decompressor |
◆ Mp3FileReaderBase() [3/3]
NAudio.Wave.Mp3FileReaderBase.Mp3FileReaderBase |
( |
Stream | inputStream, |
|
|
FrameDecompressorBuilder | frameDecompressorBuilder, |
|
|
bool | ownInputStream ) |
|
inlineprotected |
◆ 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.
◆ 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
-
disposing | True 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()
Function that can create an MP3 Frame decompressor.
- Parameters
-
mp3Format | A 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
-
sampleBuffer | The buffer to store the read bytes. |
offset | The zero-based byte offset in sampleBuffer at which to begin storing the data read from the current stream. |
numBytes | The 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.
◆ 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
-
readData | A 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.
◆ ReadNextFrame() [2/2]
Mp3Frame NAudio.Wave.Mp3FileReaderBase.ReadNextFrame |
( |
bool | readData | ) |
|
|
inlineprivate |
Reads the next mp3 frame.
- Returns
- Next mp3 frame, or null if EOF
◆ 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.
◆ ValidateFrameFormat()
void NAudio.Wave.Mp3FileReaderBase.ValidateFrameFormat |
( |
Mp3Frame | frame | ) |
|
|
inlineprivate |
Validates the format of the MP3 frame.
- Parameters
-
frame | The MP3 frame to be validated. |
- Exceptions
-
InvalidOperationException | Thrown 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.
◆ 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
◆ 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 |
◆ Id3v1Tag
byte [] NAudio.Wave.Mp3FileReaderBase.Id3v1Tag |
|
get |
◆ Id3v2Tag
Id3v2Tag NAudio.Wave.Mp3FileReaderBase.Id3v2Tag |
|
get |
◆ 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
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 |
◆ WaveFormat
override WaveFormat NAudio.Wave.Mp3FileReaderBase.WaveFormat |
|
get |
◆ XingHeader
XingHeader NAudio.Wave.Mp3FileReaderBase.XingHeader |
|
get |
The documentation for this class was generated from the following file:
- /Users/sumansaurabh/Documents/my-startup/xeno-rat/Plugins/LiveMicrophone/lib/NAudio.Core/Wave/WaveStreams/Mp3FileReaderBase.cs