My goal is to mix 2 audio files that is one voice and one background music. For mixing I am using NAudio.
The problem is I am getting following exception while reading mp3 file using NAudio's Mp3FileReader.
DllImport cannot be used on user-defined methods
I am using NAudio in Windows Phone 8.1 Silverlight app project. I am not sure if NAudio is useable on WP Silverlight app if its useable then please help by providing a code example or suggest any other library or custom implementation to mix 2 audio files.
No, I'm afraid NAudio is not usable on Silverlight, as it makes lots of calls into Windows APIs which you can't do in Silverlight. You can take a look at the NAudio NLayer project which offers fully managed MP3 decoding. You could use that in conjunction with some of the more generic helper classes in NAudio like the MixingSampleProvider to perform the mixing you require. Of course the next issue would be what you want to do with that mixed audio. Silverlight does have a way of streaming user generated audio using the MediaElement but NAudio does not provide support for this directly.
[DllImport] requires a substantial chunk of code in the CLR, nothing very subtle about the pinvoke marshaller. That's a problem on a phone, it runs a special version of the CLR named .NETCore. Probably better known today as the codebase that spun-off the CoreCLR open source project. Keeping it small required unsubtle choices, pinvoke fell on the floor.
So no, you'll have no use at all for NAudio. You'll have to dip into the built-in support for audio. The relevant oversight MSDN page is this one. This blog post is relevant.
As you can tell, XAudio2 is your ticket with direct support for mixing. There is a learning curve of course, the language is probably the first obstacle given the question tags. Get started with this sample to get the basics.
Maybe you should consider taking the step to upgrade from WP8.1 Silverlight (WPS) project to WP8.1 (WinRT) one so that you have better access to audio APIs...
...or directly to a UWP/Win10 app (if you don't plan to release immediately to phones). If you choose that path, you could try maybe a free preview tool that converts WPS to UWP, just released from Microsoft and Mobilize.NET - https://blogs.windows.com/buildingapps/2015/09/17/initial-preview-of-silverlight-bridge-to-uwp/
Related
I'm working on a wave file playback system, but I'm having trouble getting proper playback output using winmm.dll
The problems I'm experiencing are:
The playback stops abruptly.
The playback speeds up or breaks up or both.
There is no playback at all.
The 'Stop' method causes the system to hang on a Thread.Join call.
I do realize that there are alternatives to playing sound files in C#, WPF, but I'm trying to achieve it through winmm.dll with .wav files specifically because it will allow me *(I hope) to build specific features such as: Wave File Visualization and Sound Effect Filters.
I have looked at this Code Project link:
Programming Audio Effects in C#
It's very insightful, but I'm unable to achieve similar results in WPF. I'm not sure if the problems have to do with Garbage Collection that works differently from Windows Forms to WPF.
Here's my project on GitHub:
Wave Player - Base - WPF and Windows Forms
The solution has 2 projects: One is Windows Forms and the other is WPF.
The Windows Forms project works fine, the WPF doesn't. Both the projects, however, uses the same winmm.dll code logic.
I've also found this Microsoft link on 'Waveform Audio' :
Microsoft - About Waveform Audio
Any help or advice will be appreciated.
Which one is better choice for UWP? VLC is really easy to start to use but FFmpeg more complicated (read: difficult). But if we are thinking for example licenses, support of different format, casting, media tags, converting , subtitles and audio support, video/audio editing etc.
Any experiences?
Vlc.DotNet does not run with UWP.
I'd advise you to use https://github.com/kakone/VLC.MediaElement which uses a C++/CX wrapper under the hood to call libvlc. That's a rather complete sample app: https://code.videolan.org/videolan/vlc-winrt
licenses, support of different format, casting, media tags, converting , subtitles and audio support, video/audio editing
That's a lot of considerations and I don't know your requirements and needs. You should evaluate both. But for ease of use, VLC.MediaElement is the best choice.
Vlc Dot net . you can find details here https://github.com/ZeBobo5/Vlc.DotNet
This library will provide you better control. There are many other choices but as you are talking about audio/video/subtitles/formats you will find everything in this library. This is core medial lib and wrap by custom control.
Thus can be easily import in any wpf project/ Uwp project.
Windows Sound mixer/settings can set the microphone to play over the speakers. I'm looking for a way to do that through C#. I'm assuming there is a DLL reference or .NET call that might be able to.
Everything I've been finding invariably goes back to streaming, which I don't want to do. Unless that's whats actually happening under the hood when changing the audio settings in windows.
If it helps, I'm using C# 3.5 (Unity App) and running on Windows 10 latest.
Thanks!
You can do this with Core Audio APIs link
For implementation you can refer
https://blog.sverrirs.com/2016/02/windows-coreaudio-api-in-c.html
I am trying to build a Universal Windows App in C# that involves opening an image, re-sizing it, editing some of the pixels' RGB values and saving it again. After looking around the net for a while I found that most people seemed to be using the namespace "System.Drawing.Imaging" to do similar things, however when I tried to include "System.Drawing.Imaging", Visual Studio told me that the namespace didn't exist.
I believed this may just be that some namespaces that are available for .NET programs are not available for Universal Windows Apps, so I tried looking around some more and found a similar namespace that could be used, "Windows.UI.Xaml.Media.Imaging", however this one is much more limited than "System.Drawing.Imaging" and cannot read or edit pixels as far as I could tell.
Is there another namespace I could use, or a way to get "System.Drawing.Imaging" to in a Universal Windows App? If there isn't anyway of doing something like this with a Universal Windows App in C#, is there a way to do it in another language? Any tips or pointers would help.
For straight pixel manipulations you can use Windows.UI.Xaml.Media.ImagingWriteableBitmap and stream out of and back into its PixelBuffer property. There is a third party library WriteableBitmapEx which provides extension methods to perform higher level manipulations on the buffer.
Another alternate is the Win2D library which exposes the low level Direct2D and DirectWrite libraries to UWP apps.
I've been facing a road block in trying to incorporate .ogg and .mp3 files in a WinCE 5.0 (build 1400) environment. Many of the answers I've found require some part of the Directsound libraries which are no longer supported.
Is there any way to implement playing of .ogg and .mp3 files on WinCE 5.0 without using Directsound libraries?
For this situation I would recommend taking a look at GSPlayer or TCPMP Player (open source software, C++), you could use the code to create a dll. GSPlayer uses WaveOut internally, so no worries about DirectSound. However you will need to check the license and make sure you are not violating it. After creating such dll you could use it with p/invoke.
If you are the OEM of your target device, another option that excludes .ogg would be to add Windows Media Player Control in your OS image, and use it from C# as an ActiveX control. There is more information on how to do this here, here and here
Update:
In answers to a similar question it is recommended to use FMOD, although this is not free for commercial use as #mack369 pointed out in a comment.