Quantcast
Channel: NAudio
Viewing all 5831 articles
Browse latest View live

New Post: where is Mp3Frame::FrameLengthMs()

$
0
0

Hi,

I had one project, which used this method. I don't have clue which version of NAudio was used in this project.

But when I tried to check the source code of this method, I couldn't find this method from NAudio 1.5 release. 

 

Could anyone let me know which version of release has this method? Why it is removed from current release?

Thanks in advance!


New Post: where is Mp3Frame::FrameLengthMs()

$
0
0

no idea when this was removed. I have no memory of it. You could always check the source control history. It's easily calculated using SampleCount and SampleRate

Mark

New Post: where is Mp3Frame::FrameLengthMs()

$
0
0

Hi Mark,

Sorry for rockie question. I just started audio programming. Don't really know the concepts yet. Could you please tell me how to use SampleCount and SampleRate to calculate to get the same value as FrameLengthMs() returned.

Thanks!

New Post: where is Mp3Frame::FrameLengthMs()

$
0
0

var milliseconds = (SampleCount * 1000.0) / SampleRate

New Post: where is Mp3Frame::FrameLengthMs()

New Post: Can WaveFormatConversionStream(WaveFormat targetFormat, WaveStream sourceStream) be used to covert from wav to mp3

$
0
0

My case is to fade in/out a mp3 file. Searched the forum, looks I need to conver it to wav first, after editing, I need to convert the wav back to mp3 again.

I am reading the APIs from NAudio. Wondering if this API can be used for this purpose.

Thanks!

New Post: A working MIDI tutorial, please?

$
0
0

sorry the tutorial isn't working for you. I'm afraid that one wasn't written by me, so I am not in a position to update it. All my tutorials are available on my blog at http://mark-dot-net.blogspot.co.uk/search/label/NAudio. I'm afraid I haven't done much on MIDI but I will bear it in mind for future blog posts. The best thing for now is to look at the source code for the NAudioDemo which contains simple working examples of NAudio in action.

Mark

New Post: Can WaveFormatConversionStream(WaveFormat targetFormat, WaveStream sourceStream) be used to covert from wav to mp3

$
0
0

Yes, you can use NAudio to do most of this. The AudioFileReader class will read the MP3 file. Then use FadeInOutSampleProvider to perform the fade. Then you would convert to WAV file using WaveFileWriter and SampleToWaveProvider16. Finally, you'd need to use something like LAME.exe to re-encode as MP3

Mark


New Post: Can WaveFormatConversionStream(WaveFormat targetFormat, WaveStream sourceStream) be used to covert from wav to mp3

$
0
0
markheath wrote:

Yes, you can use NAudio to do most of this. The AudioFileReader class will read the MP3 file. Then use FadeInOutSampleProvider to perform the fade. Then you would convert to WAV file using WaveFileWriter and SampleToWaveProvider16. Finally, you'd need to use something like LAME.exe to re-encode as MP3

Mark

Hi Mark,

Which version of release have the APIs you pointed out? I am reading NAudio v1.5 release. But I couldn't find 

. FadeInOutSampleProvider

SampleToWaveProvider16 (Is it NAudio.Wave.WaveProvider16?)

As both wav and mp3 are from WaveStream, can I use WaveFormatConversionStream to convert wav to mp3? I like to stick to NAudio only if possible.

Thanks!

Valimo

New Post: A working MIDI tutorial, please?

$
0
0

No need to apologize! Thanks for all of the great work! I'll grab an example.

Thanks

New Post: Playlist in NAudio

$
0
0

Hello everyone,

Now I'm working on an audioplayer project, that requires playing multiple audio files one by one, just like some kind of playlist. For playing it uses DirectSoundOut.

Well, at this point I don't know how to implement this. Should I use event like playbackStopped (when current song has ended) and recreate output stream? Or there is simplier way to do this?

Please, help.

New Comment on "MP3"

$
0
0
I created a player using VB.NET. It was very easy to follow your example. It only plays MP3 files. What other file types are supported/allowed? I am hoping for M4A and AIFF; WMA would be nice but not essential.

New Comment on "MP3"

$
0
0
To answer my own question: MP3, WMA, and AIFF are possible; no sign of M4A. Here is my version of CreateInputStream: Private Function CreateInputStream(ByRef fileName As String) As WaveStream Dim inputStream As WaveChannel32 Dim fReader As WaveStream If fileName.EndsWith(".aiff") Then fReader = New AiffFileReader(fileName) ElseIf fileName.EndsWith(".mp3") Then fReader = New Mp3FileReader(fileName) ElseIf fileName.EndsWith(".wma") Then fReader = New WMAFileReader(fileName) Else Throw New InvalidOperationException("Invalid file extension") End If inputStream = New WaveChannel32(fReader) Return inputStream End Function

Commented Issue: MP3FileReader.Length property is not correct [16359]

$
0
0
I use the MP3FileReader to open a mp3 which is in the attachments , the total time returned is 05:09. And I use the NAudio demo to play this mp3, the sound is slower than expected.

But if I use other players like foobar to open this mp3, the total time is 03:41, and sounds normal.

I think there should be a bug in this class.
Comments: NAudio now throws an exception to show that this is considered an invalid file and cannot be played. A separate issue can be raised as a feature request if needed

Commented Issue: Streaming MP3, wrong bitrate. creates incorrect sound [16328]

$
0
0
So, i was streaming some Mp3's and noticed that some song were being play'd to fast and some to slow.
After checking what bitrate the Mp3Frame were returning, i found that some songs got 128kbps when they in face were 222kbps, and other got 160kbps when they in face were 128kbps.

After digging around in the code, i found that there are some problems reading the MPEG header, as it requires the header to be at the first bytes of the song.
That's not always the case. So i got to work and have made a solution, that streams around 1k at the time and scans is for the header.
It works wonderful and i'll try to replace the original method in the following days, if that's alright! =)

Sorry for any possible spelling or grammar issues =)
Comments: Unfortunately there is not enough information here for me to investigate this bug. Please attach an MP3 file that demonstrates the problem

Commented Issue: Streaming MP3-files, error decompressing last frame [16322]

$
0
0
Hi!

I'm trying to make a program that can stream audio from a server.
I all works fine, until i get to the last frame, then i get the following error:

Object reference not set to an instance of an object.

The code that returns the error is:
Array.Copy(frame.RawData, conversionStream.SourceBuffer, frame.FrameLength);

and is fund in "AcmMp3FrameDecompressor.cs" in "DecompressFrame"

I know that is happen because i stream a bit ahead to i can listen to the song directly from the stream.
But i don't know what i can do about it..
Here is the code i'm using to get frame from stream and decompress the frame.

IMp3FrameDecompressor decompressor = null;
try
{

var readFullyStream = new ReadFullyStream(responseStream);
do
{
if (bufferedWaveProvider != null && bufferedWaveProvider.BufferLength - bufferedWaveProvider.BufferedBytes < bufferedWaveProvider.WaveFormat.AverageBytesPerSecond / 4)
{
Console.WriteLine("Buffer getting full, taking a break");
Thread.Sleep(500);
}
else
{
Mp3Frame frame = null;
try
{
frame = Mp3Frame.LoadFromStream(readFullyStream);
}
catch (EndOfStreamException)
{
this.fullyDownloaded = true;
// reached the end of the MP3 file / stream
break;
}
catch (WebException)
{
// probably we have aborted download from the GUI thread
break;
}
if (decompressor == null)
{
// don't think these details matter too much - just help ACM select the right codec
// however, the buffered provider doesn't know what sample rate it is working at
// until we have a frame
WaveFormat waveFormat = new Mp3WaveFormat(frame.SampleRate, frame.ChannelMode == ChannelMode.Mono ? 1 : 2, frame.FrameLength, frame.BitRate);
decompressor = new AcmMp3FrameDecompressor(waveFormat);
this.bufferedWaveProvider = new BufferedWaveProvider(decompressor.OutputFormat);
this.bufferedWaveProvider.BufferDuration = TimeSpan.FromSeconds(20); // allow us to get well ahead of ourselves
//this.bufferedWaveProvider.BufferedDuration = 250;
}
int decompressed = decompressor.DecompressFrame(frame, buffer, 0);
//Debug.WriteLine(String.Format("Decompressed a frame {0}", decompressed));
bufferedWaveProvider.AddSamples(buffer, 0, decompressed);

}

} while (playbackState != StreamingPlaybackState.Stopped);
Console.WriteLine("Exiting");
// was doing this in a finally block, but for some reason
// we are hanging on response stream .Dispose so never get there
decompressor.Dispose();
}

finally
{
if (decompressor != null)
{
decompressor.Dispose();
}
}

Hope this information helps :)
Comments: this is because frame is null, which can happen. If you get a null frame, this means you have reached the end of your stream without finding another MP3 frame. Don't call DecompressFrame in this instance

Source code checked in, #68fa6828b5a6

$
0
0
AcmMp3FrameDecompressor better exception if null frame passed in (see issue 16322)

Edited Issue: Streaming MP3-files, error decompressing last frame [16322]

$
0
0
Hi!

I'm trying to make a program that can stream audio from a server.
I all works fine, until i get to the last frame, then i get the following error:

Object reference not set to an instance of an object.

The code that returns the error is:
Array.Copy(frame.RawData, conversionStream.SourceBuffer, frame.FrameLength);

and is fund in "AcmMp3FrameDecompressor.cs" in "DecompressFrame"

I know that is happen because i stream a bit ahead to i can listen to the song directly from the stream.
But i don't know what i can do about it..
Here is the code i'm using to get frame from stream and decompress the frame.

IMp3FrameDecompressor decompressor = null;
try
{

var readFullyStream = new ReadFullyStream(responseStream);
do
{
if (bufferedWaveProvider != null && bufferedWaveProvider.BufferLength - bufferedWaveProvider.BufferedBytes < bufferedWaveProvider.WaveFormat.AverageBytesPerSecond / 4)
{
Console.WriteLine("Buffer getting full, taking a break");
Thread.Sleep(500);
}
else
{
Mp3Frame frame = null;
try
{
frame = Mp3Frame.LoadFromStream(readFullyStream);
}
catch (EndOfStreamException)
{
this.fullyDownloaded = true;
// reached the end of the MP3 file / stream
break;
}
catch (WebException)
{
// probably we have aborted download from the GUI thread
break;
}
if (decompressor == null)
{
// don't think these details matter too much - just help ACM select the right codec
// however, the buffered provider doesn't know what sample rate it is working at
// until we have a frame
WaveFormat waveFormat = new Mp3WaveFormat(frame.SampleRate, frame.ChannelMode == ChannelMode.Mono ? 1 : 2, frame.FrameLength, frame.BitRate);
decompressor = new AcmMp3FrameDecompressor(waveFormat);
this.bufferedWaveProvider = new BufferedWaveProvider(decompressor.OutputFormat);
this.bufferedWaveProvider.BufferDuration = TimeSpan.FromSeconds(20); // allow us to get well ahead of ourselves
//this.bufferedWaveProvider.BufferedDuration = 250;
}
int decompressed = decompressor.DecompressFrame(frame, buffer, 0);
//Debug.WriteLine(String.Format("Decompressed a frame {0}", decompressed));
bufferedWaveProvider.AddSamples(buffer, 0, decompressed);

}

} while (playbackState != StreamingPlaybackState.Stopped);
Console.WriteLine("Exiting");
// was doing this in a finally block, but for some reason
// we are hanging on response stream .Dispose so never get there
decompressor.Dispose();
}

finally
{
if (decompressor != null)
{
decompressor.Dispose();
}
}

Hope this information helps :)

Commented Issue: Streaming MP3-files, error decompressing last frame [16322]

$
0
0
Hi!

I'm trying to make a program that can stream audio from a server.
I all works fine, until i get to the last frame, then i get the following error:

Object reference not set to an instance of an object.

The code that returns the error is:
Array.Copy(frame.RawData, conversionStream.SourceBuffer, frame.FrameLength);

and is fund in "AcmMp3FrameDecompressor.cs" in "DecompressFrame"

I know that is happen because i stream a bit ahead to i can listen to the song directly from the stream.
But i don't know what i can do about it..
Here is the code i'm using to get frame from stream and decompress the frame.

IMp3FrameDecompressor decompressor = null;
try
{

var readFullyStream = new ReadFullyStream(responseStream);
do
{
if (bufferedWaveProvider != null && bufferedWaveProvider.BufferLength - bufferedWaveProvider.BufferedBytes < bufferedWaveProvider.WaveFormat.AverageBytesPerSecond / 4)
{
Console.WriteLine("Buffer getting full, taking a break");
Thread.Sleep(500);
}
else
{
Mp3Frame frame = null;
try
{
frame = Mp3Frame.LoadFromStream(readFullyStream);
}
catch (EndOfStreamException)
{
this.fullyDownloaded = true;
// reached the end of the MP3 file / stream
break;
}
catch (WebException)
{
// probably we have aborted download from the GUI thread
break;
}
if (decompressor == null)
{
// don't think these details matter too much - just help ACM select the right codec
// however, the buffered provider doesn't know what sample rate it is working at
// until we have a frame
WaveFormat waveFormat = new Mp3WaveFormat(frame.SampleRate, frame.ChannelMode == ChannelMode.Mono ? 1 : 2, frame.FrameLength, frame.BitRate);
decompressor = new AcmMp3FrameDecompressor(waveFormat);
this.bufferedWaveProvider = new BufferedWaveProvider(decompressor.OutputFormat);
this.bufferedWaveProvider.BufferDuration = TimeSpan.FromSeconds(20); // allow us to get well ahead of ourselves
//this.bufferedWaveProvider.BufferedDuration = 250;
}
int decompressed = decompressor.DecompressFrame(frame, buffer, 0);
//Debug.WriteLine(String.Format("Decompressed a frame {0}", decompressed));
bufferedWaveProvider.AddSamples(buffer, 0, decompressed);

}

} while (playbackState != StreamingPlaybackState.Stopped);
Console.WriteLine("Exiting");
// was doing this in a finally block, but for some reason
// we are hanging on response stream .Dispose so never get there
decompressor.Dispose();
}

finally
{
if (decompressor != null)
{
decompressor.Dispose();
}
}

Hope this information helps :)
Comments: I've improved the exception to make the cause of this more obvious

Edited Issue: 1.5.9 build from source naudiodemo crash on launch [16344]

$
0
0
just download latest source 1.5.9 buid release any cpu
run naudiodemo.exe from bin release and crush
my os win 7 ultimate x64 sp1
any idea?
Problem signature:
Problem Event Name: APPCRASH
Application Name: NAudioDemo.exe
Application Version: 1.0.1.0
Application Timestamp: 4f7c4901
Fault Module Name: KERNELBASE.dll
Fault Module Version: 6.1.7601.17651
Fault Module Timestamp: 4e21213c
Exception Code: e0434f4d
Exception Offset: 000000000000cacd
OS Version: 6.1.7601.2.1.0.256.1
Locale ID: 1037

Viewing all 5831 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>