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

Commented Issue: Destination array was not long anough when reading mp3 file whit NAudio [16345]

$
0
0
I've got this code

static void Main(string[] args)
{
try
{
Mp3FileReader reader = new Mp3FileReader(@"C:\testAudio.mp3");
long count = reader.Length;
if (count <= int.MaxValue)
{
byte[] info = new byte[count];
reader.Read(info, 0, (int)count);
Console.WriteLine("Succesfull read");
}
else
Console.WriteLine("Could not read");
}
catch(Exception ex)
{
Console.WriteLine(ex);
}
}

that prints out the following exception message

System.ArgumentException: Destination array was not long enough. Check destIndex and length, and the array's lower bounds.
at System.Array.Copy(Array sourceArray, Int32 sourceIndex, Array destinationArray, Int32 destinationIndex, Int32 length, Boolean reliable)
at System.Array.Copy(Array sourceArray, Int32 sourceIndex, Array destinationArray, Int32 destinationIndex, Int32 length)
at NAudio.Wave.AcmMp3FrameDecompressor.DecompressFrame(Mp3Frame frame, Byte[] dest, Int32 destOffset) in C:\NAudio-Source\NAudio\FileFormats\Mp3\Mp3FrameDecompressor.cs:line 50
at NAudio.Wave.Mp3FileReader.Read(Byte[] sampleBuffer, Int32 offset, Int32 numBytes) in C:\NAudio-Source\NAudio\Wave\WaveStreams\Mp3FileReader.cs:line 338
at Tester.Program.Main(String[] args) in C:\Tester\Program.cs:line 30

I've dowloaded NAudio code and I've been debugging it but I can't find the cause of the error, although, as you can see on the stack trace is in *NAudio-Source\NAudio\FileFormats\Mp3\Mp3FrameDecompressor.cs:line 50*

¿Am I doing something wrong? By the way, it only happens with a few mp3 files, others are read just fine. I'm attaching one of the files that can't be read

Thanx
Comments: Hi! Is there any development regarding this issue? I'm having the same issues that are represented here, I think all of them: 1 - Listening to the file in Windows Media Player either works flawlessly (in some files) or sounds, in fact, like a glitch (in the same frames where NAudio crashes); 2 - Of course I try-catched the Read method in NAudio, but that creates a silence inside the audio, as you would expect; 3 - If I play the file in NAudio once from beginning to end, the glitches sound much more audible and clear; however, if I repeat the problem region over and over again those glitches start to fade away, so I think that this issue might have something to do with the read buffer after all. Thanks in advance! Bruno Coelho

Commented Issue: Destination array was not long anough when reading mp3 file whit NAudio [16345]

$
0
0
I've got this code

static void Main(string[] args)
{
try
{
Mp3FileReader reader = new Mp3FileReader(@"C:\testAudio.mp3");
long count = reader.Length;
if (count <= int.MaxValue)
{
byte[] info = new byte[count];
reader.Read(info, 0, (int)count);
Console.WriteLine("Succesfull read");
}
else
Console.WriteLine("Could not read");
}
catch(Exception ex)
{
Console.WriteLine(ex);
}
}

that prints out the following exception message

System.ArgumentException: Destination array was not long enough. Check destIndex and length, and the array's lower bounds.
at System.Array.Copy(Array sourceArray, Int32 sourceIndex, Array destinationArray, Int32 destinationIndex, Int32 length, Boolean reliable)
at System.Array.Copy(Array sourceArray, Int32 sourceIndex, Array destinationArray, Int32 destinationIndex, Int32 length)
at NAudio.Wave.AcmMp3FrameDecompressor.DecompressFrame(Mp3Frame frame, Byte[] dest, Int32 destOffset) in C:\NAudio-Source\NAudio\FileFormats\Mp3\Mp3FrameDecompressor.cs:line 50
at NAudio.Wave.Mp3FileReader.Read(Byte[] sampleBuffer, Int32 offset, Int32 numBytes) in C:\NAudio-Source\NAudio\Wave\WaveStreams\Mp3FileReader.cs:line 338
at Tester.Program.Main(String[] args) in C:\Tester\Program.cs:line 30

I've dowloaded NAudio code and I've been debugging it but I can't find the cause of the error, although, as you can see on the stack trace is in *NAudio-Source\NAudio\FileFormats\Mp3\Mp3FrameDecompressor.cs:line 50*

¿Am I doing something wrong? By the way, it only happens with a few mp3 files, others are read just fine. I'm attaching one of the files that can't be read

Thanx
Comments: Hi! Is there any development regarding this issue? I'm having the same issues that are represented here, I think all of them: 1 - Listening to the file in Windows Media Player either works flawlessly (in some files) or sounds, in fact, like a glitch (in the same frames where NAudio crashes); 2 - Of course I try-catched the Read method in NAudio, but that creates a silence inside the audio, as you would expect; 3 - If I play the file in NAudio once from beginning to end, the glitches sound much more audible and clear; however, if I repeat the problem region over and over again those glitches start to fade away, so I think that this issue might have something to do with the read buffer after all. Thanks in advance! Bruno Coelho

New Post: Repeated Start/StopRecording does not work

$
0
0

When I start/stop recordings, while a playback is running at the same time, NAudio hangs after some time. Down below you can find a small demo that shows the effect. The test-loop is expected to loop-back recorded audio to the output device forever. But after some random record sequences no recording will take place any more and the StopRecording method call hangs.

Any idea what's wrong here? I tested with a few days old NAudio codebase, but had the same effect with the official NAudio release 1.5 too.

Norbert

 

using System;
using System.Threading;
using NAudio.Wave;

namespace NAudioRecTest
{
    class Program
    {
        static BufferedWaveProvider bufferedWaveProvider = new BufferedWaveProvider(new WaveFormat(8000, 16, 1));

        static void Main(string[] args)
        {
            IWaveIn waveIn = new WaveInEvent();
            waveIn.DataAvailable += new EventHandler<WaveInEventArgs>(waveIn_DataAvailable);

            IWavePlayer waveOut = new WaveOutEvent();
            waveOut.Init(bufferedWaveProvider);
            waveOut.Play();

            while (true)
            {
                Console.Out.WriteLine("Start recording.");
                waveIn.StartRecording();

                Thread.Sleep(1000);
                
                Console.Out.WriteLine("Stop recording.");
                waveIn.StopRecording();

                Thread.Sleep(500);
            }
        }

        static void waveIn_DataAvailable(object sender, WaveInEventArgs e)
        {
            Console.Out.WriteLine("Data available");
            bufferedWaveProvider.AddSamples(e.Buffer, 0, e.BytesRecorded);
        }
    }
}

New Post: Couple Questions

$
0
0

Hello,

Is it possible to play a wave file out of the left or right channels only, aka a balance control?

What method returns the total length of a wave file?

Thanks,

kingneb

New Post: Probably Simple

$
0
0

OK, I placed my dispose code in the Visual Basic form close event. That took care of it. As far as the crackling was concerned, that was due to the sound cards being USB and run through a hub. Those USB hubs are not a great thing for audio.

 

Anyway Thanks

New Post: 2 Output devices simultaneously?

$
0
0

Im currently trying to develop a multi room audio system and i want to accomplish this with multiple soundcards (1 for each room).

The problem is, that i can't figure out how to play one audio file on two soundcards synchronized.

Is this even possible with NAudio?

New Post: 2 Output devices simultaneously?

$
0
0

I had a similar problem and I found out that JACK could sync the clocks of multiple soundcards. But I ended up using Virtual Audio Cable to replicate the audio with all the clocks synced, because I didn't want to learn the JACK api for a small personal project.

New Post: 2 Output devices simultaneously?

$
0
0

I also discovered VAC but i want to choose the output device/devices dynamically. 


New Post: 2 Output devices simultaneously?

$
0
0

No, I'm afraid that NAudio contains nothing special to do this. You simply would have to try to sync playback to both devices yourself. This is because the Windows API's NAudio is making use of do not have any provision for this. You might find some virtual audio driver that can present multiple cards to Windows as though they were a single audio device.

New Post: Probably Simple

$
0
0

glad you found the cause in the end

Commented Issue: Destination array was not long anough when reading mp3 file whit NAudio [16345]

$
0
0
I've got this code

static void Main(string[] args)
{
try
{
Mp3FileReader reader = new Mp3FileReader(@"C:\testAudio.mp3");
long count = reader.Length;
if (count <= int.MaxValue)
{
byte[] info = new byte[count];
reader.Read(info, 0, (int)count);
Console.WriteLine("Succesfull read");
}
else
Console.WriteLine("Could not read");
}
catch(Exception ex)
{
Console.WriteLine(ex);
}
}

that prints out the following exception message

System.ArgumentException: Destination array was not long enough. Check destIndex and length, and the array's lower bounds.
at System.Array.Copy(Array sourceArray, Int32 sourceIndex, Array destinationArray, Int32 destinationIndex, Int32 length, Boolean reliable)
at System.Array.Copy(Array sourceArray, Int32 sourceIndex, Array destinationArray, Int32 destinationIndex, Int32 length)
at NAudio.Wave.AcmMp3FrameDecompressor.DecompressFrame(Mp3Frame frame, Byte[] dest, Int32 destOffset) in C:\NAudio-Source\NAudio\FileFormats\Mp3\Mp3FrameDecompressor.cs:line 50
at NAudio.Wave.Mp3FileReader.Read(Byte[] sampleBuffer, Int32 offset, Int32 numBytes) in C:\NAudio-Source\NAudio\Wave\WaveStreams\Mp3FileReader.cs:line 338
at Tester.Program.Main(String[] args) in C:\Tester\Program.cs:line 30

I've dowloaded NAudio code and I've been debugging it but I can't find the cause of the error, although, as you can see on the stack trace is in *NAudio-Source\NAudio\FileFormats\Mp3\Mp3FrameDecompressor.cs:line 50*

¿Am I doing something wrong? By the way, it only happens with a few mp3 files, others are read just fine. I'm attaching one of the files that can't be read

Thanx
Comments: hi, no active development, but the MP3 file you uploaded contains a frame at a different sample rate, which is something NAudio currently cannot handle

New Post: Audio Format Conversion

$
0
0

yes, the Mp3FileReader already does this, and there is a WmaFileReader as well in the WMA assembly if you build from source.

New Post: 2 Output devices simultaneously?

$
0
0

From VAC help file:

"...clock rates are calculated roughly because data amount is counted in portions (buffers)."

So my guess is that, you could set WaveOut of each soundcard to use multiple buffers, ie 4, and then upon receiving WOM_DATA callback, calculate the clock drift, and "lenghten" (don't know the correct audio term) the audio data slightly (using interpolation?), and feed it to the device that is lagging behind. (or shorten the audio (compress to a shorter time frame?) if one of the devices playing back too fast)

New Post: Couple Questions

New Post: DirectSoundOut support for SetVolume and so on?

$
0
0

Ok i tried to implement it by myself. The strange thing is that it only works on MTA Threads. Do you have any ideas why?


New Post: Couple Questions

$
0
0

Yes, it is possible. I would use Multiplexing wave provider (Mark posted a tutorial on his blog: http://mark-dot-net.blogspot.com/).

WaveStream class has Length property which will tell you the length in samples of the wave file.

New Post: Couple Questions

$
0
0

Legoless is right if you want to simply route signals to different outputs rather than mix the levels.

I have a feeling that WaveChannel32 has a balance/pan implementation. It would also be easy to create your own panning logic if you are using the new ISampleProvider interface

New Post: 24 bit WASAPI

$
0
0

Hello,

I had hoped to use NAudio to access raw 24 bit WASAPI audio streams in exclusive mode, but find that AudioClient.IsFormatSupported() allows only 16 bit access to my particular sound cards. Three sound cards are attached, two via USB, and all have 24-bit hardware.

Below is a partial printout of IsFormatSupported() responses for all combinations of sample rates { 192000, 96000, 48000, 44100 } and bit widths { 32, 24, 16 }. Operating system was Windows 7 x64, and the C# project was compiled for "Any CPU". Properties of all devices were set to "Allow applications to take exclusive control" and "Give exclusive applications priority".

Question: Is the 16 bit restriction something to do with my code, the NAudio library, the operating system and drivers, or the hardware?

Ian

High Definition Audio Device: Speakers

192000: 16 EXCLUSIVE

96000: 16 EXCLUSIVE

48000: 16 EXCLUSIVE

44100: 32 SHARED

44100: 24 SHARED

44100: 16 EXCLUSIVE SHARED

SB X-Fi Surround 5.1: Speaker

96000: 16 EXCLUSIVE

48000: 32 SHARED

48000: 24 SHARED

48000: 16 EXCLUSIVE SHARED

44100: 16 EXCLUSIVE

E-MU 0202 | USB: Speakers

192000: 16 EXCLUSIVE

96000: 16 EXCLUSIVE

48000: 32 SHARED

48000: 24 SHARED

48000: 16 SHARED

  

New Post: Audio Format Conversion

$
0
0

ya ya i got it mark,thanks a lot

New Post: 24 bit WASAPI

$
0
0

Update: it's not an NAudio problem. Spent this afternoon hacking a C++ version (no NAudio involved) which gives the same result.

But I would still like to know what causes the 16 bit limitation.

Ian

Viewing all 5831 articles
Browse latest View live


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