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

New Post: MP3 Encoding feature

$
0
0

Hi, have you ever thought about implementing encoding algorithm for mp3 in managed code? Maybe you already have it in your backlog?

it can be useful in Silverlight 4/WP7 projects, which cannot use native live (like lame)


New Post: MP3 Encoding feature

$
0
0

I'd love to do this, but it would be a huge undertaking. Keep hoping someone else will do it one day. If there was even a Java version I could port it. I've done unmanaged decoding, but encoding is a much bigger task

Commented Issue: WasapiCapture not reusable [16341]

$
0
0
I've been writing an app that records chunks of input audio to multiple files, with gaps between, but I discovered that if I try a call sequence which essentially boils down to this:

WasapiCapture client = new WasapiCapture();
// set up output processor for file 1
client.StartRecording();
// wait for end of content for file 1
client.StopRecording();
// set up output processor for file 2
client.StartRecording();





then the second StartRecording() fails inside InitializeCaptureDevice() at the call to audioClient.Initialize()

I was able to work around this by disposing of my WasapiCapture client and constructing a new one each time, because my system load was low enough that I didn't care about the needless thread destroy/create and whatever the overhead of fetching a new IAudioClient
might be. In other circumstances all that unnecessary work might be a problem though.

I see the MS documentation for IAudioClient states that "the client must successfully call
Initialize once and only once to initialize the audio stream between the client and the device" (italics mine), so I'm thinking some strategy where NAudio remembers the WaveFormat it uses in a call to audioClient.Initialize() and on
subsequent calls to InitializeCaptureDevice(), throws if a recording is active, does nothing if the WaveFormat has not changed, or disposes the old audioClient and initializes a new one if the WaveFormat has changed. Doing something like that would probably
also need some modification to CaptureThread so that it didn't exit until the WasapiCapture object is disposed.
Comments: Modded the app that ran into this issue in the first place to use my fork and reuse the same capture object, and it worked fine; was able to plough through a dozen different recordings. Was running in the VS debugger so I was able to confirm from the output that it was using the same recording thread all through, and that the thread exited correctly at the end when the capture object was destroyed.

New Post: MP3 Encoding feature

$
0
0

What's the deal with patents on mp3? I know Fedora linux doesn't include mp3 encoding or even decoding because of patent encumbrances, although Fedora does appear to be extremely strict about what they include as a base package. Did you manage to get a license for the decoder that's already in NAudio, or are you just taking advantage of the fact the patent owners no longer pursue authors of free-beer mp3 decoders? I believe it's still the case that anyone distributing encoders in binary form, even if for free, should probably expect a cease & desist order in their future. There's a reason lame can only be downloaded from sourceforge in source form.

To support Silverlight / WP7, I would think the ability to make use of Microsoft's WMA Encoder would make more sense, since that can be used for free by anyone with a valid Windows license.

Now Ogg support is a different matter...

New Post: MP3 Encoding feature

$
0
0

NAudio uses the MP3 decoder that comes with Windows, which MS has already paid the license fee for. WMA Encoding is possible (I've done it once for a commercial project), but the API is ridiculously overcoomplicated. Fully managed ogg encoding would be a nice idea.

New Post: WAV &or MP3 separate left & right channel view

$
0
0

Hi, NAudio experts ;)

I'm new to this library, and I nedd to create application that shows separate left and right channel of a wave or mp3 audio while recording or playing sound.

I managed to draw signal on waveformPainter control while recording but i don't know how to show left and right channel on a diferent views while playing, also I managed to draw signal on one WaveViewer control that shows signal of both channels.

Since this application in future will need to handle fft on signal and all sort of other things (e.g. effects), I need access to this channels but I don't know where to start.

So if anyone could help me or provide me with information (example) how to do that I would be very gratefull.

thx

Source code checked in, #501c949719f2

$
0
0
Merging in Pull Request from Nikolaos Georgiou for Id3v2 creation

New Post: Problem Converting To GSM610

$
0
0

I don't suppose you could shed a little more light on this please?  I'm trying to do the same PCM to GSM conversion and get exactly the same error.

From what I can gather, the issue is with moving from a block align of 2 to 65, but I don't know how to deal with this.  Do I need to create a new class deriving from WaveStream to pass to the conversion stream? 

My ultimate goal is to insert a period of silence into a GSM file, so what I'm doing is converting to PCM, inserting the appropriate empty bytes and then converting back to GSM.  Is there a better way to do this?

Thanks,
Chris


New Post: Problem Converting To GSM610

$
0
0

Here is the full source code for CreateWaveFile:

        public static void CreateWaveFile(string filename, IWaveProvider sourceProvider)
        {
            using (WaveFileWriter writer = new WaveFileWriter(filename, sourceProvider.WaveFormat))
            {
                byte[] buffer = new byte[sourceProvider.WaveFormat.AverageBytesPerSecond * 4];
                while (true)
                {
                    int bytesRead = sourceProvider.Read(buffer, 0, buffer.Length);
                    if (bytesRead == 0)
                        break;
                    writer.Write(buffer, 0, bytesRead);
                }
            }
        }

The problem is simply that the size of the buffer ought to be a multiple of 65. Make it 65000 or something. Then it should work.

As for how to insert silence, your way is fine. The only alternative is to create one 65 byte block of GSM silence (don't know what that looks like), and insert those blocks. However, even that may produce artefacts if the GSM codec stores state between consecutive blocks.

New Post: Problem Converting To GSM610

$
0
0

Thanks for the quick reply.

Where should I be calling that code then?  Trying the example you posted in reply to jonny, I get the exception when initialising the conversion stream.  It doesn't ever get as far as calling CreateWaveFile.

New Post: Problem Converting To GSM610

$
0
0

OK, are you definitely using the Gsm610WaveFormat class?

Also, before you can go to GSM 610, you already need to have resampled to 8kHz, if your audio was originally at a higher sample rate

New Post: Problem Converting To GSM610

$
0
0

Yes, I'm using the Gsm610WaveFormat class and I've already ensured the PCM is at 8kHz.

I've also tried generating the PCM file myself so that I know it's at the correct sample rate.  Should the following work?

 

string pcmFilepath = @"D:\Temp\GeneratedPCM.wav";
string gsmFilepath = @"D:\Temp\ConvertedGSM.wav";

int sampleRate = 8000;
WaveFormat pcmFormat = new WaveFormat(sampleRate, 16, 1);

// Generate 8 kHz PCM audio:
using (WaveFileWriter pcmWriter = new WaveFileWriter(pcmFilepath, pcmFormat))
{
   int frequency = 440;
   short amplitude = 10000;
   int duration = 2;
   double omega = frequency * 2 * Math.PI / sampleRate;

   short[] buffer = new short[100];
   int bufferPos = 0;

   for (int i = 0; i < sampleRate * duration; i++)
   {
       short sample = (short)(amplitude * Math.Sin((double)i * omega));
       buffer.SetValue(sample, bufferPos);
       bufferPos++;

       if (bufferPos == buffer.Length)
       {
           pcmWriter.WriteSamples(buffer, 0, buffer.Length);
           bufferPos = 0;
       }
   }
}

// Convert to GSM:
using (WaveFileReader reader = new WaveFileReader(pcmFilepath))
{
   using (WaveFormatConversionStream converter = new WaveFormatConversionStream(new Gsm610WaveFormat(), reader))
   {
       WaveFileWriter.CreateWaveFile(gsmFilepath, converter);
   }
}

Thanks for helping by the way!

New Post: Problem Converting To GSM610

$
0
0

there is an ACM demo in the NAudioDemo app that will tell you what ACM codecs you have installed on your system. Check that there is actually a GSM one there. What version of Windows are you running on?

New Post: Problem Converting To GSM610

$
0
0

I've tried that and I can see the corresponding entry for the GSM format I'm trying to convert to:

===========================================
Format Tag 1: GSM 6.10
   Standard Format Count: 4
   Support Flags: Codec
   Format Tag: Gsm610, Format Size: 20
   Formats:
   ===========================================

.....

   Format 0: 8.000 kHz, Mono
      FormatTag: Gsm610, Support Flags: Codec
      WaveFormat: Gsm610 8000Hz Channels: 1 Bits: 0 Block Align: 65, AverageBytesPerSecond: 1625 (13.0 kbps), Extra Size: 2
   ===========================================

 

I'm running Windows 7 Pro, 32-bit.  If it makes any difference, I can save as GSM using GoldWave audio editor.

New Post: Problem Converting To GSM610

$
0
0

Can you convert your PCM file using the Encode button in the NAudioDemo app?


New Post: Problem Converting To GSM610

$
0
0

Nope.  I get the same "AcmNotPossible calling acmStreamSize" error.

New Post: Problem Converting To GSM610

$
0
0

and that is in the WaveFormatConversionStream constructor? or in CreateWaveFile?

New Post: Problem Converting To GSM610

$
0
0

That's in the constructor again.

Stack trace:

at NAudio.MmException.Try(MmResult result, String function) in D:\\VS Projects\\NAudio 1.5\\NAudio\\Wave\\MmeInterop\\MmException.cs:line 39
at NAudio.Wave.Compression.AcmStream.SourceToDest(Int32 source) in D:\\VS Projects\\NAudio 1.5\\NAudio\\Wave\\Compression\\AcmStream.cs:line 75
at NAudio.Wave.WaveFormatConversionStream.SourceToDest(Int32 source) in D:\\VS Projects\\NAudio 1.5\\NAudio\\Wave\\WaveStreams\\WaveFormatConversionStream.cs:line 55
at NAudio.Wave.WaveFormatConversionStream..ctor(WaveFormat targetFormat, WaveStream sourceStream) in D:\\VS Projects\\NAudio 1.5\\NAudio\\Wave\\WaveStreams\\WaveFormatConversionStream.cs:line 46
at NAudioDemo.AcmPanel.EncodeFile() in D:\\VS Projects\\NAudio 1.5\\NAudioDemo\\AcmDemo\\AcmPanel.cs:line 126
at NAudioDemo.AcmPanel.buttonEncode_Click(Object sender, EventArgs args) in D:\\VS Projects\\NAudio 1.5\\NAudioDemo\\AcmDemo\\AcmPanel.cs:line 33"

New Post: Problem Converting To GSM610

$
0
0

OK, will have to try to debug this one myself. I suspect sending in non block aligned values is confusing it

New Post: Problem Converting To GSM610

$
0
0

OK, fixed the bug and checked in this evening. You can build your own copy of NAudio, or if you know how to use NuGet to get a pre-release version, you can get it from the NuGet gallery:

https://nuget.org/packages/NAudio/1.5.3-beta

Viewing all 5831 articles
Browse latest View live