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)
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)
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
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...
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.
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
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
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.
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.
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
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); } }
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?
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.
Can you convert your PCM file using the Encode button in the NAudioDemo app?
Nope. I get the same "AcmNotPossible calling acmStreamSize" error.
and that is in the WaveFormatConversionStream constructor? or in CreateWaveFile?
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"
OK, will have to try to debug this one myself. I suspect sending in non block aligned values is confusing it
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